Material update, before changing prefabs

This commit is contained in:
2023-01-19 19:29:01 -08:00
parent 985218b9bc
commit e60002b8dc
25 changed files with 439 additions and 716 deletions

View File

@ -0,0 +1,65 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/ShaderProgram.hpp"
#include "scene/components/display/MeshRenderer.hpp"
namespace Dawn {
class Material;
struct ShaderPass {
ShaderProgram *shaderProgram;
int32_t orderShader;
bool_t needsW;
// Parameters
std::map<shaderparameter_t, struct Color> colorValues;
std::map<shaderparameter_t, bool_t> boolValues;
std::map<shaderparameter_t, glm::mat4> matrixValues;
std::map<shaderparameter_t, glm::vec3> vec3Values;
std::map<shaderparameter_t, textureslot_t> textureValues;
std::map<shaderparameter_t, float_t> floatValues;
// Textures
std::map<textureslot_t, Texture*> textureSlots;
};
class Shader {
public:
int_fast16_t renderId;
/**
* Compile all programs for this shader. This amy not remain forever as I
* may decide to allow shaders to share programs somehow. For now though
* this is clean enough.
*/
virtual void compile() = 0;
/**
* Returns the list of passes to render for the given scene item.
*
* @param mesh Mesh Renderer for the scene item.
* @param material Material for the scene item.
* @return List of passes to render.
*/
virtual std::vector<struct ShaderPass> getItemPasses(
MeshRenderer *mesh,
Material *material
) = 0;
/**
* Called once per frame, set the global shader parameters that is used by
* every item in the scene.
*
* @param cameraProjection Projection matrix of the camera.
* @param cameraView View matrix of the camera.
*/
virtual void setGlobalParameters(
glm::mat4 cameraProjection,
glm::mat4 cameraView
) = 0;
};
}

View File

@ -1,115 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/Texture.hpp"
namespace Dawn {
class Material;
enum ShaderParameterType {
SHADER_PARAMETER_TYPE_MATRIX,
SHADER_PARAMETER_TYPE_BOOLEAN,
SHADER_PARAMETER_TYPE_COLOR,
SHADER_PARAMETER_TYPE_VECTOR3,
SHADER_PARAMETER_TYPE_TEXTURE,
SHADER_PARAMETER_TYPE_FLOAT
};
template<typename T>
class IShader {
public:
/**
* Attaches the supplied shader as the current shader.
*/
virtual void bind() = 0;
/**
* Requested by the Material to set the default parameters of the shader.
* Each parameter really should have a default value set so that there is
* no nullptr's or other issues.
*
* @param material Material to set the default parameters on to.
*/
virtual void setDefaultParameters(Material *material) = 0;
/**
* Requested by the render pipeline (typically) to set global level (once
* per frame) parameters.
*
* @param projection Projection matrix of the current viewport.
* @param view View matrix of the current viewport.
*/
virtual void setGlobalParameters(
glm::mat4 projection,
glm::mat4 view
) = 0;
/**
* Requested by the render pipeline (typically) to set mesh-level params.
* This may be performed multiple times per frame.
*
* @param position Matrix of the position of the mesh.
*/
virtual void setMeshParameters(glm::mat4 position) = 0;
/**
* Retreives the list of all parameters that the shader supports. This
* should not include the GLOBAL shader parameters (listed above) since
* those will be modified by the engine directly.
*
* @return Key-Value-Pair of Shader parameters and their type.
*/
virtual std::map<T, enum ShaderParameterType> getParameters() = 0;
/**
* Set's a specific shader parameter to a matrix.
*
* @param parameter parameter on the shader to set.
* @param matrix Matrix to apply.
*/
virtual void setMatrix(T parameter, glm::mat4 matrix) = 0;
/**
* Attaches a boolean to a shader.
*
* @param parameter parameter to set.
* @param value Value to set.
*/
virtual void setBoolean(T parameter, bool_t value) = 0;
/**
* Set a color on to the shader.
*
* @param parameter parameter to set the color to.
* @param color Color to set.
*/
virtual void setColor(T parameter, struct Color color) = 0;
/**
* Set a 3D vector on to the shader.
*
* @param parameter parameter to set the vector to.
* @param vector Vector to set.
*/
virtual void setVector3(T parameter, glm::vec3 vector) = 0;
/**
* Attaches a texture to the currently bound shader.
*
* @param parameter parameter to set the texture on to.
* @param texture Texture to bind to the parameter.
*/
virtual void setTexture(T parameter, Texture *texture) = 0;
/**
* Sets a floating point value to the shader.
*
* @param parameter Paramater to set the float ont o.
* @param Float to bind.
*/
virtual void setFloat(T parameter, float_t value) = 0;
};
}

View File

@ -0,0 +1,76 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/Texture.hpp"
namespace Dawn {
// class Material;
// enum ShaderParameterType {
// SHADER_PARAMETER_TYPE_MATRIX,
// SHADER_PARAMETER_TYPE_BOOLEAN,
// SHADER_PARAMETER_TYPE_COLOR,
// SHADER_PARAMETER_TYPE_VECTOR3,
// SHADER_PARAMETER_TYPE_TEXTURE,
// SHADER_PARAMETER_TYPE_FLOAT
// };
template<typename T>
class IShaderProgram {
public:
/**
* Attaches the supplied shader as the current shader.
*/
virtual void bind() = 0;
/**
* Set's a specific shader parameter to a matrix.
*
* @param parameter parameter on the shader to set.
* @param matrix Matrix to apply.
*/
virtual void setMatrix(T parameter, glm::mat4 matrix) = 0;
/**
* Attaches a boolean to a shader.
*
* @param parameter parameter to set.
* @param value Value to set.
*/
virtual void setBoolean(T parameter, bool_t value) = 0;
/**
* Set a color on to the shader.
*
* @param parameter parameter to set the color to.
* @param color Color to set.
*/
virtual void setColor(T parameter, struct Color color) = 0;
/**
* Set a 3D vector on to the shader.
*
* @param parameter parameter to set the vector to.
* @param vector Vector to set.
*/
virtual void setVector3(T parameter, glm::vec3 vector) = 0;
/**
* Attaches a texture to the currently bound shader.
*
* @param parameter parameter to set the texture on to.
* @param texture Texture slot to bind to the parameter.
*/
virtual void setTexture(T parameter, textureslot_t texture) = 0;
/**
* Sets a floating point value to the shader.
*
* @param parameter Paramater to set the float ont o.
* @param Float to bind.
*/
virtual void setFloat(T parameter, float_t value) = 0;
};
}