yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f4d5372d3
master
1//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj 2//TEST(compute):COMPARE_RENDER_COMPUTE: -mtl -shaderobj 3//TEST_INPUT: Texture2D(size=4, content = one):name tex 4//TEST_INPUT: Sampler:name samp 5//TEST_INPUT: ubuffer(data=[0 0], stride=4):out,name outputBuffer 6 7 8Texture2D tex; 9SamplerState samp; 10RWStructuredBuffer<float> outputBuffer; 11 12cbuffer Uniforms 13{ 14 float4x4 modelViewProjection; 15} 16 17struct AssembledVertex 18{ 19 float3 position; 20 float3 color; 21 float2 uv; 22}; 23 24struct CoarseVertex 25{ 26 float3 color; 27 float2 uv; 28}; 29 30struct Fragment 31{ 32 float4 color; 33}; 34 35 36// Vertex Shader 37 38struct VertexStageInput 39{ 40 AssembledVertex assembledVertex : A; 41}; 42 43struct VertexStageOutput 44{ 45 CoarseVertex coarseVertex : CoarseVertex; 46 float4 sv_position : SV_Position; 47}; 48 49[shader("vertex")] 50VertexStageOutput vertexMain(VertexStageInput input) 51{ 52 VertexStageOutput output; 53 54 float3 position = input.assembledVertex.position; 55 float3 color = input.assembledVertex.color; 56 57 output.coarseVertex.color = color; 58 output.sv_position = mul(modelViewProjection, float4(position, 1.0)); 59 output.coarseVertex.uv = input.assembledVertex.uv; 60 return output; 61} 62 63// Fragment Shader 64 65struct FragmentStageInput 66{ 67 CoarseVertex coarseVertex : CoarseVertex; 68}; 69 70struct FragmentStageOutput 71{ 72 Fragment fragment : SV_Target; 73}; 74 75[shader("fragment")] 76FragmentStageOutput fragmentMain(FragmentStageInput input) 77{ 78 FragmentStageOutput output; 79 80 float3 color = input.coarseVertex.color; 81 float2 uv = input.coarseVertex.uv; 82 output.fragment.color = float4(color, 1.0); 83 84 float4 val = float4(color, 1.0); 85 val = val - 16*tex.Sample(samp, uv); 86 87 outputBuffer[0] = 1; 88 89 if(val.x < 0) 90 discard; 91 92 outputBuffer[1] = 1; 93 return output; 94}