Any way to rotate the environment map in a shader

I would like to add a kind of moving sheen effect to a shader. One way I thought of doing it would be to use the clear coat layer reflecting a rotating environment map.
The material in the Playcanvas editor has no controls to rotate the environment, so I’m wondering whether there is any way to control that in a custom shader? Perhaps by rotating the normals in the environment lookup (although I haven’t found the code for that part of the standard material yet, so not sure if that would work.)

In other words: which shader chunk can I modify to play with the way the environment reflection happens in the clear coat section?

We do have skybox rotation:

API: https://developer.playcanvas.com/api/pc.Scene.html#skyboxRotation

Do you need it to be specifically in the shader?

Yes, I want to do this at the shader level, for the cubemap added to the environment section of the material. Not at the global scene level.

Looking through the engine code, you might be able to use the following parameter in the standard material:

https://github.dev/playcanvas/engine/blob/72a1d068d11dff06a2de140dce392e2cb5e67cbe/src/scene/materials/standard-material.js#L807-L808

            if (!scene.skyboxRotation.equals(Quat.IDENTITY) && scene._skyboxRotationMat3) {
                this._setParameter('cubeMapRotationMatrix', scene._skyboxRotationMat3.data);
            }

@Leonidas , any input on this?

Right, I haven’t tried it before, but studying the engine source code what Yaustar proposes will work.

I think if the cubeMapRotationMatrix uniform is provided in your material as soon as material.update() is called the relevant shader chunk will be updated to use that rotation.

You can check here how to calculate the rotation matrix in your own script:

1 Like

Unfortunately this does not seem to work for me.

This is my attempt:


        this.app.assets.find('Glas Panelen', 'material').resource.setParameter('cubeMapRotationMatrix', this.app.scene._skyboxRotationMat3.data);
this.app.assets.find('Glas Panelen', 'material').resource.update();

This should copy the rotation of the scene cubemap if I am not mistaken.

this.app.scene._skyboxRotationMat3.data logs the following:
image

If want custom rotation to the environment map, to lets say rotate 180 degrees on y axis, how should I convert my x, y, z values to Mat3?