mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
62 lines
1.5 KiB
Text
62 lines
1.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 v2f {
|
|
vec4 pos;
|
|
float fog;
|
|
vec2 bumpuv[2];
|
|
vec3 viewDir;
|
|
};
|
|
struct appdata {
|
|
vec4 vertex;
|
|
vec3 normal;
|
|
};
|
|
uniform sampler2D _BumpMap;
|
|
uniform sampler2D _ColorControl;
|
|
uniform vec4 _horizonColor;
|
|
vec4 UnpackNormal( in vec4 packednormal );
|
|
vec4 frag( in v2f i );
|
|
vec4 UnpackNormal( in vec4 packednormal ) {
|
|
vec4 normal;
|
|
normal.xy = ((packednormal.wy * 2.00000) - 1.00000);
|
|
normal.z = sqrt( ((1.00000 - (normal.x * normal.x )) - (normal.y * normal.y )) );
|
|
return normal;
|
|
}
|
|
vec4 frag( in v2f i ) {
|
|
vec3 bump1;
|
|
vec3 bump2;
|
|
vec3 bump;
|
|
float fresnel;
|
|
vec4 water;
|
|
vec4 col;
|
|
bump1 = UnpackNormal( texture2D( _BumpMap, i.bumpuv[ 0 ])).xyz ;
|
|
bump2 = UnpackNormal( texture2D( _BumpMap, i.bumpuv[ 1 ])).xyz ;
|
|
bump = ((bump1 + bump2) * 0.500000);
|
|
fresnel = dot( i.viewDir, bump);
|
|
water = texture2D( _ColorControl, vec2( fresnel, fresnel));
|
|
col.xyz = mix( water.xyz , _horizonColor.xyz , vec3( water.w ));
|
|
col.w = _horizonColor.w ;
|
|
return col;
|
|
}
|
|
varying vec4 xlv_FOG;
|
|
void main() {
|
|
vec4 xl_retval;
|
|
v2f xlt_i;
|
|
xlt_i.pos = vec4(0.0);
|
|
xlt_i.fog = float( xlv_FOG);
|
|
xlt_i.bumpuv[0] = vec2( gl_TexCoord[0]);
|
|
xlt_i.bumpuv[1] = vec2( gl_TexCoord[1]);
|
|
xlt_i.viewDir = vec3( gl_TexCoord[2]);
|
|
xl_retval = frag( xlt_i);
|
|
gl_FragData[0] = vec4( xl_retval);
|
|
}
|