Explorar el Código

33-pom: Fixed shaders.

Branimir Karadžić hace 8 años
padre
commit
42f6fe1430

+ 11 - 2
examples/33-pom/fs_pom.sc

@@ -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);

+ 1 - 1
examples/33-pom/pom.cpp

@@ -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.

+ 3 - 3
examples/33-pom/vs_pom.sc

@@ -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;
 }

BIN
examples/runtime/shaders/dx9/fs_pom.bin


BIN
examples/runtime/shaders/essl/vs_pom.bin


BIN
examples/runtime/shaders/glsl/vs_pom.bin


BIN
examples/runtime/shaders/metal/vs_pom.bin