mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-01 11:56:58 -05:00
43 lines
1 KiB
Text
43 lines
1 KiB
Text
|
struct appdata_full {
|
||
|
vec4 vertex;
|
||
|
vec3 normal;
|
||
|
};
|
||
|
struct v2f {
|
||
|
vec4 pos;
|
||
|
vec3 backContrib;
|
||
|
vec3 nl;
|
||
|
};
|
||
|
uniform vec3 _TerrainTreeLightDirections[4];
|
||
|
uniform float _TranslucencyViewDependency;
|
||
|
|
||
|
v2f vert(in appdata_full v)
|
||
|
{
|
||
|
v2f o;
|
||
|
vec3 viewDir;
|
||
|
o.pos = v.vertex;
|
||
|
viewDir = v.vertex.xyz;
|
||
|
|
||
|
// Do we unroll this loop?
|
||
|
// At some point we didn't since the loop body was deemed "too large"
|
||
|
for (int j = 0; j < 3; j++)
|
||
|
{
|
||
|
vec3 lightDir = _TerrainTreeLightDirections[j];
|
||
|
float nl = dot(v.normal, lightDir);
|
||
|
float backContrib = dot(viewDir, -lightDir);
|
||
|
o.backContrib[ j ] = mix(-nl, backContrib, _TranslucencyViewDependency);
|
||
|
o.nl[ j ] = max(0.0, (nl * 0.6) + 0.4);
|
||
|
}
|
||
|
return o;
|
||
|
}
|
||
|
|
||
|
void main() {
|
||
|
v2f xl_retval;
|
||
|
appdata_full xlt_v;
|
||
|
xlt_v.vertex = gl_Vertex;
|
||
|
xlt_v.normal = gl_Normal;
|
||
|
xl_retval = vert(xlt_v);
|
||
|
gl_Position = xl_retval.pos;
|
||
|
gl_TexCoord[2] = vec4(xl_retval.backContrib, 0.0);
|
||
|
gl_TexCoord[3] = vec4(xl_retval.nl, 0.0);
|
||
|
}
|