Dawn/assets/shaders/hello-world.slang

60 lines
1.1 KiB
Plaintext

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;
float2 texcoord : TEXCOORD;
};
struct Fragment {
float4 color;
};
struct VertexStageOutput {
float2 uv : UV;
float4 sv_position : SV_Position;
};
[shader("vertex")]
VertexStageOutput vertexMain(
AssembledVertex assembledVertex
) {
VertexStageOutput output;
float3 position = assembledVertex.position;
output.uv = assembledVertex.texcoord;
output.sv_position = mul(
float4(position, 1.0),
mul(transforms.model, mul(transforms.view, transforms.projection))
);
return output;
}
[shader("fragment")]
Fragment fragmentMain(
float2 uv: UV
) : SV_Target {
Fragment output;
if (colors.hasTexture) {
output.color = colors.texture.Sample(uv) * colors.colors[0];
} else {
output.color = colors.colors[0] - float4(colors.somethingElse, 0, 0, 0);
}
return output;
}