yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f4d5372d3
master
1//TEST(render):COMPARE_HLSL_CROSS_COMPILE_RENDER: 2 3 4// This is a test to ensure that we can cross-compile a complete entry point. 5 6float3 transformColor(float3 color) 7{ 8 float3 result; 9 10 result.x = sin(20.0 * (color.x + color.y)); 11 result.y = saturate(cos(color.z * 30.0)); 12 result.z = sin(color.x * color.y * color.z * 100.0); 13 14 result = 0.5 * (result + 1); 15 16 return result; 17} 18 19cbuffer Uniforms 20{ 21 float4x4 modelViewProjection; 22}; 23 24struct AssembledVertex 25{ 26 float3 position; 27 float3 color; 28}; 29 30struct CoarseVertex 31{ 32 float3 color; 33}; 34 35struct Fragment 36{ 37 float4 color; 38}; 39 40// Vertex Shader 41 42struct VertexStageInput 43{ 44 AssembledVertex assembledVertex : A; 45}; 46 47struct VertexStageOutput 48{ 49 CoarseVertex coarseVertex : CoarseVertex; 50 float4 sv_position : SV_Position; 51}; 52 53[shader("vertex")] 54VertexStageOutput vertexMain(VertexStageInput input) 55{ 56 VertexStageOutput output; 57 58 float3 position = input.assembledVertex.position; 59 float3 color = input.assembledVertex.color; 60 61 output.coarseVertex.color = color; 62 output.sv_position = mul(modelViewProjection, float4(position, 1.0)); 63 64 return output; 65 66} 67 68// Fragment Shader 69 70struct FragmentStageInput 71{ 72 CoarseVertex coarseVertex : CoarseVertex; 73}; 74 75struct FragmentStageOutput 76{ 77 Fragment fragment : SV_Target; 78}; 79 80[shader("fragment")] 81FragmentStageOutput fragmentMain(FragmentStageInput input) 82{ 83 FragmentStageOutput output; 84 85 float3 color = input.coarseVertex.color; 86 87 color = transformColor(color); 88 89 output.fragment.color = float4(color, 1.0); 90 91 return output; 92}