I literally just want to move a vertex up by one unit

Hi, I got this basic unlit shader, now I simply want to move up the vertices by one world unit, thats it. Any help is appreciated.

The code below does not work, it moves the tile up by more than 1 unit.
Multiplying by unity_ObjectToWorld or unity_WorldToObject does not change the position at all.

// Upgrade NOTE: replaced ‘_Object2World’ with ‘unity_ObjectToWorld’
// Upgrade NOTE: replaced ‘_World2Object’ with ‘unity_WorldToObject’

// Upgrade NOTE: replaced ‘_Object2World’ with ‘unity_ObjectToWorld’

// Upgrade NOTE: replaced ‘_Object2World’ with ‘unity_ObjectToWorld’
// Upgrade NOTE: replaced ‘_World2Object’ with ‘unity_WorldToObject’

// Upgrade NOTE: replaced ‘_Object2World’ with ‘unity_ObjectToWorld’

Shader “Unlit/CurvatureShader”
{
Properties
{
_MainTex (“Texture”, 2D) = “white” {}
_MapWidth (“Map Width”, Int) = 0
_CamX (“Camera X”, Float) = 0
}
SubShader
{
Tags { “Queue”=“Transparent”
“IgnoreProjector”=“True”
“RenderType”=“Transparent”
“PreviewType”=“Plane”
“CanUseSpriteAtlas”=“True”
}
LOD 100

Cull Off
Lighting Off
ZWrite Off
Fog { Mode Off }
Blend One OneMinusSrcAlpha

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog

#include “UnityCG.cginc”

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};

sampler2D _MainTex;
float4 _MainTex_ST;

v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);

float3 worldPos = mul(unity_ObjectToWorld, o.vertex.xyz);
worldPos.y += 1.0;
o.vertex.xyz = mul(unity_WorldToObject, worldPos);

o.uv = TRANSFORM_TEX(v.uv, _MainTex);

UNITY_TRANSFER_FOG(o,o.vertex);

return o;
}

fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}

Look at the names of the matrices and functions you’re using, the order you’re using them in, and what you’re using them on.

o.vertex = UnityObjectToClipPos(v.vertex);

That’s taking an object space position (v.vertex) and outputting a clip space position (saved to o.vertex). Object space is the original mesh vertex positions, and clip space can be thought of as projection or screen space.

float3 worldPos = mul(unity_ObjectToWorld, o.vertex.xyz);

There are two issues here. First you’re using the matrix to convert an object space position into world space. But you’re applying that to o.vertex, which you just transformed to a clip space position. So you’re transforming a clip space position into … something? It won’t be world space since you didn’t start with object space. The second problem is if the vector your transforming is 3 components (aka .xyz) it’ll be treated as a direction and not a position. You need to pass a 4 component vector with the w == 1 (which is the default for v.vertex).

So what you want is this:

float4 worldPos = mul(unity_ObjectToWorld, **v.**vertex);
worldPos.y += 1.0;
**v.**vertex = mul(unity_WorldToObject, worldPos);
o.vertex = UnityObjectToClipPos(v.vertex);

There’s one more thing you can do, which is UnityObjectToClipPos(v.vertex) is basically just doing this:

mul(UNITY_MATRIX_MV, mul(unity_ObjectToWorld, v.vertex));

So you could change the above to this:

float4 worldPos = mul(unity_ObjectToWorld, v.vertex);
worldPos.y += 1.0;
o.vertex = mul(UNITY_MATRIX_MV, worldPos);