There are 2 things here. We are using mesh.parent = scaledParent
instead of mesh.setParent(scaledParent)
The latter will recalculate the normals vector length according to the new scale.
Then there was an issue with normals still looking ‘flat’
In this example the shader has a special input of ‘normalStrength’ which is set to 1.
It needs to be hooked up to the scale factor of the parent.
// Hook up normalStrength input to scaleFactor
directX_invMat.getInputBlockByPredicate((input) => {
return input.name === 'normalStrength'
}).value = 1 / scaleFactor;
So now it looks OK when it’s under a parent of scale 0.1
Now I am wondering, how can we make it so this input block is ‘hooked up’ to the scale value of it’s parent automatically?
I suppose we have to navigate all layers of parents and calculate the scale of them all together.
Is there a better way?
I believe the problem you are seen has to do with the model matrix changing the magnitude of the normal in the shader. This can be solved by normalizing the normal after the multiplication by the Model matrix.
Thanks @srzerbetto We were able to fix it using a normalize shader block in our own shaders.
Once we did that we also realised we didn’t need to change our usage of mesh.setParent() instead or mesh.parent = newParent.