mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-11 08:41:31 -05:00
92 lines
3 KiB
Text
92 lines
3 KiB
Text
|
float xll_saturate( float x) {
|
||
|
return clamp( x, 0.0, 1.0);
|
||
|
}
|
||
|
struct appdata_full {
|
||
|
vec4 vertex;
|
||
|
vec4 tangent;
|
||
|
vec3 normal;
|
||
|
vec4 texcoord;
|
||
|
vec4 texcoord1;
|
||
|
vec4 color;
|
||
|
};
|
||
|
struct v2f {
|
||
|
vec4 pos;
|
||
|
vec2 uv;
|
||
|
vec3 color;
|
||
|
vec3 backContrib;
|
||
|
vec3 nl;
|
||
|
vec3 nh;
|
||
|
};
|
||
|
uniform vec3 _TerrainTreeLightDirections[4];
|
||
|
uniform float _TranslucencyViewDependency;
|
||
|
uniform mat4 _World2Object;
|
||
|
uniform vec3 _WorldSpaceCameraPos;
|
||
|
|
||
|
|
||
|
uniform vec4 unity_Scale;
|
||
|
vec3 ObjSpaceViewDir( in vec4 v );
|
||
|
void ExpandBillboard( in mat4 mat, inout vec4 pos, inout vec3 normal, inout vec4 tangent );
|
||
|
v2f vert( in appdata_full v );
|
||
|
vec3 ObjSpaceViewDir( in vec4 v ) {
|
||
|
vec3 objSpaceCameraPos;
|
||
|
objSpaceCameraPos = (( _World2Object * vec4( _WorldSpaceCameraPos.xyz , 1.00000) ).xyz * unity_Scale.w );
|
||
|
return (objSpaceCameraPos - v.xyz );
|
||
|
}
|
||
|
void ExpandBillboard( in mat4 mat, inout vec4 pos, inout vec3 normal, inout vec4 tangent ) {
|
||
|
float isBillboard;
|
||
|
vec3 norb;
|
||
|
vec3 tanb;
|
||
|
isBillboard = (1.00000 - abs( tangent.w ));
|
||
|
norb = vec3( normalize( ( vec4( normal, 0.000000) * mat ) ));
|
||
|
tanb = vec3( normalize( ( vec4( tangent.xyz , 0.000000) * mat ) ));
|
||
|
pos += (( vec4( normal.xy , 0.000000, 0.000000) * mat ) * isBillboard);
|
||
|
normal = mix( normal, norb, vec3( isBillboard));
|
||
|
tangent = mix( tangent, vec4( tanb, -1.00000), vec4( isBillboard));
|
||
|
}
|
||
|
v2f vert( in appdata_full v ) {
|
||
|
v2f o;
|
||
|
vec3 viewDir;
|
||
|
int j = 0;
|
||
|
vec3 lightDir;
|
||
|
float nl;
|
||
|
float backContrib;
|
||
|
vec3 h;
|
||
|
float nh;
|
||
|
ExpandBillboard( gl_ModelViewMatrixInverseTranspose, v.vertex, v.normal, v.tangent);
|
||
|
o.pos = ( gl_ModelViewProjectionMatrix * v.vertex );
|
||
|
o.uv = v.texcoord.xy ;
|
||
|
viewDir = normalize( ObjSpaceViewDir( v.vertex) );
|
||
|
for ( ; (j < 3); ( j++ )) {
|
||
|
lightDir = _TerrainTreeLightDirections[ j ];
|
||
|
nl = dot( v.normal, lightDir);
|
||
|
backContrib = xll_saturate( dot( viewDir, ( -lightDir )) );
|
||
|
backContrib = mix( xll_saturate( ( -nl ) ), backContrib, _TranslucencyViewDependency);
|
||
|
o.backContrib[ j ] = (backContrib * 2.00000);
|
||
|
nl = max( 0.000000, ((nl * 0.600000) + 0.400000));
|
||
|
o.nl[ j ] = nl;
|
||
|
h = normalize( (lightDir + viewDir) );
|
||
|
nh = max( 0.000000, dot( v.normal, h));
|
||
|
o.nh[ j ] = nh;
|
||
|
}
|
||
|
o.color = vec3( v.color.w );
|
||
|
return o;
|
||
|
}
|
||
|
attribute vec4 TANGENT;
|
||
|
void main() {
|
||
|
v2f xl_retval;
|
||
|
appdata_full xlt_v;
|
||
|
xlt_v.vertex = vec4( gl_Vertex);
|
||
|
xlt_v.tangent = vec4( TANGENT);
|
||
|
xlt_v.normal = vec3( gl_Normal);
|
||
|
xlt_v.texcoord = vec4( gl_MultiTexCoord0);
|
||
|
xlt_v.texcoord1 = vec4( gl_MultiTexCoord1);
|
||
|
xlt_v.color = vec4( gl_Color);
|
||
|
xl_retval = vert( xlt_v);
|
||
|
gl_Position = vec4( xl_retval.pos);
|
||
|
gl_TexCoord[0] = vec4( xl_retval.uv, 0.0, 0.0);
|
||
|
gl_TexCoord[1] = vec4( xl_retval.color, 0.0);
|
||
|
gl_TexCoord[2] = vec4( xl_retval.backContrib, 0.0);
|
||
|
gl_TexCoord[3] = vec4( xl_retval.nl, 0.0);
|
||
|
gl_TexCoord[4] = vec4( xl_retval.nh, 0.0);
|
||
|
}
|