Hey. I'm working on an additive projector shader for my game. I'm going to try it as a fallback from pixel lit spotlights for car headlights. I've got something working but I'd like the effect to be more intense. (While staying within the fixed function pipeline) I may be tired or I just can't figure it out. The neat thing about it currently is that you can color the "light" texture. I admit that I do not completely understand how the projector shaders work. What is the definition of "fresnel", here? Thanks, -Jon edit: put in nicholas' fog fix Code (csharp): SHADER "Projector/Projector Additive" { Properties { _ShadowTex ("Cookie", 2D) = "fresnel.png" { TexGen ObjectLinear } _FalloffTex ("FallOff", 2D) = "fresnel.png" { TexGen ObjectLinear } } SUBSHADER { Pass { ZWrite off Offset -1, -1 Fog { Color (0,0,0,0) } AlphaTest Greater 0 ColorMask RGB // Get fresnel value into alpha. This is used in next stage. blend DstColor SrcAlpha SetTexture [_ShadowTex] { combine texture, ONE - texture Matrix [_Projector] } SetTexture [_FalloffTex] { constantColor (1,1,1,0) combine previous lerp (texture) constant Matrix [_ProjectorClip] } } } }
The "fresnel.png" is a leftover from Unity 0.3 (or thereabouts). It is a default texture in case none is assigned... AFAIR the builtins are: "black", "white", "bump"... Now that you can assign textures to the shaders there's not a big reason for it. The Offset -1, -1 is to avoid any Z-fighting. It raises the depth of the rendered pixels (without altering their positions) The fog { Color (1,1,1,1) } makes the object fade to white as the distance increases. As this shader is multiplied in, that means the shadow fades to transparency as fog kicks in. Since you're doing an additive blend, you want to set fog color to black: Fog { Color (0,0,0,0) }[/b]
So in the ShadowProjector shader: // Get fresnel value into alpha. This is used in next stage. Could be rephrased to: // Get texture value into alpha. This is used in next stage. ? As for the intensity, all I can think now is to add another pass, which would be a tad costly for my situation, I think. Think there is a way to do it in one? Thanks a lot, -Jon
You have spare space in the first combiner. Try sth like this: Code (csharp): SHADER "Projector/Projector Additive" { Properties { _Color ("Tint Color (RGB), Color) = (1,1,1,0) _ShadowTex ("Cookie", 2D) = "fresnel.png" { TexGen ObjectLinear } _FalloffTex ("FallOff", 2D) = "fresnel.png" { TexGen ObjectLinear } } SUBSHADER { Pass { ZWrite off Offset -1, -1 Fog { Color (1,1,1) } AlphaTest Greater 0 ColorMask RGB // Get fresnel value into alpha. This is used in next stage. blend DstColor SrcAlpha SetTexture [_ShadowTex] { combine constant * texture, ONE - texture constantColor [_Color] Matrix [_Projector] } SetTexture [_FalloffTex] { constantColor (1,1,1,0) combine previous lerp (texture) constant Matrix [_ProjectorClip] } } } } Note: This is untested - but you can see the changes I made in the first combiner - multiplied in a constant color, which gets set from the _Color property I added above. Also, depending on which GFX card you target, you can have more than 2 combiners. Here are the caps: ATI Rage128, Geforce2, Geforce4MX: 2 combiners ATI Radeon7000, R7500: 3 combiners NVidia 3TI, 4 TI, any Geforce: 4 combiners ATI Radeon9000 or above: 6 combiners
Looking at your blend set up, it looks a bit weird... You basically multiply your alpha with the existing color and then add in the color you calculated... I think you want Blend One One for a pure additive, or a Blend OneMinusSrcColor One for a softer look
Hey aarku, any more updates to your additive projection shader? Custom Shaders are something I haven't even begun to get my head around yet, but the Blob Shadow in 1.2 got me excited about them. I'd really like to have some spotlight action in the game I'm working on. Any chance of putting your results up on the WIKI?