Search Unity

Modifying UV Values in a Shader

Discussion in 'Shaders' started by Brian-Brookwell, Apr 2, 2015.

  1. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    I'm trying to create a shader that uses a vertical slice of rock stratigraphy and bends it using a deformation texture map. It compiles okay until I try to modify the V value of the stratigraphy sampler. At that point, I get an error message that references a line completely out of the program:

    Shader error in 'Custom/Terrain': cannot implicitly convert from 'float3' to 'float4' at line 106

    I've written a few shaders but this is driving me to distraction.

    Shader "Custom/Terrain" {
    Properties {
    _Stratigraphy ("Rock Layers", 2D) = "white" {}
    _Deformation ("Deformation", 2D) = "white" {}
    _VScale ("Vertical Scale", Float) = 1
    }

    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert

    struct Input {
    float4 worldPos;
    float2 uv_Stratigraphy;
    float2 uv_Deformation;
    };

    sampler2D _Stratigraphy;
    sampler2D _Deformation;
    float _VScale;

    void surf (Input IN, inout SurfaceOutput OUT) {
    float vOffset = tex2D (_Deformation, IN.uv_Deformation).r * IN.worldPos.y *_VScale;
    float2 uv = IN.uv_Stratigraphy;
    uv[1] += vOffset;
    OUT.Albedo = tex2D (_Stratigraphy, uv).rgb;
    }
    ENDCG
    }
    //Fallback "Diffuse"
    }
     
  2. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    Just an addendum: It's only when I add the line: uv[1] += vOffset; that the error shows up.
     
  3. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    uv.y += vOffset; ?
     
  4. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    I have a stratigraphy that's represented as a texture map. The second texture map is supplying the deformation to that basic stratigraphy. What I want to do is take the base position UV and shift it up or down in y based on the deformation value