-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvout.shader
193 lines (183 loc) · 3.64 KB
/
vout.shader
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
float4 vec4(float x0, float x1, float x2, float x3)
{
return float4(x0, x1, x2, x3);
}
float4 vec4(float3 x0, float x1)
{
return float4(x0, x1);
}
// Attributes
static float4 _in_Colour = {0, 0, 0, 0};
static float3 _in_Position = {0, 0, 0};
static float2 _in_TextureCoord = {0, 0};
static float4 gl_Position = float4(0, 0, 0, 0);
// Varyings
static float4 _v_vColour = {0, 0, 0, 0};
static float2 _v_vTexcoord = {0, 0};
uniform float4 dx_ViewAdjust : register(c1);
uniform float4 _gm_AmbientColour : register(c2);
uniform float _gm_FogStart : register(c3);
uniform bool _gm_LightingEnabled : register(c4);
uniform float4 _gm_Lights_Colour[8] : register(c5);
uniform float4 _gm_Lights_Direction[8] : register(c13);
uniform float4 _gm_Lights_PosRange[8] : register(c21);
uniform float4x4 _gm_Matrices[5] : register(c29);
uniform float _gm_RcpFogRange : register(c49);
uniform bool _gm_VS_FogEnabled : register(c50);
;
;
;
;
;
;
;
;
;
float _CalcFogFactor(in float4 _pos)
{
{
if(_gm_VS_FogEnabled)
{
{
float4 _viewpos = mul((_gm_Matrices[3]), _pos);
float _fogfactor = ((_viewpos.z - _gm_FogStart) * _gm_RcpFogRange);
return _fogfactor;
;
}
;
}
else
{
{
return 0.0;
;
}
;
}
;
}
}
;
float4 _DoDirLight(in float3 _ws_normal, in float4 _dir, in float4 _diffusecol)
{
{
float _dotresult = dot(_ws_normal, _dir.xyz);
(_dotresult = max(0.0, _dotresult));
return (_dotresult * _diffusecol);
;
}
}
;
float4 _DoPointLight(in float3 _ws_pos, in float3 _ws_normal, in float4 _posrange, in float4 _diffusecol)
{
{
float3 _diffvec = (_ws_pos - _posrange.xyz);
float _veclen = length(_diffvec);
(_diffvec /= _veclen);
float _atten = (1.0 / (_veclen / _posrange.w));
if((_veclen > _posrange.w))
{
{
(_atten = 0.0);
}
;
}
;
float _dotresult = dot(_ws_normal, _diffvec);
(_dotresult = max(0.0, _dotresult));
return ((_dotresult * _atten) * _diffusecol);
;
}
}
;
float4 _DoLighting(in float4 _vertexcolour, in float4 _objectspacepos, in float3 _objectspacenormal)
{
{
if(_gm_LightingEnabled)
{
{
float4 _objectspacenormal4 = vec4(_objectspacenormal, 0.0);
float3 _ws_normal = {0, 0, 0};
(_ws_normal = mul((_gm_Matrices[3]), _objectspacenormal4).xyz);
(_ws_normal = (-normalize(_ws_normal)));
float3 _ws_pos = {0, 0, 0};
(_ws_pos = mul((_gm_Matrices[2]), _objectspacepos).xyz);
float4 _accumcol = float4(0.0, 0.0, 0.0, 0.0);
{for(int _i = 0; (_i < 8); (_i++))
{
{
(_accumcol += _DoDirLight(_ws_normal, _gm_Lights_Direction[_i], _gm_Lights_Colour[_i]));
}
;}
}
;
{for(int _i = 0; (_i < 8); (_i++))
{
{
(_accumcol += _DoPointLight(_ws_pos, _ws_normal, _gm_Lights_PosRange[_i], _gm_Lights_Colour[_i]));
}
;}
}
;
(_accumcol *= _vertexcolour);
(_accumcol += _gm_AmbientColour);
(_accumcol = min(float4(1.0, 1.0, 1.0, 1.0), _accumcol));
return _accumcol;
;
}
;
}
else
{
{
return _vertexcolour;
;
}
;
}
;
}
}
;
;
;
;
;
;
void gl_main()
{
{
float4 _object_space_pos = vec4(_in_Position.x, _in_Position.y, _in_Position.z, 1.0);
(gl_Position = mul((_gm_Matrices[4]), _object_space_pos));
(_v_vColour = _in_Colour);
(_v_vTexcoord = _in_TextureCoord);
}
}
;
struct VS_INPUT
{
float4 _in_Colour : COLOR0;
float3 _in_Position : POSITION;
float2 _in_TextureCoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 gl_Position : POSITION;
float4 v0 : TEXCOORD0;
float2 v1 : TEXCOORD1;
};
VS_OUTPUT main(VS_INPUT input)
{
_in_Colour = (input._in_Colour);
_in_Position = (input._in_Position);
_in_TextureCoord = (input._in_TextureCoord);
gl_main();
VS_OUTPUT output;
output.gl_Position.x = gl_Position.x;
output.gl_Position.y = gl_Position.y;
output.gl_Position.z = gl_Position.z;
output.gl_Position.w = gl_Position.w;
output.v0 = _v_vColour;
output.v1 = _v_vTexcoord;
return output;
}