yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Anders LeinoMigrate render-test away from deprecated compile request API (#6514)f4d5372d3

master
2.5 KiB160 linesraw
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{
14	float3	position;
15	float3	color;
16};
17
18struct CoarseVertex
19{
20	float3	color;
21};
22
23struct Fragment
24{
25	float4 color;
26};
27
28// Vertex  Shader
29
30struct VertexStageInput
31{
32	AssembledVertex assembledVertex	: A;
33};
34
35struct VertexStageOutput
36{
37	CoarseVertex	coarseVertex	: CoarseVertex;
38	float4			sv_position		: SV_Position;
39};
40
41[shader("vertex")]
42VertexStageOutput vertexMain(VertexStageInput input)
43{
44	VertexStageOutput output;
45
46	float3 position = input.assembledVertex.position;
47	float3 color	= input.assembledVertex.color;
48
49	output.coarseVertex.color = color;
50	output.sv_position = mul(modelViewProjection, float4(position, 1.0));
51
52	return output;
53	
54}
55
56// Fragment Shader
57
58struct FragmentStageInput
59{
60	CoarseVertex	coarseVertex	: CoarseVertex;
61};
62
63struct FragmentStageOutput
64{
65	Fragment fragment	: SV_Target;
66};
67
68[shader("fragment")]
69FragmentStageOutput fragmentMain(FragmentStageInput input)
70{
71	FragmentStageOutput output;
72
73	float3 color = input.coarseVertex.color;
74
75	color = transformColor(color);
76
77	output.fragment.color = float4(color, 1.0);
78
79	return output;
80}
81
82#elif defined(__GLSL__)
83
84#version 420
85
86layout(binding = 0)
87uniform Uniforms
88{
89	mat4x4 modelViewProjection;
90};
91
92float saturate(float x)
93{
94    return clamp(x, float(0), float(1));	
95}
96
97vec3 transformColor(vec3 color)
98{
99	vec3 result;
100
101	result.x = sin(20.0 * (color.x + color.y));
102	result.y = saturate(cos(color.z * 30.0));
103	result.z = sin(color.x * color.y * color.z * 100.0);
104
105	result = 0.5 * (result + 1);
106
107	return result;
108}
109
110#define ASSEMBLED_VERTEX(QUAL)		\
111	/* */
112
113#define V2F(QUAL)									\
114	layout(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{
131	vec3 position = assembled_position;
132	vec3 color	= assembled_color;
133
134	coarse_color = color;
135//	gl_Position = modelViewProjection * vec4(position, 1.0);
136	gl_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{
150	vec3 color = coarse_color;
151
152	color = transformColor(color);
153
154	fragment_color = vec4(color, 1.0);
155}
156
157
158#endif
159
160#endif