|
|
|
@ -25,14 +25,25 @@ struct v2f
|
|
|
|
|
UNITY_POSITION(pos);
|
|
|
|
|
float3 normal : NORMAL;
|
|
|
|
|
float4 uv_decal : TEXCOORD0;
|
|
|
|
|
|
|
|
|
|
#ifdef DECAL_BASE_NORMAL
|
|
|
|
|
float2 uv_base : TEXCOORD1;
|
|
|
|
|
#endif //DECAL_BASE_NORMAL
|
|
|
|
|
|
|
|
|
|
float4 tSpace0 : TEXCOORD2;
|
|
|
|
|
float4 tSpace1 : TEXCOORD3;
|
|
|
|
|
float4 tSpace2 : TEXCOORD4;
|
|
|
|
|
fixed3 vlight : TEXCOORD5;
|
|
|
|
|
UNITY_SHADOW_COORDS(6)
|
|
|
|
|
|
|
|
|
|
#ifdef UNITY_PASS_FORWARDBASE
|
|
|
|
|
fixed3 vlight : TEXCOORD5;
|
|
|
|
|
UNITY_SHADOW_COORDS(6)
|
|
|
|
|
#endif //UNITY_PASS_FORWARDBASE
|
|
|
|
|
|
|
|
|
|
#ifdef UNITY_PASS_FORWARDADD
|
|
|
|
|
UNITY_LIGHTING_COORDS(5,6)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Projection matrix, normal, and tangent vectors
|
|
|
|
@ -44,7 +55,7 @@ float3 _DecalTangent;
|
|
|
|
|
// this must be defined in any shader using this cginc
|
|
|
|
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
|
|
|
|
|
|
|
|
|
|
v2f vert_forward_base(appdata_decal v)
|
|
|
|
|
v2f vert_forward(appdata_decal v)
|
|
|
|
|
{
|
|
|
|
|
v2f o;
|
|
|
|
|
UNITY_INITIALIZE_OUTPUT(v2f,o);
|
|
|
|
@ -59,7 +70,6 @@ v2f vert_forward_base(appdata_decal v)
|
|
|
|
|
|
|
|
|
|
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
|
|
|
|
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
|
|
|
|
|
//fixed3 worldTangent = fixed3(0,0,0);//UnityObjectToWorldDir(v.tangent.xyz);
|
|
|
|
|
fixed3 worldTangent = UnityObjectToWorldDir(_DecalTangent);
|
|
|
|
|
fixed3 worldBinormal = cross(worldTangent, worldNormal);
|
|
|
|
|
worldTangent = cross(worldNormal, worldBinormal);
|
|
|
|
@ -67,28 +77,32 @@ v2f vert_forward_base(appdata_decal v)
|
|
|
|
|
o.tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y);
|
|
|
|
|
o.tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z);
|
|
|
|
|
|
|
|
|
|
// SH/ambient light
|
|
|
|
|
#if UNITY_SHOULD_SAMPLE_SH
|
|
|
|
|
float3 shlight = ShadeSH9 (float4(worldNormal,1.0));
|
|
|
|
|
o.vlight = shlight;
|
|
|
|
|
#else
|
|
|
|
|
o.vlight = 0.0;
|
|
|
|
|
#endif // UNITY_SHOULD_SAMPLE_SH
|
|
|
|
|
// forward base pass specific lighting code
|
|
|
|
|
#ifdef UNITY_PASS_FORWARDBASE
|
|
|
|
|
// SH/ambient light
|
|
|
|
|
#if UNITY_SHOULD_SAMPLE_SH
|
|
|
|
|
float3 shlight = ShadeSH9 (float4(worldNormal,1.0));
|
|
|
|
|
o.vlight = shlight;
|
|
|
|
|
#else
|
|
|
|
|
o.vlight = 0.0;
|
|
|
|
|
#endif // UNITY_SHOULD_SAMPLE_SH
|
|
|
|
|
|
|
|
|
|
// vertex light
|
|
|
|
|
#ifdef VERTEXLIGHT_ON
|
|
|
|
|
o.vlight += Shade4PointLights (
|
|
|
|
|
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
|
|
|
|
|
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
|
|
|
|
|
unity_4LightAtten0, worldPos, worldNormal );
|
|
|
|
|
#endif // VERTEXLIGHT_ON
|
|
|
|
|
// vertex light
|
|
|
|
|
#ifdef VERTEXLIGHT_ON
|
|
|
|
|
o.vlight += Shade4PointLights (
|
|
|
|
|
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
|
|
|
|
|
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
|
|
|
|
|
unity_4LightAtten0, worldPos, worldNormal );
|
|
|
|
|
#endif // VERTEXLIGHT_ON
|
|
|
|
|
#endif // UNITY_PASS_FORWARDBASE
|
|
|
|
|
|
|
|
|
|
UNITY_TRANSFER_LIGHTING(o, 0.0); // pass shadow and, possibly, light cookie coordinates to pixel shader
|
|
|
|
|
// pass shadow and, possibly, light cookie coordinates to pixel shader
|
|
|
|
|
UNITY_TRANSFER_LIGHTING(o, 0.0);
|
|
|
|
|
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fixed4 frag_forward_base(v2f IN) : SV_Target
|
|
|
|
|
fixed4 frag_forward(v2f IN) : SV_Target
|
|
|
|
|
{
|
|
|
|
|
DecalSurfaceInput i;
|
|
|
|
|
SurfaceOutput o;
|
|
|
|
@ -98,7 +112,7 @@ fixed4 frag_forward_base(v2f IN) : SV_Target
|
|
|
|
|
|
|
|
|
|
float3 worldPos = float3(IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w);
|
|
|
|
|
float3 worldTan = float3(IN.tSpace0.x, IN.tSpace1.x, IN.tSpace2.x);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef USING_DIRECTIONAL_LIGHT
|
|
|
|
|
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(worldPos));
|
|
|
|
|
#else
|
|
|
|
@ -135,11 +149,19 @@ fixed4 frag_forward_base(v2f IN) : SV_Target
|
|
|
|
|
worldN = normalize(worldN);
|
|
|
|
|
o.Normal = worldN;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//KSP lighting function
|
|
|
|
|
c += LightingBlinnPhongSmooth(o, lightDir, viewDir, atten);
|
|
|
|
|
c.rgb += o.Emission;
|
|
|
|
|
c.rgb += o.Albedo * IN.vlight;
|
|
|
|
|
|
|
|
|
|
#ifdef UNITY_PASS_FORWARDBASE
|
|
|
|
|
c.rgb += o.Emission;
|
|
|
|
|
c.rgb += o.Albedo * IN.vlight;
|
|
|
|
|
#endif //UNITY_PASS_FORWARDBASE
|
|
|
|
|
|
|
|
|
|
#ifdef UNITY_PASS_FORWARDADD
|
|
|
|
|
c.rgb *= c.a;
|
|
|
|
|
c.a = 0.0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|