Did not test for backside (it's possible the normals are flipped)
Did not test combining this with a bump map / normal map / displacement map on the three.js material
Only tested with MeshStandardMaterial & MeshPhysicalMaterial as base material
For the perturb function I just used the difference normal = normalize(normal - ${keywords.bump}); which seems the same as what three.js does for bump maps (though I'm not 100% sure)
I did a nested #if defined IS_MESHNORMALMATERIAL in shaders.ts, which feels wrong.
I did confirm that this works as expected with clearcoat, which should not be affected by bump
While I think it works, I do wonder if it would be better if these lines in the example were somehow moved to patchMaps.ts so that users don't have to worry about projection and normal calculation, though doing that would also tradeoff against flexibility.
// N_ is orthogonal to N.
vec3 N_ = g - (dot(g, csm_vNormal) * csm_vNormal);
// need to do projection, and multiply by bumpStrength
csm_Bump = mat3(csm_vModelViewMatrix) * (bumpStrength * N_);
I'd also be remiss not to mention that the technique used in the example is from @stegu and the tutorial here
Added csm_Bump per suggestion in https://github.com/FarazzShaikh/THREE-CustomShaderMaterial/issues/33
A couple of notes:
normal = normalize(normal - ${keywords.bump});
which seems the same as what three.js does for bump maps (though I'm not 100% sure)#if defined IS_MESHNORMALMATERIAL
in shaders.ts, which feels wrong.While I think it works, I do wonder if it would be better if these lines in the example were somehow moved to
patchMaps.ts
so that users don't have to worry about projection and normal calculation, though doing that would also tradeoff against flexibility.I'd also be remiss not to mention that the technique used in the example is from @stegu and the tutorial here