Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED] Trying to get my _Reflectiveness variable to work

Discussion in 'Shaders' started by pixpusher2, Dec 1, 2014.

  1. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Hi, I've pretty much zero knowledge on shaders, but I managed to cobble together a couple I found online.

    The shader is working well until after I tried changing this:
    Code (csharp):
    1. o.Emission = texCUBE (_Cube, IN.worldRefl).rgb * 0.5;
    to this:
    Code (csharp):
    1. o.Emission = texCUBE (_Cube, IN.worldRefl).rgb * _Reflectiveness;
    The _Reflectiveness is always zero regardless of the amount I set on the material itself. What did I do wrong?

    Full shader code below:
    Code (csharp):
    1. Shader "Custom/Mobile/Vertex Color Unlit Water" {
    2. Properties {
    3.     _SColor ("Color", Color) = (1,1,1,1)
    4.     _MainTex ("Texture", 2D) = "white" {}
    5.     _Cube ("Cubemap", Cube) = "" {}
    6.     _Reflectiveness ("Reflection Amount", Range(0,1.0)) = 0.5
    7. }
    8.  
    9. Category {
    10.     Tags { "Queue"="Geometry" }
    11.     Lighting Off
    12.     BindChannels {
    13.         Bind "Color", color
    14.         Bind "Vertex", vertex
    15.         Bind "TexCoord", texcoord
    16.     }
    17.  
    18.     // ---- Dual texture cards
    19.     SubShader {
    20.         Tags { "RenderType" = "Opaque" }
    21.         CGPROGRAM
    22.         #pragma surface surf Lambert
    23.         struct Input {
    24.             float3 worldRefl;
    25.         };
    26.         samplerCUBE _Cube;
    27.         float3 _Reflectiveness;
    28.         void surf (Input IN, inout SurfaceOutput o) {
    29.         o.Emission = texCUBE (_Cube, IN.worldRefl).rgb * _Reflectiveness;
    30.         }
    31.         ENDCG
    32.      
    33.         Pass {
    34.             Blend One One
    35.             SetTexture [_MainTex] {
    36.                 matrix [_OffsetTex]
    37.                 combine texture * primary
    38.             }
    39.             SetTexture [_MainTex] {
    40.                 constantColor [_SColor]
    41.                 combine previous lerp (previous) constant DOUBLE
    42.             }
    43.         }
    44.     }
    45.  
    46.     // ---- Single texture cards (does not do vertex colors)
    47.     SubShader {
    48.         Pass {
    49.             SetTexture [_MainTex] {
    50.             matrix [_OffsetTex]
    51.                 constantColor [_SColor]
    52.                 combine texture lerp(texture) constant DOUBLE
    53.             }
    54.         }
    55.     }
    56. }
    57. }
    Thanks!
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Maybe because you're trying to access it as a float3, while it is a float?
     
    pixpusher2 likes this.
  3. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Not sure why I didn't spot that! Thanks, it's working fine now