unlit window glass

Hi!

I’m trying to get a good glass shader with cubemap reflections.

There’s no real light source in my scene, it’s all lightmapped.

I tried this shader from the forum

Shader "Glass" { 
   Properties { 
      _Color ("Main Color", Color) = (1,1,1,1) 
      _MainTex ("Base (RGB) Transparency (A)", 2D) = "white" 
      _Reflections ("Reflection cubemap", Cube) = "skybox" { TexGen CubeReflect } 
   } 
   SubShader { 
      Tags {"Queue" = "Transparent" } 
      Pass { 
         Blend SrcAlpha OneMinusSrcAlpha 
         ZWrite Off 
         Material { 
            Diffuse [_Color] 
         } 
         Lighting On 
         SetTexture [_MainTex] { 
            combine texture * primary double, texture * primary 
         } 
      } 
      Pass { 
         Blend One One 
         Material { 
            Diffuse [_Color] 
         } 
         Lighting On 
         SetTexture [_Reflections] { 
            combine texture 
            Matrix [_Reflection] 
         } 
      } 
   } 
   SubShader { 
      Tags {"Queue" = "Transparent" } 
      Pass { 
         Blend SrcAlpha OneMinusSrcAlpha 
         Material { 
            Diffuse [_Color] 
         } 
         Lighting On 
         SetTexture [_MainTex] { 
            combine texture * primary double, texture * primary 
         } 
      } 
   } 
}

… my problems are:

  • I am an idiot when it comes to writing shaders :frowning: - I’m just starting out…
  • all the stuff behind my glass material gets brightened up which is kinda unrealistic
  • the above shader doesn’t have a color when there’s no light in the scene

Now what I need is a transparent blueish material with a cubemap that gets reflected…

I’d be so glad if someone could help me a little in finding a solution :slight_smile:

Thanks a lot in advance !

Couldn’t you just create some lights specifically for the reflection shader.

You can use layer masks and the lights culling mask to do this.

Try this shader:

Shader "Glass (unlit)" { 
Properties { 
    _Color ("Glass Color", Color) = (1,1,1,0.5) 
    _Cube ("Reflection cubemap", Cube) = "" { TexGen CubeReflect } 
}
Category {
    Tags {"Queue" = "Transparent" } 
    Blend SrcAlpha OneMinusSrcAlpha
    ZWrite Off
    BindChannels {
        Bind "Vertex", vertex
        Bind "Normal", normal
    }
    // cards with cube maps
    SubShader { 
        Pass { 
            SetTexture [_Cube] {
                constantColor [_Color]
                combine texture * constant, constant
            } 
        } 
    } 
    // cards without cube maps - just simple transparency
    SubShader { 
        Pass { 
            SetTexture [_Dummy] { 
                constantColor [_Color]
                combine constant
            } 
        } 
    } 
}
}

This has only a cube map and a color. The color (and it’s alpha channel) define the color/transparency of the glass. This multiplies color with the cubemap, so it you have dark cubemap you’ll get dark glass. A more correct approach would probably be to add cubemap to glass’ color, let me know if that’s what you want.

:smile:

Wow, that’s exactly what I needed

  • thank you so very much =)

My approach was to take the Unify Wiki window shader and stripping it down to what I need (and still runs :wink: ) but I didn’t really know what I was doing…

But this one seems clear to me - thanks again !