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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Reflective/BumpedSpecularSRCGeometry shader not working in Unity 3?

Discussion in 'Shaders' started by Teejay5, Mar 23, 2011.

  1. Teejay5

    Teejay5

    Joined:
    Feb 26, 2010
    Posts:
    106
    I have this transparent bumped specular reflective shader that worked fine, but as soon as I upgraded to Unity 3, the reflective cubemap part doesn't work. After I set the cubemap for it to use, It does not show up on the object. How should I fix this? There aren't any errors or warnings showing up, so I have no idea what it could be...

    Here is the code:
    Code (csharp):
    1. Shader "Reflective/BumpedSpecularSRCGeometry" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,0)
    4.         _SpecColor ("Specular Color", Color) = (0,0,0,0)
    5.         _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    6.         _ReflectColor ("Reflection Color", Color) = (1.0, 1.0, 1.0, 0)
    7.         _MainTex ("Base (RGB) Gloss (A)", 2D) = "white"
    8.         _BumpMap ("Bumpmap", 2D) = "bump"
    9.         _Cube ("cubemap", Cube) = "_Skybox"
    10.     }
    11.     Category {
    12.         ZWrite Off
    13.         Alphatest Greater 0
    14.         Tags { "Queue" = "Geometry+1"}
    15.         Fog { Color [_AddFog] }
    16.         SubShader {
    17.         UsePass "Alpha/Glossy/BASE"
    18.         // ------------------------------------------------------
    19.         // ARB_FP, Geforce3
    20.         // ------------------------------------------------------
    21.             UsePass "Reflective/Bumped Unlit/BASE"
    22.             Pass {
    23.                 Name "BASE"
    24.                 Tags {"LightMode" = "Vertex"}
    25.                
    26.                 Blend SrcAlpha One
    27.                     Material {
    28.                         Diffuse [_Color]
    29.                         Ambient (1,1,1,1)
    30.                         Shininess 10
    31.                         Specular [_SpecColor]
    32.                     }
    33.                 Lighting On
    34.                 SeparateSpecular on
    35.                 SetTexture [_MainTex] {
    36.                     constantColor [_Color] Combine texture * primary DOUBLE, constant
    37.                 }
    38.             }
    39.             UsePass "Alpha/BumpedSpecular/PPL"
    40.         }
    41.     }
    42.     FallBack "Alpha/BumpedSpecular", 1
    43. }
    The transparency, bumpmapping, and lighting works, but the reflection is the only thing that doesn't...
     

    Attached Files:

  2. morris

    morris

    Joined:
    Mar 2, 2011
    Posts:
    7
    I also noticed that the cubemap element of this shader doesn't seem to work in Unity 3. I am curious to know why as well. Do you think there's a way to implement this shader in Strumpy Shader Editor?
     
    Last edited: Mar 24, 2011
  3. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Is it possible that the pass you've got is overwriting the reflective surface?

    i.e. move this line
    Code (csharp):
    1.  
    2. UsePass "Reflective/Bumped Unlit/BASE"
    3.  
    Below the scripted Pass {}
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Yeah, using two BASE passes in a row without a Blend statement will cause the second pass to simply overwrite the results of the first.
     
  5. Teejay5

    Teejay5

    Joined:
    Feb 26, 2010
    Posts:
    106
    Thanks for the answers! So were should I move it exactly? I tried several places below the Pass {}, but then it did one of two things: it either didn't work, or it returned an error. Where should I put UsePass "Reflective/Bumped Unlit/BASE" ?
     
    Last edited: Mar 25, 2011
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    You'll have to copy and rewrite one of the passes to use blending.
     
  7. Teejay5

    Teejay5

    Joined:
    Feb 26, 2010
    Posts:
    106
    I'm still confused about what I'm supposed to be doing here....I tried copying one of the passes (I think I'm doing it right) but the shader still doesnt give me the reflection...
     
  8. Teejay5

    Teejay5

    Joined:
    Feb 26, 2010
    Posts:
    106
    Can anyone here help? I tried removing one of the passes, then it let me see the reflective part, but not the transparent or specular effects.then I tried moving it to a different spot, which didnt do anything. I tried copying some of the passes and it didnt help. What should I modify here?
     
  9. chrisiona

    chrisiona

    Joined:
    Aug 25, 2010
    Posts:
    24
    hi there :)

    I have the same probleme!
    Any solutions?
     
  10. Teejay5

    Teejay5

    Joined:
    Feb 26, 2010
    Posts:
    106
    I haven't solved this yet, but I will try fiddling around with the code until it works! I NEED THIS SHADER!
     
  11. modena3d

    modena3d

    Joined:
    Sep 28, 2010
    Posts:
    12
    I'm having the same problem
     
  12. chrisiona

    chrisiona

    Joined:
    Aug 25, 2010
    Posts:
    24
    No solutions i'll go back on unity 2.6 lol
     
  13. Teejay5

    Teejay5

    Joined:
    Feb 26, 2010
    Posts:
    106
    gah, I still didnt figure out how to make this work...
    ..and I'm NOT going back to unity 2.6!! :mad:
     
  14. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I'm surprised this shader worked in Unity 2 to begin with. It overwrites its own passes, and refers to passes from shaders that didn't exist by default. It's no surprise that it doesn't work in Unity 3.

    Here is a modification of the built-in Reflective/Bumped Specular shader that supports transparency. Changes are in blue. It really is this simple with surface shaders.

    Code (csharp):
    1. Shader "Transparent/Reflective Bumped Specular" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _SpecColor ("Specular Color", Color) = (0.5,0.5,0.5,1)
    5.         _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    6.         _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    7.         _MainTex ("Base (RGB) RefStrGloss (A)", 2D) = "white" {}
    8.         _Cube ("Reflection Cubemap", Cube) = "" { TexGen CubeReflect }
    9.         _BumpMap ("Normalmap", 2D) = "bump" {}
    10.     }
    11.  
    12.     SubShader {
    13.         [COLOR="#4169e1"]Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}[/COLOR]
    14.         LOD 400
    15.         CGPROGRAM
    16.             [COLOR="#4169e1"]#pragma surface surf BlinnPhong alpha[/COLOR]
    17.             #pragma target 3.0
    18.  
    19.             sampler2D _MainTex;
    20.             sampler2D _BumpMap;
    21.             samplerCUBE _Cube;
    22.  
    23.             fixed4 _Color;
    24.             fixed4 _ReflectColor;
    25.             half _Shininess;
    26.  
    27.             struct Input {
    28.                 float2 uv_MainTex;
    29.                 float2 uv_BumpMap;
    30.                 float3 worldRefl;
    31.                 INTERNAL_DATA
    32.             };
    33.  
    34.             void surf (Input IN, inout SurfaceOutput o) {
    35.                 fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    36.                 fixed4 c = tex * _Color;
    37.                 o.Albedo = c.rgb;
    38.    
    39.                 o.Gloss = tex.a;
    40.                 o.Specular = _Shininess;
    41.    
    42.                 o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    43.    
    44.                 float3 worldRefl = WorldReflectionVector (IN, o.Normal);
    45.                 fixed4 reflcol = texCUBE (_Cube, worldRefl);
    46.                 reflcol *= tex.a;
    47.                 o.Emission = reflcol.rgb * _ReflectColor.rgb;
    48.                 [COLOR="#4169e1"]o.Alpha = c.a;[/COLOR]
    49.             }
    50.         ENDCG
    51.     }
    52.  
    53.     [COLOR="#4169e1"]FallBack "Transparent/Bumped Specular"[/COLOR]
    54. }
    55.  
     
  15. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,888
    HI there, I copied and pasted this code into an empty file exactly and saved it as a shader, but I'm getting an error:
    But all that's there is a needed closing curly brace, that closes SubShader, line 51.
    Can someone show me what the problem is?
    EDIT
    Ignore that, i had missed a curly brace.
     
    Last edited: Jun 24, 2011
  16. Jasper-Hesseling

    Jasper-Hesseling

    Joined:
    Jul 27, 2009
    Posts:
    34
    Thanks working like a charme.
     
  17. Loard

    Loard

    Joined:
    Oct 5, 2010
    Posts:
    14
    Hi! i tried to use this in unity 3.5 and is not working, i get a lot of error in the script.

    $error_shader.JPG

    Any chance to fix this? I'm not any good at shader scripting.

    Thanks!
     
  18. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You're copy and pasting nonsense text. Look at the errors.
     
  19. Loard

    Loard

    Joined:
    Oct 5, 2010
    Posts:
    14
    thanks.. i feel so dump right know.. work fine.
     
  20. stevemachineHK

    stevemachineHK

    Joined:
    May 6, 2010
    Posts:
    18
    Nonsense text? I got the same errors when i cut and paste the code, can you explain what you mean by the nonsense text?

    Thanks
     
  21. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Unity changed the way that code gets formatted on the forum, so the parts I highlighted in blue now just have raw BB tags around them. Remove the tags (in square brackets) and you should be fine.
     
  22. stevemachineHK

    stevemachineHK

    Joined:
    May 6, 2010
    Posts:
    18