Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Standard Shader, SetTextureOffset / SetTextureScale for emission only

Discussion in 'Shaders' started by ADoby, Jul 26, 2015.

  1. ADoby

    ADoby

    Joined:
    Dec 10, 2012
    Posts:
    21
    Hey,

    I wanted to animate my emission using offset.
    But it seems like standard shader only use _MainTex scale/offset instead of their own.
    This makes it impossible to animate only emission for me.

    I am new to all this multi_compile and shader_feature things.
    Just wanted to do the thing that worked all time long.

    Would be nice, if someone could help me.
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Just sample your emissive with new UVs. You can either specify these in a vertex program or just manipulate _MainTex's UVs

    Code (csharp):
    1.  
    2. Shader "Custom/NewShader" {
    3.     Properties {
    4.         _Color ("Color", Color) = (1,1,1,1)
    5.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    6.  
    7. //add your props for adjusting UVs
    8.         _EmissiveXOffset("Emissive X Offset", Float) = 0.0
    9.         _EmissiveYOffset("Emissive Y Offset", Float) = 0.0
    10.         _EmissiveTiling("Emissive Tiling", Float) = 1.0
    11. }
    12.  
    13. ....rest of shader here....
    14.  
    15. void surf (Input IN, inout SurfaceOutputStandard o) {
    16.          
    17.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    18.             o.Albedo = c.rgb;
    19.            
    20. //more efficient to setup UV's in vertex program but you get the idea
    21.             float2 emissiveUV = float2(IN.uv_MainTex.x + EmissiveXOffset, IN.uv_MainTex.y + EmissiveYOffset) * _EmissiveTiling;
    22.             fixed4 e = tex2D(_MainTex, emissiveUV);
    23.             o.Emission = e.rgb;
    24.  
     
    KhaledM likes this.
  3. ADoby

    ADoby

    Joined:
    Dec 10, 2012
    Posts:
    21
    Sory, as said, I am using the standard shader. I don't want to recode all needed features.
    Just wanted to animate the emission while keeping all the other features in place.
     
  4. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    There's no way to do that without a custom shader. The existing one is not designed for it, so, if that's what you want to do, you need to have a custom shader, either a modified standard shader (very difficult) or a surface shader that matches a majority of the standard shader features (simpler, as posted above).