Shader structure done.

This commit is contained in:
2024-12-29 10:09:20 -06:00
parent ba305de596
commit f574b60856
19 changed files with 382 additions and 262 deletions

View File

@ -1,9 +1,18 @@
uniform float4x4 u_Projection;
uniform float4x4 u_View;
uniform float4x4 u_Model;
uniform float4 u_Color;
uniform bool u_HasTexture;
uniform Sampler2D u_Texture;
struct Transforms {
float4x4 projection;
float4x4 view;
float4x4 model;
}
struct Colors {
bool hasTexture;
float4 colors[4];
int somethingElse;
Sampler2D texture;
}
uniform Transforms transforms;
uniform Colors colors;
struct AssembledVertex {
float3 position : POSITION;
@ -19,10 +28,6 @@ struct VertexStageOutput {
float4 sv_position : SV_Position;
};
float4 someFunction(float4 color) {
return color * float4(0.5, 0.5, 0.5, 1.0);
}
[shader("vertex")]
VertexStageOutput vertexMain(
AssembledVertex assembledVertex
@ -35,7 +40,7 @@ VertexStageOutput vertexMain(
output.sv_position = mul(
float4(position, 1.0),
mul(u_Model, mul(u_View, u_Projection))
mul(transforms.model, mul(transforms.view, transforms.projection))
);
return output;
@ -46,10 +51,10 @@ Fragment fragmentMain(
float2 uv: UV
) : SV_Target {
Fragment output;
if(u_HasTexture) {
output.color = u_Texture.Sample(uv) * u_Color;
if (colors.hasTexture) {
output.color = colors.texture.Sample(uv) * colors.colors[0];
} else {
output.color = someFunction(u_Color);
output.color = colors.colors[0] - float4(colors.somethingElse, 0, 0, 0);
}
return output;
}