Scale the camera view along axis?

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.

1 Like

I suspect you can do this by manipulating the Camera’s projection matrix directly:

https://docs.unity3d.com/ScriptReference/Camera-projectionMatrix.html

Or perhaps the world matrix:

https://docs.unity3d.com/ScriptReference/Camera-worldToCameraMatrix.html

Not sure which would be correct in your specific case.

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

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. :slight_smile:

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

I tried to use a custom shader with a vert method, and tested 3 cubes

void vert(inout appdata_full data){
            float4 modifiedPos = data.vertex;
            modifiedPos.x *= _scaleX;
            modifiedPos.y *= _scaleY;
            modifiedPos.z *= _scaleZ;
                        
            data.vertex = modifiedPos;
        }

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

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

I posted this Dynamic Batching question in the Shader forum and got the answer: