33-pom: Fixed shaders.

This commit is contained in:
Branimir Karadžić 2017-04-04 22:41:21 -07:00
parent 8ca270a449
commit 42f6fe1430
7 changed files with 15 additions and 6 deletions

View File

@ -60,6 +60,15 @@ vec2 parallax_uv(vec2 uv, vec3 view_dir)
}
}
vec2 texture2DBc4(sampler2D _sampler, vec2 _uv)
{
#if BGFX_SHADER_LANGUAGE_HLSL && BGFX_SHADER_LANGUAGE_HLSL <= 3
return texture2D(_sampler, _uv).yx;
#else
return texture2D(_sampler, _uv).xy;
#endif
}
void main()
{
vec3 light_dir = normalize(v_ts_light_pos - v_ts_frag_pos);
@ -88,8 +97,8 @@ void main()
}
else
{
normal.xy = texture2D(s_texNormal, uv).xy * 2.0 - 1.0;
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy) );
normal.xy = texture2DBc4(s_texNormal, uv) * 2.0 - 1.0;
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy) );
}
float diffuse = max(dot(light_dir, normal), 0.0);

View File

@ -307,7 +307,7 @@ class ExamplePom : public entry::AppI
bx::mtxRotateY(a, time * 0.4f);
bx::mtxRotateX(b, 0.4f);
bx::mtxMul(c, a, b);
bx::mtxTranslate(d, 0, 0, 4);
bx::mtxTranslate(d, 0.0f, 0.0f, 4.0f);
bx::mtxMul(mtx, c, d);
// Set transform for draw call.

View File

@ -20,10 +20,10 @@ void main()
vec3 n = normalize(mul(u_norm_mtx, vec4(normal, 0.0) ).xyz);
mat3 tbn = mat3(t, b, n);
v_ts_light_pos = mul(tbn, u_light_pos.xyz);
v_ts_light_pos = instMul(u_light_pos.xyz, tbn);
// Our camera is always at the origin
v_ts_view_pos = mul(tbn, vec3_splat(0.0) );
v_ts_frag_pos = mul(tbn, wpos);
v_ts_view_pos = instMul(vec3_splat(0.0), tbn);
v_ts_frag_pos = instMul(wpos, tbn);
v_texcoord0 = a_texcoord0;
}