Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scale the camera view along axis?

Discussion in 'Editor & General Support' started by CHOPJZL, Apr 1, 2021.

  1. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    Hi,
    Is it possible to scale the camera view along axis so that everything in the scene looks scaled? For example, scale Y-axis to 1.5, then the gameobjects all become 1.5 times taller. But their transform is not changed.

    I don't want to just scale the gameobject because I want to keep their transform in case not break game logic.
     
    IronOG likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
  3. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    How should I do it to scale along xyz axis? and I need to use orthographic view, I tried the projection matrix's example the camera becomes perspective
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    My linear math is too rusty for this. The way I see it, you have two possible approaches:

    - learn and research the linear math required and figure out how it is applied in these matricies in the Unity3D closed-source game engine. And then forget it all a week later.

    - set up your camera as it is now, read each matrix and iterate by changing values that are 1.0 into either 1.5 or else 0.677 and see if it does what you want.

    I know which way I would start with. :)
     
  5. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    Maybe I didn't set the right parameter, I think the matrix is not what I want.

    I tried the change m[0,0], m[1,1] and the whole view get scaled, not axis respectively.

    Take a cube for example, if scale Y-axis to 1.5, In the view the left right forward behind side will be 1.5 times taller, but up and down side will remain the same
     
  6. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    I tried to use a custom shader with a vert method, and tested 3 cubes
    Code (CSharp):
    1. void vert(inout appdata_full data){
    2.             float4 modifiedPos = data.vertex;
    3.             modifiedPos.x *= _scaleX;
    4.             modifiedPos.y *= _scaleY;
    5.             modifiedPos.z *= _scaleZ;
    6.                        
    7.             data.vertex = modifiedPos;
    8.         }
    3box vertex.jpg

    The left pic should be the result of the shader, but why it is different in the game?
     
  7. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    After I turn off Dynamic Batching in Project Settings, the shader become the same in Scene and Game.

    But why is this? Is it a bug? I am using 2020.3.0f1c1
     
  8. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    I posted this Dynamic Batching question in the Shader forum and got the answer: