x


Transparency Shader that Allows Shadows

I'm trying to "hide" walls behind the player by setting their transparency down a bit. I don't want them to cast or receive shadows any differently than if they were opaque, just make them slightly transparent so the player is never hidden. Seems like most of what I'm finding is for people who want to allow transparent objects to cast shadows based on transparency, so I'm hoping there is a multi-pass system that might allow shadows to ignore the alpha channel of the object, but still make the object alpha-y? Could I maybe just modify the diffuse channel's alpha?

In a related note, I've found reference to the Visibility Bubble system implemented in a few games, but very little in regards to how to implement it. Any thoughts?

more ▼

asked Jul 17 '12 at 05:42 PM

irrationalistic gravatar image

irrationalistic
104 1 3 6

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

try this one

Shader "Transparent/Diffuse with Shadow" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}

SubShader {
	Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
	LOD 200
	Blend SrcAlpha OneMinusSrcAlpha
	CGPROGRAM
	#pragma surface surf Lambert addshadow
	
	sampler2D _MainTex;
	fixed4 _Color;
	
	struct Input {
		float2 uv_MainTex;
	};
	
	void surf (Input IN, inout SurfaceOutput o) {
		fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
		o.Albedo = c.rgb;
		o.Alpha = c.a;
	}
	ENDCG
}

Fallback "Transparent/VertexLit"
}

more ▼

answered Jul 17 '12 at 06:45 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

This is really close! The only issue is with objects in this pass ignoring shadows from other objects in the pass. If there is any fix, that would be awesome. Otherwise I might be able to make this work by having only the objects that need to be transparent having this shader and then toggling back to the default diffuse geometry shader.

Jul 17 '12 at 07:03 PM irrationalistic

this shader is more expensive then diffuse shader (cause no zbuffer writes and it is everything below this geometry renders even if it is hided totally). so you shouldn't use it for all walls - just for ones that have at least some transparency

Jul 17 '12 at 07:31 PM ScroodgeM

PS a shadow-receiving for transparency objects is not so easy due to shadow rendering mechanism

Jul 17 '12 at 07:41 PM ScroodgeM

Gotcha. That should be fine. I'll just toggle the shader on for objects I need it. It's only for objects blocking the view of the player, so they'll be out of focal point anyways. Thanks so much!

Jul 17 '12 at 09:34 PM irrationalistic

Thanks for that shader - works perfectly. :-)

Sep 07 '12 at 12:27 PM bateleur
(comments are locked)
10|3000 characters needed characters left

Works, thanks!

more ▼

answered Sep 14 '12 at 06:56 AM

brzozowsky gravatar image

brzozowsky
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1655
x245
x170

asked: Jul 17 '12 at 05:42 PM

Seen: 2406 times

Last Updated: Sep 14 '12 at 06:56 AM