mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-04 21:31:11 -05:00
95 lines
2.5 KiB
Text
95 lines
2.5 KiB
Text
|
struct v2f_vertex_lit {
|
||
|
vec2 uv;
|
||
|
vec4 diff;
|
||
|
vec4 spec;
|
||
|
};
|
||
|
struct v2f_img {
|
||
|
vec4 pos;
|
||
|
vec2 uv;
|
||
|
};
|
||
|
struct appdata_img {
|
||
|
vec4 vertex;
|
||
|
vec2 texcoord;
|
||
|
};
|
||
|
struct SurfaceOutput {
|
||
|
vec3 Albedo;
|
||
|
vec3 Normal;
|
||
|
vec3 Emission;
|
||
|
float Specular;
|
||
|
float Gloss;
|
||
|
float Alpha;
|
||
|
};
|
||
|
struct appdata_full {
|
||
|
vec4 vertex;
|
||
|
vec4 tangent;
|
||
|
vec3 normal;
|
||
|
vec4 texcoord;
|
||
|
vec4 texcoord1;
|
||
|
vec4 color;
|
||
|
};
|
||
|
struct LeafSurfaceOutput {
|
||
|
vec3 Albedo;
|
||
|
vec3 Normal;
|
||
|
vec3 Emission;
|
||
|
vec3 Translucency;
|
||
|
float Specular;
|
||
|
float Gloss;
|
||
|
float Alpha;
|
||
|
};
|
||
|
struct v2f {
|
||
|
vec4 pos;
|
||
|
vec2 uv;
|
||
|
vec3 color;
|
||
|
};
|
||
|
uniform vec4 _TerrainTreeLightColors[4];
|
||
|
uniform vec3 _TerrainTreeLightDirections[4];
|
||
|
|
||
|
|
||
|
|
||
|
void ExpandBillboard( in mat4 mat, inout vec4 pos, inout vec3 normal, inout vec4 tangent );
|
||
|
v2f vert( in appdata_full v );
|
||
|
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( normal.z , 0.000000, ( -normal.x ), 0.000000) * mat ) ));
|
||
|
pos += (( tangent * 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 lightColor;
|
||
|
int i = 0;
|
||
|
vec3 lightDir;
|
||
|
float diff;
|
||
|
ExpandBillboard( gl_ModelViewMatrixInverseTranspose, v.vertex, v.normal, v.tangent);
|
||
|
o.pos = ( gl_ModelViewProjectionMatrix * v.vertex );
|
||
|
o.uv = v.texcoord.xy ;
|
||
|
lightColor = gl_LightModel.ambient.xyz ;
|
||
|
for ( ; (i < 4); ( i++ )) {
|
||
|
lightDir.xyz = _TerrainTreeLightDirections[ i ];
|
||
|
diff = max( 0.000000, ((dot( lightDir.xyz , v.normal) * 0.500000) + 0.500000));
|
||
|
lightColor += vec3( (_TerrainTreeLightColors[ i ] * diff));
|
||
|
}
|
||
|
o.color = (lightColor * 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);
|
||
|
}
|