yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f4d5372d3
master
1//TEST(smoke,render):COMPARE_HLSL_GLSL_RENDER: 2 3// This test is trying to ensure that we can 4// correctly handle cases where top-level shader 5// parameters are declared in an `import`ed file. 6 7#if defined ( __HLSL__ ) 8 9// Pull in Slang code depdendency using extended syntax: 10__import imported_parameters ; 11 12struct AssembledVertex 13{ 14float3 position ; 15float3 color ; 16}; 17 18struct CoarseVertex 19{ 20float3 color ; 21}; 22 23struct Fragment 24{ 25float4 color ; 26}; 27 28// Vertex Shader 29 30struct VertexStageInput 31{ 32AssembledVertex assembledVertex : A ; 33}; 34 35struct VertexStageOutput 36{ 37CoarseVertex coarseVertex : CoarseVertex ; 38float4 sv_position : SV_Position ; 39}; 40 41[ shader ( "vertex" )] 42VertexStageOutput vertexMain ( VertexStageInput input ) 43{ 44VertexStageOutput output ; 45 46float3 position = input . assembledVertex . position ; 47float3 color = input . assembledVertex . color ; 48 49output . coarseVertex . color = color ; 50output . sv_position = mul ( modelViewProjection , float4 ( position , 1.0 )); 51 52return output ; 5354 } 55 56// Fragment Shader 57 58struct FragmentStageInput 59{ 60CoarseVertex coarseVertex : CoarseVertex ; 61}; 62 63struct FragmentStageOutput 64{ 65Fragment fragment : SV_Target ; 66}; 67 68[ shader ( "fragment" )] 69FragmentStageOutput fragmentMain ( FragmentStageInput input ) 70{ 71FragmentStageOutput output ; 72 73float3 color = input . coarseVertex . color ; 74 75color = transformColor ( color ); 76 77output . fragment . color = float4 ( color , 1.0 ); 78 79return output ; 80} 81 82#elif defined ( __GLSL__ ) 83 84#version 420 85 86layout ( binding = 0 ) 87uniform Uniforms 88{ 89mat4x4 modelViewProjection ; 90}; 91 92float saturate ( float x ) 93{ 94return clamp ( x , float ( 0 ), float ( 1 )); 95 } 96 97vec3 transformColor ( vec3 color ) 98{ 99vec3 result ; 100 101result . x = sin ( 20.0 * ( color . x + color . y )); 102result . y = saturate ( cos ( color . z * 30.0 )); 103result . z = sin ( color . x * color . y * color . z * 100.0 ); 104 105result = 0.5 * ( result + 1 ); 106 107return result ; 108} 109 110#define ASSEMBLED_VERTEX ( QUAL ) \ 111/* */ 112 113#define V2F ( QUAL ) \ 114layout(location = 0) QUAL vec3 coarse_color; \ 115/* */ 116 117// Vertex Shader 118 119#ifdef __GLSL_VERTEX__ 120 121layout ( location = 0 ) 122in vec3 assembled_position ; 123 124layout ( location = 1 ) 125in vec3 assembled_color ; 126 127V2F ( out ) 128 129void main () 130{ 131vec3 position = assembled_position ; 132vec3 color = assembled_color ; 133 134coarse_color = color ; 135// gl_Position = modelViewProjection * vec4(position, 1.0); 136gl_Position = vec4 ( position , 1.0 ) * modelViewProjection ; 137} 138 139#endif 140 141#ifdef __GLSL_FRAGMENT__ 142 143V2F ( in ) 144 145layout ( location = 0 ) 146out vec4 fragment_color ; 147 148void main () 149{ 150vec3 color = coarse_color ; 151 152color = transformColor ( color ); 153 154fragment_color = vec4 ( color , 1.0 ); 155} 156 157 158#endif 159 160#endif