Model normal come to shader in world space

I struggle to get correct specular / reflection for two days, and finally find out that, normal come to shader in world space, and mtx_normal transform it back to local space.

following code is what I use at the very beginning without doubt nor second thought

attribute mediump vec3 normal;
uniform mediump mat4 mtx_normal;
varying mediump vec4 var_normal;

void main()
{
    vec3 normalWorld = normalize((mtx_normal * vec4(normal, 0.0)).xyz);
    //... calculate fresnel term, etc...
    var_normal = vec4(normalWorld, fresnel);
    //... frag color etc...
}

When I visualize normal vector on surface, I find that it gives local normal rather than world normal.

attribute mediump vec3 normal;
uniform mediump mat4 mtx_normal;
varying mediump vec4 var_normal;

void main()
{
   // pass the normal directly,  yield correct world normal instead
    //... calculate fresnel term, etc...
    var_normal = vec4(normal, fresnel);
    //... frag color etc...
}

With this modification, my PBR implementation now render identically as Unity3D.

I wonder, is this by design or a bug?

2 Likes

Hello?Any one here can answer me?

@sven might know.

Or @Andreas_Tadic

The engine is attempting to batch as many objects as possible into one draw call for performance reason (especially on older devices). The position and normal vectors etc. must be transformed on the CPU and sent to the shader in world space (one or more big vertex buffers).
The matrices sent to the shader should therefore be identity, but there was a bug regarding this fixed in 1.2.120 (see note on DEF-3090).

Note that there is upcoming functionality in the engine for selecting world or local vertex space from the material, where the local space will allow for GPU transform of vertex data (and thus generating a draw call per object). I can’t however give you an exact release date of this yet.

2 Likes

OK……get it……
This does not matter much but make billboard harder to write, but it’s OK.
And will custom vertex data come soon? Since I simulate texCubeLOD by interpolating two cubemap, and get satisfied result, normal map is now last obstacle between me and full blown PBR pipeline.

2 Likes

Custom vertex format is a frequently requested feature and is planned for, but I can’t give you any details on when and what it will look like yet, sorry.

2 Likes

Well, if custom vertex format will not be available soon enough, would you please consider add tangent to fix attribute list? Since this is essential for any 3D rendering with lighting

1 Like