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 4//TEST_INPUT: Texture2D(size=4, content = one):name t 5//TEST_INPUT: Sampler:name s 6//TEST_INPUT: ubuffer(data=[0], stride=4):out, name outputBuffer 7 8Texture2D t; 9SamplerState s; 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// Vertex Shader 36 37struct VertexStageInput 38{ 39 AssembledVertex assembledVertex : A; 40}; 41 42struct VertexStageOutput 43{ 44 CoarseVertex coarseVertex : CoarseVertex; 45 float4 sv_position : SV_Position; 46}; 47 48[shader("vertex")] 49VertexStageOutput vertexMain(VertexStageInput input) 50{ 51 VertexStageOutput output; 52 53 float3 position = input.assembledVertex.position; 54 float3 color = input.assembledVertex.color; 55 56 output.coarseVertex.color = color; 57 output.sv_position = mul(modelViewProjection, float4(position, 1.0)); 58 output.coarseVertex.uv = input.assembledVertex.uv; 59 return output; 60} 61 62// Fragment Shader 63 64struct FragmentStageInput 65{ 66 CoarseVertex coarseVertex : CoarseVertex; 67}; 68 69struct FragmentStageOutput 70{ 71 Fragment fragment : SV_Target; 72}; 73 74[shader("fragment")] 75FragmentStageOutput fragmentMain(FragmentStageInput input) 76{ 77 FragmentStageOutput output; 78 79 float3 color = input.coarseVertex.color; 80 float2 uv = input.coarseVertex.uv; 81 output.fragment.color = float4(color, 1.0); 82 83 84 float4 result = 0; 85 $for(i in Range(0,5)) 86 { 87 float4 v = t.Sample(s, uv, int2(i - 2, 0)); 88 result += v; 89 } 90 91 outputBuffer[0] = result.x; 92 93 return output; 94}