mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-04 21:31:11 -05:00
97 lines
2.5 KiB
Text
97 lines
2.5 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 SurfaceOutput {
|
||
|
vec3 Albedo;
|
||
|
vec3 Normal;
|
||
|
vec3 Emission;
|
||
|
float Specular;
|
||
|
float Gloss;
|
||
|
float Alpha;
|
||
|
};
|
||
|
struct Input {
|
||
|
vec3 worldRefl;
|
||
|
};
|
||
|
struct v2f_surf {
|
||
|
vec4 pos;
|
||
|
float fog;
|
||
|
vec3 worldRefl;
|
||
|
vec3 normal;
|
||
|
vec3 lightDir;
|
||
|
};
|
||
|
struct appdata_full {
|
||
|
vec4 vertex;
|
||
|
vec4 tangent;
|
||
|
vec3 normal;
|
||
|
vec4 texcoord;
|
||
|
vec4 texcoord1;
|
||
|
vec4 color;
|
||
|
};
|
||
|
uniform mat4 _Object2World;
|
||
|
uniform mat4 _World2Object;
|
||
|
uniform vec3 _WorldSpaceCameraPos;
|
||
|
uniform vec4 _WorldSpaceLightPos0;
|
||
|
|
||
|
uniform vec4 unity_Scale;
|
||
|
vec3 WorldSpaceLightDir( in vec4 v );
|
||
|
void PositionFog( in vec4 v, out vec4 pos, out float fog );
|
||
|
vec3 ObjSpaceViewDir( in vec4 v );
|
||
|
v2f_surf vert_surf( in appdata_full v );
|
||
|
vec3 WorldSpaceLightDir( in vec4 v ) {
|
||
|
vec3 worldPos;
|
||
|
worldPos = ( _Object2World * v ).xyz ;
|
||
|
return _WorldSpaceLightPos0.xyz ;
|
||
|
}
|
||
|
void PositionFog( in vec4 v, out vec4 pos, out float fog ) {
|
||
|
pos = ( gl_ModelViewProjectionMatrix * v );
|
||
|
fog = pos.z ;
|
||
|
}
|
||
|
vec3 ObjSpaceViewDir( in vec4 v ) {
|
||
|
vec3 objSpaceCameraPos;
|
||
|
objSpaceCameraPos = (( _World2Object * vec4( _WorldSpaceCameraPos.xyz , 1.00000) ).xyz * unity_Scale.w );
|
||
|
return (objSpaceCameraPos - v.xyz );
|
||
|
}
|
||
|
v2f_surf vert_surf( in appdata_full v ) {
|
||
|
v2f_surf o;
|
||
|
vec3 viewDir;
|
||
|
vec3 viewRefl;
|
||
|
PositionFog( v.vertex, o.pos, o.fog);
|
||
|
viewDir = ( -ObjSpaceViewDir( v.vertex) );
|
||
|
viewRefl = reflect( viewDir, v.normal);
|
||
|
o.worldRefl = ( xll_constructMat3( _Object2World) * viewRefl );
|
||
|
o.normal = ( xll_constructMat3( _Object2World) * (v.normal * unity_Scale.w ) );
|
||
|
o.lightDir = WorldSpaceLightDir( v.vertex);
|
||
|
return o;
|
||
|
}
|
||
|
attribute vec4 TANGENT;
|
||
|
varying vec4 xlv_FOG;
|
||
|
void main() {
|
||
|
v2f_surf 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_surf( xlt_v);
|
||
|
gl_Position = vec4( xl_retval.pos);
|
||
|
xlv_FOG = vec4( xl_retval.fog, 0.0, 0.0, 0.0);
|
||
|
gl_TexCoord[0] = vec4( xl_retval.worldRefl, 0.0);
|
||
|
gl_TexCoord[1] = vec4( xl_retval.normal, 0.0);
|
||
|
gl_TexCoord[2] = vec4( xl_retval.lightDir, 0.0);
|
||
|
}
|