mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 09:08:22 -05:00
77 lines
2 KiB
Text
77 lines
2 KiB
Text
mat3 xll_constructMat3( mat4 m) {
|
|
return mat3( vec3( m[0]), vec3( m[1]), vec3( m[2]));
|
|
}
|
|
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 v2f {
|
|
vec4 pos;
|
|
vec2 uv;
|
|
vec4 nz;
|
|
};
|
|
struct appdata {
|
|
vec4 vertex;
|
|
vec3 normal;
|
|
vec4 color;
|
|
vec4 texcoord;
|
|
};
|
|
uniform vec4 _ProjectionParams;
|
|
uniform vec4 _Scale;
|
|
uniform float _SquashAmount;
|
|
uniform vec4 _SquashPlaneNormal;
|
|
uniform mat4 _TerrainEngineBendTree;
|
|
|
|
|
|
|
|
vec4 Squash( in vec4 pos );
|
|
void TerrainAnimateTree( inout vec4 pos, in float alpha );
|
|
v2f vert( in appdata v );
|
|
vec4 Squash( in vec4 pos ) {
|
|
vec3 projectedVertex;
|
|
vec3 planePoint;
|
|
vec3 planeNormal;
|
|
projectedVertex = pos.xyz ;
|
|
planePoint = vec3( 0.000000, _SquashPlaneNormal.w , 0.000000);
|
|
planeNormal = _SquashPlaneNormal.xyz ;
|
|
projectedVertex += (dot( planeNormal, (planePoint - vec3( pos))) * planeNormal);
|
|
pos = vec4( mix( projectedVertex, pos.xyz , vec3( _SquashAmount)), 1.00000);
|
|
return pos;
|
|
}
|
|
void TerrainAnimateTree( inout vec4 pos, in float alpha ) {
|
|
vec3 bent;
|
|
pos.xyz *= _Scale.xyz ;
|
|
bent = ( _TerrainEngineBendTree * vec4( pos.xyz , 0.000000) ).xyz ;
|
|
pos.xyz = mix( pos.xyz , bent, vec3( alpha));
|
|
pos = Squash( pos);
|
|
}
|
|
v2f vert( in appdata v ) {
|
|
v2f o;
|
|
TerrainAnimateTree( v.vertex, v.color.w );
|
|
o.pos = ( gl_ModelViewProjectionMatrix * v.vertex );
|
|
o.uv = v.texcoord.xy ;
|
|
o.nz.xyz = ( xll_constructMat3( gl_ModelViewMatrixInverseTranspose) * v.normal );
|
|
o.nz.w = ( -(( gl_ModelViewMatrix * v.vertex ).z * _ProjectionParams.w ) );
|
|
return o;
|
|
}
|
|
void main() {
|
|
v2f xl_retval;
|
|
appdata xlt_v;
|
|
xlt_v.vertex = vec4( gl_Vertex);
|
|
xlt_v.normal = vec3( gl_Normal);
|
|
xlt_v.color = vec4( gl_Color);
|
|
xlt_v.texcoord = vec4( gl_MultiTexCoord0);
|
|
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.nz);
|
|
}
|