x


Creating a mobile version of shader

I have created the following animated shader which takes two textures.

How can I rewrite this to achieve the same effect with vertex lighting instead of pixel lighting? I believe that I need a vertex & fragment shader. I am very new to shader programming and this would greatly help me to understand how they work.

This shader currently runs very poorly on iPhone 4G due to per-pixel lighting.

Shader "Custom/Animated/Layer" {

Properties {
    _Speed("Speed (XY)", Vector) = (1, 1, 0, 0)
    _Color("Color", Color) = (1, 0, 0)
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _LayerTex ("Layer (RGB)", 2D) = "bump" {}
}

SubShader {
CGPROGRAM
    #pragma surface surf Lambert

    sampler2D _MainTex;
    sampler2D _LayerTex;
    float4 _Color;
    float4 _Speed;

    struct Input {
       float2 uv_MainTex;
        float2 uv_LayerTex;
    };

    void surf(Input IN, inout SurfaceOutput o) {
       float4 maintex = tex2D(_MainTex, IN.uv_MainTex);
       float4 layertex = tex2D(_LayerTex, IN.uv_LayerTex + _Speed.xy * _Time.x);

       o.Albedo = lerp(maintex, maintex * _Color * 2, layertex.r);
       o.Alpha = maintex.a;
    }
ENDCG
}

FallBack "VertexLit"

}
more ▼

asked Feb 06 '12 at 12:03 AM

numberkruncher gravatar image

numberkruncher
2.2k 37 46 59

(comments are locked)
10|3000 characters needed characters left

0 answers: sort oldest
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2026
x2013
x1740
x3

asked: Feb 06 '12 at 12:03 AM

Seen: 775 times

Last Updated: Feb 06 '12 at 12:03 AM