mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 09:08:22 -05:00
67 lines
1.7 KiB
Text
67 lines
1.7 KiB
Text
|
void xll_clip(float x) {
|
||
|
if ( x<0.0 ) discard;
|
||
|
}
|
||
|
struct v2f {
|
||
|
vec4 pos;
|
||
|
vec2 uv;
|
||
|
vec3 color;
|
||
|
vec3 backContrib;
|
||
|
vec3 nl;
|
||
|
vec3 nh;
|
||
|
};
|
||
|
uniform sampler2D _BumpSpecMap;
|
||
|
uniform float _Cutoff;
|
||
|
uniform sampler2D _MainTex;
|
||
|
uniform vec4 _SpecColor;
|
||
|
uniform vec4 _TerrainTreeLightColors[4];
|
||
|
uniform vec3 _TranslucencyColor;
|
||
|
uniform sampler2D _TranslucencyMap;
|
||
|
|
||
|
vec4 frag( in v2f i ) {
|
||
|
vec4 col;
|
||
|
vec3 albedo;
|
||
|
float specular;
|
||
|
vec4 trngls;
|
||
|
float gloss;
|
||
|
vec3 light;
|
||
|
vec3 backContribs;
|
||
|
int j = 0;
|
||
|
vec3 lightColor;
|
||
|
vec3 translucencyColor;
|
||
|
float nl;
|
||
|
float nh;
|
||
|
float spec;
|
||
|
vec4 c;
|
||
|
col = texture2D( _MainTex, i.uv);
|
||
|
xll_clip( (col.w - _Cutoff) );
|
||
|
albedo = (col.xyz * i.color);
|
||
|
specular = (texture2D( _BumpSpecMap, i.uv).x * 128.000);
|
||
|
trngls = texture2D( _TranslucencyMap, i.uv);
|
||
|
gloss = trngls.w ;
|
||
|
light = (vec3( gl_LightModel.ambient) * albedo);
|
||
|
backContribs = (i.backContrib * trngls.z );
|
||
|
for ( ; (j < 3); ( j++ )) {
|
||
|
lightColor = _TerrainTreeLightColors[ j ].xyz ;
|
||
|
translucencyColor = (backContribs[ j ] * _TranslucencyColor);
|
||
|
nl = i.nl[ j ];
|
||
|
nh = i.nh[ j ];
|
||
|
spec = (pow( nh, specular) * gloss);
|
||
|
light += (((albedo * (translucencyColor + nl)) + (_SpecColor.xyz * spec)) * lightColor);
|
||
|
}
|
||
|
c.xyz = (light * 2.00000);
|
||
|
c.w = 1.00000;
|
||
|
return c;
|
||
|
}
|
||
|
void main() {
|
||
|
vec4 xl_retval;
|
||
|
v2f xlt_i;
|
||
|
xlt_i.pos = vec4(0.0);
|
||
|
xlt_i.uv = vec2( gl_TexCoord[0]);
|
||
|
xlt_i.color = vec3( gl_TexCoord[1]);
|
||
|
xlt_i.backContrib = vec3( gl_TexCoord[2]);
|
||
|
xlt_i.nl = vec3( gl_TexCoord[3]);
|
||
|
xlt_i.nh = vec3( gl_TexCoord[4]);
|
||
|
xl_retval = frag( xlt_i);
|
||
|
gl_FragData[0] = vec4( xl_retval);
|
||
|
}
|