None tranparent glass shader

I’ve been trying to get some ‘realistic’ looking window glass by using a base texture and a cubemap, however i’ve been unable to create a nice result. The glass shouldn’t be to heavy to render (no realtime i guess) and shouldn’t be tranparent since this would require me to model the inside of the building/object.

Any suggestions?

You could probably get a nice look with using a fresnel like effect to control how bright a cubemap reflection is (showing more at higher angles than when directly viewed) and maybe have a faint normal map on that to give the impression of ever so slightly warped glass (like in Doom 3, only not transparent in this case).

There’s a shader elsewhere on the forum that does that recently popular trick of pretending to show the interior of a room behind the glass, it looks really neat, but might not be suitable for everything.

Ok this is my first proper attempt at making a shader via Strumpy’s Shader Editor, so excuse it for being terrible. :slight_smile: I wanted the Dirt on Glass texture to only show the darker parts not the lighter ones, but can’t get it to work, but you can screw around with the color and the slider to approximate it.

Yeah, it’s rubbish but it’s better than a kick up the arse as my dad would say.

Shader "Crap/Glass"
{
	Properties
	{
_Color("Base Color", Color) = (1,0,0,1)
_RimColor("Rim Color", Color) = (0.0597015,0.2503912,1,1)
_MySpecColor("Specular Color", Color) = (1,1,1,1)
_DirtonGlass("Dirt on Glass", 2D) = "white" {}
_Normalmap("Normalmap", 2D) = "normal" {}
_SamplerCube("Reflection", Cube) = "" {}
_RimPower("Rim Power", Range(-0.8831257,5) ) = 1.8
_SpecPower("Specular Power", Range(0.1,1) ) = 0.9

_Rangeaaa("Dirt Amount", Range(0,1) ) = 0.5

	}

	SubShader
	{
		Tags
		{
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"

		}


Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}


		CGPROGRAM
#pragma surface surf BlinnPhongEditor  vertex:vert
#pragma target 3.0


float4 _Color;
sampler2D _DirtonGlass;
float _Rangeaaa;
sampler2D _Normalmap;
float4 _RimColor;
samplerCUBE _SamplerCube;
float _RimPower;
float _SpecPower;
float4 _MySpecColor;

			struct EditorSurfaceOutput {
				half3 Albedo;
				half3 Normal;
				half3 Emission;
				half3 Gloss;
				half Specular;
				half Alpha;
			};

			inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
			{
float4 Multiply1=float4(s.Albedo, 1.0) * light;
float4 Splat0=light.w;
float4 Multiply0=float4(s.Gloss, 1.0) * Splat0;
float4 Multiply2=light * Multiply0;
float4 Add2=Multiply1 + Multiply2;
float4 Mask1=float4(Add2.x,Add2.y,Add2.z,0.0);
float4 Luminance1= float4( Luminance( Multiply0.xyz ) );
float4 Add0=Luminance1 + float4(s.Albedo, 1.0);
float4 Mask0=float4(0.0,0.0,0.0,Add0.w);
float4 Add1=Mask1 + Mask0;
return Add1;

			}

			inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
			{
				half3 h = normalize (lightDir + viewDir);

				half diff = max (0, dot (s.Normal, lightDir));

				float nh = max (0, dot (s.Normal, h));
				float spec = pow (nh, s.Specular*128.0);

				half4 res;
				res.rgb = _LightColor0.rgb * diff * atten * 2.0;
				res.w = spec * Luminance (_LightColor0.rgb);

				return LightingBlinnPhongEditor_PrePass( s, res );
			}

			struct Input {
				float2 uv_DirtonGlass;
float2 uv_Normalmap;
float3 viewDir;

			};


			void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);


			}


			void surf (Input IN, inout EditorSurfaceOutput o) {
				o.Normal = float3(0.0,0.0,1.0);
				o.Alpha = 1.0;
				o.Albedo = 0.0;
				o.Emission = 0.0;
				o.Gloss=0.0;
				o.Specular=0.0;

float4 Tex2D0=tex2D(_DirtonGlass,(IN.uv_DirtonGlass.xyxy).xy);
float4 Min0=min(Tex2D0,_Rangeaaa.xxxx);
float4 Max0=max(_Color,Min0);
float4 Tex2DNormal0=float4(UnpackNormal( tex2D(_Normalmap,(IN.uv_Normalmap.xyxy).xy)).xyz, 1.0 );
float4 TexCUBE0=texCUBE(_SamplerCube,float4(IN.viewDir, 1.0));
float4 Fresnel1=float4( 1.0 - dot( normalize( float4(IN.viewDir, 1.0).xyz), normalize( Tex2DNormal0.xyz ) ) );
float4 Multiply1=TexCUBE0 * Fresnel1;
float4 Multiply2=_RimColor * Multiply1;
float4 Fresnel0_1_NoInput = float4(0,0,1,1);
float4 Fresnel0=float4( 1.0 - dot( normalize( float4(IN.viewDir, 1.0).xyz), normalize( Fresnel0_1_NoInput.xyz ) ) );
float4 Pow0=pow(Fresnel0,_RimPower.xxxx);
float4 Multiply0=Multiply2 * Pow0;
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Max0;
o.Normal = Tex2DNormal0;
o.Emission = Multiply0;
o.Specular = _SpecPower.xxxx;
o.Gloss = _MySpecColor;

				o.Normal = normalize(o.Normal);
			}
		ENDCG
	}
	Fallback "Diffuse"
}