KSP-Conformal-Decals/Assets/Shaders/DecalFeatureBumped.shader

115 lines
3.3 KiB
Plaintext
Raw Normal View History

Shader "ConformalDecals/Feature/Bumped"
2020-05-22 06:38:49 +00:00
{
Properties
{
_Decal("Decal Texture", 2D) = "gray" {}
_DecalBumpMap("Decal Normal Map", 2D) = "bump" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_Opacity("_Opacity", Range(0,1) ) = 1
}
SubShader
{
Tags { "Queue" = "Geometry+400" }
2020-05-22 06:38:49 +00:00
ZWrite Off
ZTest LEqual
Offset -1, -1
2020-05-22 06:38:49 +00:00
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
2020-05-24 18:41:09 +00:00
#pragma vertex vert_forward
#pragma fragment frag_forward
2020-05-22 06:38:49 +00:00
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
2020-05-22 06:38:49 +00:00
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "LightingKSP.cginc"
2020-05-22 06:38:49 +00:00
#include "DecalsCommon.cginc"
2020-05-24 18:41:09 +00:00
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));
2020-05-24 23:05:29 +00:00
clip(color.a - _Cutoff);
2020-05-24 18:41:09 +00:00
o.Normal = normal;
o.Albedo = color.rgb;
o.Alpha = color.a * _Opacity;
}
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"
2020-05-22 06:38:49 +00:00
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));
2020-05-24 23:05:29 +00:00
clip(color.a - _Cutoff);
2020-05-22 06:38:49 +00:00
o.Normal = normal;
2020-05-24 05:10:27 +00:00
o.Albedo = color.rgb;
o.Alpha = color.a * _Opacity;
2020-05-22 06:38:49 +00:00
}
ENDCG
}
// shadow casting support
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}