// 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 } // Per-vertex attributes to be assembled from bound vertex buffers. struct AssembledVertex { float3 position : POSITION; float2 texcoord : TEXCOORD0; }; // 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 }; // Combined Texture and Sampler (avoids linking issues) Texture2D textureMap; SamplerState textureSampler; // Vertex Shader [shader("vertex")] CoarseVertex vertexMain(AssembledVertex assembledVertex) { CoarseVertex 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); // Pass through texture coordinates output.texcoord = assembledVertex.texcoord; return output; } // Fragment Shader [shader("fragment")] Fragment fragmentMain(CoarseVertex coarseVertex) { Fragment output; // Sample the texture if a texture is bound if (u_HasTexture != 0) { output.color = textureMap.Sample(textureSampler, coarseVertex.texcoord); } else { // Use the uniform color if no texture is bound output.color = u_Color; } return output; }