mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Enable multi-pass forward rendering
This commit is contained in:
parent
03b647560e
commit
bd83729e5a
@ -22,8 +22,8 @@ Shader "ConformalDecals/Feature/Bumped"
|
|||||||
Blend SrcAlpha OneMinusSrcAlpha
|
Blend SrcAlpha OneMinusSrcAlpha
|
||||||
|
|
||||||
CGPROGRAM
|
CGPROGRAM
|
||||||
#pragma vertex vert_forward_base
|
#pragma vertex vert_forward
|
||||||
#pragma fragment frag_forward_base
|
#pragma fragment frag_forward
|
||||||
|
|
||||||
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
|
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
|
||||||
|
|
||||||
@ -62,6 +62,53 @@ Shader "ConformalDecals/Feature/Bumped"
|
|||||||
ENDCG
|
ENDCG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pass
|
||||||
|
{
|
||||||
|
Name "FORWARD"
|
||||||
|
Tags { "LightMode" = "ForwardAdd" }
|
||||||
|
Blend One One
|
||||||
|
|
||||||
|
CGPROGRAM
|
||||||
|
#pragma vertex vert_forward
|
||||||
|
#pragma fragment frag_forward
|
||||||
|
|
||||||
|
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
|
||||||
|
|
||||||
|
#include "UnityCG.cginc"
|
||||||
|
#include "Lighting.cginc"
|
||||||
|
#include "AutoLight.cginc"
|
||||||
|
#include "LightingKSP.cginc"
|
||||||
|
#include "DecalsCommon.cginc"
|
||||||
|
|
||||||
|
sampler2D _Decal;
|
||||||
|
sampler2D _DecalBumpMap;
|
||||||
|
|
||||||
|
float _Cutoff;
|
||||||
|
float _Opacity;
|
||||||
|
|
||||||
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||||
|
{
|
||||||
|
fixed4 projUV = UNITY_PROJ_COORD(IN.uv_decal);
|
||||||
|
|
||||||
|
// since I cant easily affect the clamping mode in KSP, do it here
|
||||||
|
clip(projUV.xyz);
|
||||||
|
clip(1-projUV.xyz);
|
||||||
|
|
||||||
|
// clip backsides
|
||||||
|
clip(dot(_DecalNormal, IN.normal));
|
||||||
|
|
||||||
|
float4 color = tex2D(_Decal, projUV);
|
||||||
|
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, projUV));
|
||||||
|
//clip(color.a - _Cutoff);
|
||||||
|
|
||||||
|
o.Normal = normal;
|
||||||
|
o.Albedo = color.rgb;
|
||||||
|
o.Alpha = color.a * _Opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
ENDCG
|
||||||
|
}
|
||||||
|
|
||||||
// shadow casting support
|
// shadow casting support
|
||||||
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
|
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,25 @@ struct v2f
|
|||||||
UNITY_POSITION(pos);
|
UNITY_POSITION(pos);
|
||||||
float3 normal : NORMAL;
|
float3 normal : NORMAL;
|
||||||
float4 uv_decal : TEXCOORD0;
|
float4 uv_decal : TEXCOORD0;
|
||||||
|
|
||||||
#ifdef DECAL_BASE_NORMAL
|
#ifdef DECAL_BASE_NORMAL
|
||||||
float2 uv_base : TEXCOORD1;
|
float2 uv_base : TEXCOORD1;
|
||||||
#endif //DECAL_BASE_NORMAL
|
#endif //DECAL_BASE_NORMAL
|
||||||
|
|
||||||
float4 tSpace0 : TEXCOORD2;
|
float4 tSpace0 : TEXCOORD2;
|
||||||
float4 tSpace1 : TEXCOORD3;
|
float4 tSpace1 : TEXCOORD3;
|
||||||
float4 tSpace2 : TEXCOORD4;
|
float4 tSpace2 : TEXCOORD4;
|
||||||
|
|
||||||
|
#ifdef UNITY_PASS_FORWARDBASE
|
||||||
fixed3 vlight : TEXCOORD5;
|
fixed3 vlight : TEXCOORD5;
|
||||||
UNITY_SHADOW_COORDS(6)
|
UNITY_SHADOW_COORDS(6)
|
||||||
|
#endif //UNITY_PASS_FORWARDBASE
|
||||||
|
|
||||||
|
#ifdef UNITY_PASS_FORWARDADD
|
||||||
|
UNITY_LIGHTING_COORDS(5,6)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Projection matrix, normal, and tangent vectors
|
// Projection matrix, normal, and tangent vectors
|
||||||
@ -44,7 +55,7 @@ float3 _DecalTangent;
|
|||||||
// this must be defined in any shader using this cginc
|
// this must be defined in any shader using this cginc
|
||||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o);
|
||||||
|
|
||||||
v2f vert_forward_base(appdata_decal v)
|
v2f vert_forward(appdata_decal v)
|
||||||
{
|
{
|
||||||
v2f o;
|
v2f o;
|
||||||
UNITY_INITIALIZE_OUTPUT(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 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||||
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
|
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||||
//fixed3 worldTangent = fixed3(0,0,0);//UnityObjectToWorldDir(v.tangent.xyz);
|
|
||||||
fixed3 worldTangent = UnityObjectToWorldDir(_DecalTangent);
|
fixed3 worldTangent = UnityObjectToWorldDir(_DecalTangent);
|
||||||
fixed3 worldBinormal = cross(worldTangent, worldNormal);
|
fixed3 worldBinormal = cross(worldTangent, worldNormal);
|
||||||
worldTangent = cross(worldNormal, worldBinormal);
|
worldTangent = cross(worldNormal, worldBinormal);
|
||||||
@ -67,6 +77,8 @@ v2f vert_forward_base(appdata_decal v)
|
|||||||
o.tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y);
|
o.tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y);
|
||||||
o.tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z);
|
o.tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z);
|
||||||
|
|
||||||
|
// forward base pass specific lighting code
|
||||||
|
#ifdef UNITY_PASS_FORWARDBASE
|
||||||
// SH/ambient light
|
// SH/ambient light
|
||||||
#if UNITY_SHOULD_SAMPLE_SH
|
#if UNITY_SHOULD_SAMPLE_SH
|
||||||
float3 shlight = ShadeSH9 (float4(worldNormal,1.0));
|
float3 shlight = ShadeSH9 (float4(worldNormal,1.0));
|
||||||
@ -82,13 +94,15 @@ v2f vert_forward_base(appdata_decal v)
|
|||||||
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
|
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
|
||||||
unity_4LightAtten0, worldPos, worldNormal );
|
unity_4LightAtten0, worldPos, worldNormal );
|
||||||
#endif // VERTEXLIGHT_ON
|
#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;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed4 frag_forward_base(v2f IN) : SV_Target
|
fixed4 frag_forward(v2f IN) : SV_Target
|
||||||
{
|
{
|
||||||
DecalSurfaceInput i;
|
DecalSurfaceInput i;
|
||||||
SurfaceOutput o;
|
SurfaceOutput o;
|
||||||
@ -135,11 +149,19 @@ fixed4 frag_forward_base(v2f IN) : SV_Target
|
|||||||
worldN = normalize(worldN);
|
worldN = normalize(worldN);
|
||||||
o.Normal = worldN;
|
o.Normal = worldN;
|
||||||
|
|
||||||
|
|
||||||
//KSP lighting function
|
//KSP lighting function
|
||||||
c += LightingBlinnPhongSmooth(o, lightDir, viewDir, atten);
|
c += LightingBlinnPhongSmooth(o, lightDir, viewDir, atten);
|
||||||
|
|
||||||
|
#ifdef UNITY_PASS_FORWARDBASE
|
||||||
c.rgb += o.Emission;
|
c.rgb += o.Emission;
|
||||||
c.rgb += o.Albedo * IN.vlight;
|
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;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user