Search Unity

How to make an object rotate around another in the vertex shader?

Discussion in 'Shaders' started by unity_ycAc5ynYwYxpFQ, Jun 9, 2020.

  1. unity_ycAc5ynYwYxpFQ

    unity_ycAc5ynYwYxpFQ

    Joined:
    Sep 17, 2017
    Posts:
    8
    Hi,

    I am trying to make a planet rotate around the sun in the vertex shader. But for now, the vertices are rotating around the planet's game object. Would you know how to solve this?



    Here is my code:

    Code (CSharp):
    1. // Rotating the planet
    2.                 /*float vertRotAngle = _Time *5;
    3.  
    4.                 float vertCosAngle = cos(vertRotAngle);
    5.  
    6.                 float vertSinAngle = sin(vertRotAngle);
    7.  
    8.                 float3x3 rotVertMatrix = float3x3(vertCosAngle, 0, -vertSinAngle,
    9.                     0, 1, 0,
    10.                     vertSinAngle, 0, vertCosAngle);
    11.  
    12.  
    13.                 float3 newVertPos = mul(rotVertMatrix, input.vertex);
    14.  
    15.                 output.vertex = UnityObjectToClipPos(newVertPos);
    16.  
    17.  
    18.                 float3 newNormalPos = mul(rotVertMatrix, input.normal);
    19.  
    20.                 output.normal = mul(unity_ObjectToWorld, newNormalPos);
    21.  
    22.                
    23.  
    24.  
    25.  
    26.                 output.worldPos = mul(unity_ObjectToWorld, input.vertex);
    27.                
    28.                
    29.                 */
     

    Attached Files: