DynamicTexture and parallax occlusion

Is there a playground example showing a DynamicTexture being used w/ parallax occlusion? I’m trying to do some procgen stuff, but am struggling.

@sebavan @Evgeni_Popov

Wow, interesting. Can a dynamicTexture be used as a bumpTexture? I believe not.
I’d love to see an example of this if it works.

Why shouldn’t this be possible?

Don’t know, in truth. May be because you’re struggling :wink: :grinning:

What do you exactly want ? generate dynamically the content of a bump texture or have some parallax occlusion in a dynamic texture (which I am not too sure what it would be) ?

If the first one, a dynamic texture can be used like any other texture as a bump map, you would need to use the canvas 2d api to fill in with your data.

Oh, so it would work for a bump map. Good to know. Never checked out this part. Don’t had much use of these with parallax so far. But then, I guess it wouldn’t work for a normal map (to use with a standard material), would it?

It is a texture so you can use it in place of any texture :slight_smile:

1 Like

One can use Dynamic bump texture for some effects over diffuse texture.

3 Likes

Maybe a demo using sine waves for both bump and height? With full parallax turned on?

Using the PG from @labris:

3 Likes

Thanks @Evgeni_Popov !

The DrawText call, the two colors, I’m unclear what is determining the normal and what is determining the height?

Normals are encoded this way? In rgb?

https://developer.download.nvidia.com/CgTutorial/cg_tutorial_chapter08.html

809fff, how is this a proper normal?

Normals are in rgb and heights in a.

0x809fff=rgb(128,159, 255)=(0.502, 0.623, 1)=nt after we divide by 255. To get the true normal, the shader code is doing n=nt*2 - 1 and normalize the result.

For the alpha channel, 0xff is the highest height and 0x00 the lowest.

2 Likes

What does nt mean? And why does it need to be normalized in the shader code?

More detailed info here - LearnOpenGL - Normal Mapping

1 Like

What does nt mean?

It means nothing, it’s simply a way for me to describe the computation that is done in the shader :slight_smile:

Frankly, I didn’t even check the shader code, maybe it’s not normalized (actually, it normalizes the normal after it has been transformed by the cotangent frame).

But the only thing that matters to you to use parallax effectively is to know that the shader is doing nt*2-1 where nt is the normal you put in the rgb component. It means that if the normal you want to use is (nx,ny,nz), you must transform these coordinates to (nx*0.5+0.5, ny*0.5+0.5, nz*0.5+0.5) before stuffing them in the bump/height texture. Also, don’t forget to multiply each component by 255 if you are creating an unsigned byte texture (which is what the PG is doing) and not a float texture!

Got it, thanks guys!