LightMap starts to fly when material parallax true


  1. When I select mode Parallax Shadow floats around the center of the ground mesh when I rotate the camera
  2. In the case of “Parallax Occlusion” there are also shadow duplicates that start to appear at mesh corners when I look at mesh from angel

Any way to fix it and make the shadow map “stationary” as it is in case of “bump” and “flat”?

This is a current limitation of parallax.

It creates an offset applied to all texture samples so uScale and vScale will need to be similar on the textures.

Thanks, can I fix the shader, or it is, for some reason, something that needs more than just a shader fix?

It would require a change to handle uvOffset per “sampler” combinaison. Lets see if @Evgeni_Popov has snother idea ?

Do I understand correctly:

  1. Here, I need to change uvOffset to be bump texture scale independent (multiply it by bump map sampler scale)

uvOffset = parallaxOcclusion(invTBN * -viewDirectionW, invTBN * normalW, vBumpUV, vBumpInfos.z);
uvOffset = parallaxOffset(invTBN * viewDirectionW, vBumpInfos.z);

  1. In all places like below, I need to recalculate uvOffset (divide by sampler scale)

vec4 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset);

I can try this, if it will work I can create pull request

No, it will not fix the problem entirely. Lightmap can have separate UV sets, so it will be broken even with the same scale if an offset is applied based on different UV space, because lightmaps often consist of multiple objects entirely in UV they are less dense, like with higher scale. Or even there can be close to the current pixel pixel from different object in lightmap uv.

And it is not something that can be fixed any way except just removing offset for lightmap, I change it that way and now lightmaps stop flying around

If you want this fix I can make pull request

The pull request would need to handle one offset per combination (matrix/uvindex) which is “a lot” to add. Maybe there could be at leat a flag to not apply offset as it could be enough in quite a lot of cases. The flag could be true if the other textures use a different uvindex pr texture matrix.

Okay, I can try the second option because I am not sure performance will be okay with the first option, if I understand it correctly recursive search for offset will be done per each matrix in worst case.

So, can you please help me understand where uvindex for each sampler defined?
Is it ./ShadersInclude/samplerFragmentDeclaration ?

If yes, can you please explain how it works? Is it some part of the build process that do some magic?

I would suggest for now to add a flag in the material which simply corresponds to a #ifdef in the shader.

By default we use the code from now and in the second case we use it without the uvOffset.

We ll see to automate only if it starts to be more in use :slight_smile:

Do you mean something like material.forceDisableShadowOffset = true ?

And how do we define that “if” value in a proper way in the shader?

material.disableLightmapParallaxOffset = true is what I am thinking about.

In the shader, it would be smthg like:

	vec4 lightmapColor = texture2D(lightmapSampler, vLightmapUV);
	vec4 lightmapColor = texture2D(lightmapSampler, vLightmapUV + uvOffset);