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