yum-mirror/slang

Making it easier to work with shaders

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

Tim FoleyRemove old code paths from render-test (#1760)6e5d85efb

master
2.7 KiB176 linesraw
1//DISABLED_TEST(smoke,render):COMPARE_HLSL_GLSL_RENDER:
2//DISABLED_TEST(smoke,render):COMPARE_HLSL_GLSL_RENDER: -dx12
3
4// This is a basic test case for cross-compilation behavior.
5//
6// We will define distinct HLSL and GLSL entry points,
7// but the two will share a dependency on a file of
8// pure Slang code that provides the actual shading logic.
9
10
11#if defined(__HLSL__)
12
13// Pull in Slang code depdendency using extended syntax:
14__import unused_discard;
15
16cbuffer Uniforms
17{
18	float4x4 modelViewProjection;
19};
20
21struct AssembledVertex
22{
23	float3	position;
24	float3	color;
25};
26
27struct CoarseVertex
28{
29	float3	color;
30};
31
32struct Fragment
33{
34	float4 color;
35};
36
37// Vertex  Shader
38
39struct VertexStageInput
40{
41	AssembledVertex assembledVertex	: A;
42};
43
44struct VertexStageOutput
45{
46	CoarseVertex	coarseVertex	: CoarseVertex;
47	float4			sv_position		: SV_Position;
48};
49
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
60	return output;
61	
62}
63
64// Fragment Shader
65
66struct FragmentStageInput
67{
68	CoarseVertex	coarseVertex	: CoarseVertex;
69};
70
71struct FragmentStageOutput
72{
73	Fragment fragment	: SV_Target;
74};
75
76FragmentStageOutput fragmentMain(FragmentStageInput input)
77{
78	FragmentStageOutput output;
79
80	float3 color = input.coarseVertex.color;
81
82	color = transformColor(color);
83
84	doConditionalDiscard(color);
85
86	output.fragment.color = float4(color, 1.0);
87
88	return output;
89}
90
91#elif defined(__GLSL__)
92
93#version 420
94
95float saturate(float x)
96{
97    return clamp(x, float(0), float(1));	
98}
99
100vec3 transformColor(vec3 color)
101{
102	vec3 result;
103
104	result.x = sin(20.0 * (color.x + color.y));
105	result.y = saturate(cos(color.z * 30.0));
106	result.z = sin(color.x * color.y * color.z * 100.0);
107
108	result = 0.5 * (result + 1);
109
110	return result;
111}
112
113uniform Uniforms
114{
115	mat4x4 modelViewProjection;
116};
117
118#define ASSEMBLED_VERTEX(QUAL)		\
119	/* */
120
121#define V2F(QUAL)									\
122	layout(location = 0) QUAL vec3 coarse_color;	\
123	/* */
124
125// Vertex  Shader
126
127#ifdef __GLSL_VERTEX__
128
129layout(location = 0)
130in vec3 assembled_position;
131
132layout(location = 1)
133in vec3 assembled_color;
134
135V2F(out)
136
137void main()
138{
139	vec3 position = assembled_position;
140	vec3 color	= assembled_color;
141
142	coarse_color = color;
143//	gl_Position = modelViewProjection * vec4(position, 1.0);
144	gl_Position = vec4(position, 1.0) * modelViewProjection;
145}
146
147#endif
148
149#ifdef __GLSL_FRAGMENT__
150
151void doConditionalDiscard(vec3 color)
152{
153	if(color.x < 0.5)
154		discard;
155}
156
157V2F(in)
158
159layout(location = 0)
160out vec4 fragment_color;
161
162void main()
163{
164	vec3 color = coarse_color;
165
166	color = transformColor(color);
167
168	doConditionalDiscard(color);
169
170	fragment_color = vec4(color, 1.0);
171}
172
173
174#endif
175
176#endif