Vertex/Curved shader with scrolliung texture?

Hey guys,

I am VERY new to shader programming, and know very little about it. I needed a shader that would bend a plane to make it look like a horizon of the earth. I will have enemies spawning in the background and moving forward along this plane. My main problem is that when I apply the vertex shader to my plane, it doesn’t let me scroll the texture that I have assigned to the plane anymore.

Here is my shader script:

		_QOffset ("Offset", Vector) = (0,0,0,0)
		_Dist ("Distance", Float) = 100.0
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			#include "UnityCG.cginc"

                        sampler2D _MainTex;
			float4 _QOffset;
			float _Dist;
			
			struct v2f {
			    float4 pos : SV_POSITION;
			    float4 uv : TEXCOORD0;
			};

			v2f vert (appdata_base v)
			{
			    v2f o;
			    float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
			    float zOff = vPos.z/_Dist;
			    vPos += _QOffset*zOff*zOff;
			    o.pos = mul (UNITY_MATRIX_P, vPos);
			    o.uv = v.texcoord;
			    return o;
			}

			half4 frag (v2f i) : COLOR
			{
			    half4 col = tex2D(_MainTex, i.uv.xy);
			    return col;
			}
			ENDCG
		}
	}
	FallBack "Diffuse"
}

Here is my AnimatedUVs script:

    using UnityEngine;
    using System.Collections;
     
    public class AnimatedUVs : MonoBehaviour
    {
    public int materialIndex = 0;
    public Vector2 uvAnimationRate = new Vector2( 1.0f, 0.0f );
    public string textureName = "_MainTex";
     
    Vector2 uvOffset = Vector2.zero;
     
    void LateUpdate()
    {
    uvOffset += ( uvAnimationRate * Time.deltaTime );
    if( renderer.enabled )
    {
    renderer.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
    }
    }
    }

And here is my AnimatedTiledTexture script:

    using UnityEngine;
    using System.Collections;
     
    public class AnimatedUVs : MonoBehaviour
    {
    public int materialIndex = 0;
    public Vector2 uvAnimationRate = new Vector2( 1.0f, 0.0f );
    public string textureName = "_MainTex";
     
    Vector2 uvOffset = Vector2.zero;
     
    void LateUpdate()
    {
    uvOffset += ( uvAnimationRate * Time.deltaTime );
    if( renderer.enabled )
    {
    renderer.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
    }
    }
    }

This line;
o.uv = v.texcoord;
is taking the vertex UVs straight from the mesh and passing them in to the fragment shader, without any edits to them.

The method you’re using requires a bit more fiddling.

Before the vertex shader, add the line;
uniform float4 _MainTex_ST;

Then inside the vertex shader, replace this line
o.uv = v.texcoord;
with this one
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

Thank you very much Farfarer!

Maybe you could help me out with one more problem…

I have 3 “Spawners” that my enemies (cubes, for now) spawn from. I have attached the same shader to them and given them the same properties as my plane object. The cubes move forward along the plane, while the player doesn’t move forward at all… It gives the illusion that you are moving forward. But, for some reason, my cubes aren’t following along the same curvature as the plane. They aren’t lined up. I assigned the cubes the same exact properties as the plane, which I thought would do the trick.

Any ideas? I am not a mathemitician, and I do not know trig (which I am afraid may have to be used here).

Is there any way to make the bottom surface of a cube collider be constantly touching the surface of my plane?