Because defold has not supported tangent, but I need to calculate TBN matrix, so I used dFdx/dFdy functions, but it has not worked on Android.
vec3 get_normal_from_map()
{
vec3 tangent_normal = texture2D(normal_map, var_texcoord0).xyz * 2.0 - 1.0;
vec3 Q1 = dFdx(vec3(var_frag_pos));
vec3 Q2 = dFdy(vec3(var_frag_pos));
vec2 st1 = dFdx(vec2(var_texcoord0));
vec2 st2 = dFdy(vec2(var_texcoord0));
vec3 N = normalize(var_normal);
vec3 T = normalize(Q1*st2.t - Q2*st1.t);
vec3 B = -normalize(cross(N, T));
mat3 TBN = mat3(T, B, N);
return normalize(TBN * tangent_normal);
}
I already added following code, it can compile successfully. but not work.
#extension GL_OES_standard_derivatives : enable
1 Like
I think @sven did some example where shader could calculate the mip level, and it used the dFdx/dFdy functions.
1 Like
Can you verify that the extension is supported on your HW? I guess it should be available if the compilation works, but just to make sure you can download something like: https://play.google.com/store/apps/details?id=com.realtechvr.glview&hl=sv and see if the extension is available.
To verify that the dfdx works, you can create an empty project with a gameobject with a sprite component and a special material that contains a shader that just outputs something like:
gl_FragColor = vec4(vec3(fwidth(var_texcoord0.xy) * 10.0,0.0),1.0);
If you scale the object up and down, you should see that the color changes. If it’s completely black then the dfdx functions doesn’t work. If it does change, then there’s something wrong with your original code.
2 Likes
Thank you. I am trying, it realy changed, so I guess my original code be something wrong.