Some slang progress
This commit is contained in:
Binary file not shown.
@ -1,62 +1,53 @@
|
||||
|
||||
// Uniform data to be passed from application -> shader.
|
||||
cbuffer Uniforms {
|
||||
float4x4 u_Projection;
|
||||
float4x4 u_View;
|
||||
float4x4 u_Model;
|
||||
float4 u_Color;
|
||||
int u_HasTexture; // Changed from bool to int for compatibility
|
||||
}
|
||||
bool u_HasTexture;
|
||||
uniform Sampler2D u_Texture;
|
||||
};
|
||||
|
||||
// Per-vertex attributes to be assembled from bound vertex buffers.
|
||||
struct AssembledVertex {
|
||||
float3 position : POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
float2 texcoord : TEXCOORD;
|
||||
};
|
||||
|
||||
// Output of the vertex shader, and input to the fragment shader.
|
||||
struct CoarseVertex {
|
||||
float2 texcoord : TEXCOORD0;
|
||||
float4 position : SV_Position; // Needed for rasterization
|
||||
};
|
||||
|
||||
// Output of the fragment shader.
|
||||
struct Fragment {
|
||||
float4 color : SV_Target; // SV_Target is required for color output
|
||||
float4 color;
|
||||
};
|
||||
|
||||
// Combined Texture and Sampler (avoids linking issues)
|
||||
Texture2D textureMap;
|
||||
SamplerState textureSampler;
|
||||
struct VertexStageOutput {
|
||||
float2 uv : UV;
|
||||
float4 sv_position : SV_Position;
|
||||
};
|
||||
|
||||
float4 someFunction(float4 color) {
|
||||
return color * float4(0.5, 0.5, 0.5, 1.0);
|
||||
}
|
||||
|
||||
// Vertex Shader
|
||||
[shader("vertex")]
|
||||
CoarseVertex vertexMain(AssembledVertex assembledVertex) {
|
||||
CoarseVertex output;
|
||||
VertexStageOutput vertexMain(AssembledVertex assembledVertex) {
|
||||
VertexStageOutput output;
|
||||
|
||||
// Transform vertex position using Model-View-Projection matrix
|
||||
float4 worldPosition = mul(u_Model, float4(assembledVertex.position, 1.0));
|
||||
float4 viewPosition = mul(u_View, worldPosition);
|
||||
output.position = mul(u_Projection, viewPosition);
|
||||
float3 position = assembledVertex.position;
|
||||
|
||||
// Pass through texture coordinates
|
||||
output.texcoord = assembledVertex.texcoord;
|
||||
output.uv = assembledVertex.texcoord;
|
||||
|
||||
output.sv_position = mul(
|
||||
float4(position, 1.0),
|
||||
mul(u_Model, mul(u_View, u_Projection))
|
||||
);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// Fragment Shader
|
||||
[shader("fragment")]
|
||||
Fragment fragmentMain(CoarseVertex coarseVertex) {
|
||||
Fragment fragmentMain(float2 uv: UV) : SV_Target {
|
||||
Fragment output;
|
||||
|
||||
// Sample the texture if a texture is bound
|
||||
if (u_HasTexture != 0) {
|
||||
output.color = textureMap.Sample(textureSampler, coarseVertex.texcoord);
|
||||
if(u_HasTexture) {
|
||||
output.color = u_Texture.Sample(uv) * u_Color;
|
||||
} else {
|
||||
// Use the uniform color if no texture is bound
|
||||
output.color = u_Color;
|
||||
output.color = someFunction(u_Color);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
Reference in New Issue
Block a user