0
\$\begingroup\$

I know how to rotate cube map with legacy surface shader

Shader Rotation Matrix:

uniform float4x4 _Rotation;
          o.Emission = texCUBE (_Cube,  mul(_Rotation, float4(IN.worldRefl,0))).rgb;

RotateCubeMap:

using UnityEngine;

public class RotateCubeMap : MonoBehaviour
{
    public float speed = 20;
    private MeshRenderer _meshRenderer;

    private void Awake()
    {
        _meshRenderer = GetComponent<MeshRenderer>();
    }

    public void Update()
    {
        var rot = Quaternion.Euler (0, Time.time*speed, 0); 
        var m = new Matrix4x4 ();
        m.SetTRS(Vector3.zero, rot,new Vector3(1,1,1) );
        _meshRenderer.material.SetMatrix ("_Rotation", m);
    }
}

I tried to recreate it by shadergraph

enter image description here

but it didn't work!

enter image description here

I need a result like this:

enter image description here

\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

I understood what is my problem!

It's because Instead of multiplying WorldReflect with Rotation Matrix

I multiplied the ObjectSpaceViewDirection with Rotation Matrix

so I could fix it by using custom function:

enter image description here

Custom function basic setup:

enter image description here

use this script inside the shader:

float3 WorldReflect = reflect(-ObjectSpaceViewDirection, ObjectSpaceNormal);
OutPut =  SAMPLE_TEXTURECUBE_LOD(_CubeMap, sampler_CubeMap, mul(Rotation, float4(WorldReflect,0)) , 0);
\$\endgroup\$
2
  • \$\begingroup\$ I'm trying to recreate this, but cannot get the cubemap to move. Also how would you control speed with this? \$\endgroup\$
    – Laiton Kuu
    Commented May 19, 2020 at 20:53
  • \$\begingroup\$ @LaitonKuu hi you should attach the RotateCubeMap and change the speed \$\endgroup\$ Commented May 20, 2020 at 5:55
1
\$\begingroup\$

Possibly found a simpler way without a custom function.

Use the Rotate About Axis Node and just set the Axis you want to rotate around (vertical is Y) to 1 and others to 0.

Connect the ViewDirection Node to the In and the Out to the SampleCubeMap ViewDir.

\$\endgroup\$
0
\$\begingroup\$

I stumbled uppon this thread a bit late, but this could be of help to other people.

I recreated the rotation inside shadergraph. Heres the image:

Basically is just calculate reflection vector between view direction and normal vector, and then rotate about axis, in this case Y needs to be set to 1 and voila. Plug it into a Sample Cubemap.

Hope this helps! enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Although the image resembles the final result, it would be nice if you could walk through a detailed creation of the graph. \$\endgroup\$
    – liggiorgio
    Commented Jun 9, 2023 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .