- Home /
Question by
Le-Capitaine · Jan 24, 2020 at 01:29 PM ·
lightingcgprojector
[Cg] Lighting a projected alpha-blended decal
Managed to get a functional alpha projector, now I'm trying to get it lit. Problem is, it seems the projection only does one light at a time, meaning the decal is entirely affected by the light colour. The decal in the screenshot is supposed to be white and magenta, the blue light being a relatively small point light on the other side of the screen.
The code:
Shader "Custom/Projector Decal" {
Properties {
_MainTex ("Main Texture", 2D) = "grey" {}
_Mask ("Alpha Mask", 2D) = "white" {}
_Color ("Colour", Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="False" "RenderType"="Transparent" }
Cull Off
Offset -1, -1
Blend Zero SrcAlpha
CGPROGRAM
#include "UnityCG.cginc"
#pragma surface surf Decal alpha noambient addshadow vertex:fProjUVs
sampler2D _MainTex;
half4 _Color;
uniform float4x4 unity_Projector;
struct Input {
float2 uv_MainTex;
float4 projPos : TEXCOORD0;
};
void fProjUVs (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT (Input, o);
o.projPos = mul (unity_Projector, v.vertex);
}
void surf (Input IN, inout SurfaceOutput o) {
if (IN.projPos.z > 0) {
half4 c = tex2D (_MainTex, IN.projPos.xy / IN.projPos.w) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a * (1 - IN.projPos.z) * _Color.a;
}
}
half4 LightingDecal (SurfaceOutput s, half3 lightDir, half atten) {
half4 c;
c.rgb = (s.Albedo * (_LightColor0 * atten));
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
}
sauce.png
(406.3 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612222046im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem with lighting in CG Shader 1 Answer
ShaderLab builtin lighting properties are not correct? 0 Answers
Shader behaves different in other scene / project 0 Answers
How to add shadows to surface shader? 1 Answer
Accessing Light in Cg Shader 1 Answer