mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add specular paint shader
This commit is contained in:
parent
8ca3925e04
commit
dc25576911
@ -4,7 +4,7 @@ Shader "ConformalDecals/Feature/Bumped"
|
|||||||
{
|
{
|
||||||
[Header(Texture Maps)]
|
[Header(Texture Maps)]
|
||||||
_Decal("Decal Texture", 2D) = "gray" {}
|
_Decal("Decal Texture", 2D) = "gray" {}
|
||||||
_DecalBumpMap("Decal Bump Map", 2D) = "bump" {}
|
_BumpMap("Decal Bump Map", 2D) = "bump" {}
|
||||||
|
|
||||||
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
|
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
|
||||||
_Opacity("_Opacity", Range(0,1) ) = 1
|
_Opacity("_Opacity", Range(0,1) ) = 1
|
||||||
@ -35,16 +35,18 @@ Shader "ConformalDecals/Feature/Bumped"
|
|||||||
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
|
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
|
||||||
|
|
||||||
sampler2D _Decal;
|
sampler2D _Decal;
|
||||||
sampler2D _DecalBumpMap;
|
sampler2D _BumpMap;
|
||||||
|
|
||||||
float4 _Decal_ST;
|
float4 _Decal_ST;
|
||||||
float4 _DecalBumpMap_ST;
|
float4 _BumpMap_ST;
|
||||||
|
|
||||||
float _Cutoff;
|
float _Cutoff;
|
||||||
float _Opacity;
|
float _Opacity;
|
||||||
float _RimFalloff;
|
float _RimFalloff;
|
||||||
float4 _RimColor;
|
float4 _RimColor;
|
||||||
|
|
||||||
|
#define DECAL_NORMAL
|
||||||
|
|
||||||
#include "UnityCG.cginc"
|
#include "UnityCG.cginc"
|
||||||
#include "Lighting.cginc"
|
#include "Lighting.cginc"
|
||||||
#include "AutoLight.cginc"
|
#include "AutoLight.cginc"
|
||||||
@ -54,7 +56,7 @@ Shader "ConformalDecals/Feature/Bumped"
|
|||||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||||
{
|
{
|
||||||
float4 color = tex2D(_Decal, IN.uv_decal);
|
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||||
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, IN.uv_decal));
|
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_bump));
|
||||||
|
|
||||||
// clip alpha
|
// clip alpha
|
||||||
clip(color.a - _Cutoff);
|
clip(color.a - _Cutoff);
|
||||||
@ -84,16 +86,18 @@ Shader "ConformalDecals/Feature/Bumped"
|
|||||||
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
|
#pragma multi_compile_fwdadd nolightmap nodirlightmap nodynlightmap
|
||||||
|
|
||||||
sampler2D _Decal;
|
sampler2D _Decal;
|
||||||
sampler2D _DecalBumpMap;
|
sampler2D _BumpMap;
|
||||||
|
|
||||||
float4 _Decal_ST;
|
float4 _Decal_ST;
|
||||||
float4 _DecalBumpMap_ST;
|
float4 _BumpMap_ST;
|
||||||
|
|
||||||
float _Cutoff;
|
float _Cutoff;
|
||||||
float _Opacity;
|
float _Opacity;
|
||||||
float _RimFalloff;
|
float _RimFalloff;
|
||||||
float4 _RimColor;
|
float4 _RimColor;
|
||||||
|
|
||||||
|
#define DECAL_NORMAL
|
||||||
|
|
||||||
#include "UnityCG.cginc"
|
#include "UnityCG.cginc"
|
||||||
#include "Lighting.cginc"
|
#include "Lighting.cginc"
|
||||||
#include "AutoLight.cginc"
|
#include "AutoLight.cginc"
|
||||||
@ -103,7 +107,7 @@ Shader "ConformalDecals/Feature/Bumped"
|
|||||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||||
{
|
{
|
||||||
float4 color = tex2D(_Decal, IN.uv_decal);
|
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||||
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, IN.uv_decal));
|
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_bump));
|
||||||
|
|
||||||
// clip alpha
|
// clip alpha
|
||||||
clip(color.a - _Cutoff);
|
clip(color.a - _Cutoff);
|
||||||
|
172
Assets/Shaders/DecalPaintSpecular.shader
Normal file
172
Assets/Shaders/DecalPaintSpecular.shader
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
Shader "ConformalDecals/Paint/Specular"
|
||||||
|
{
|
||||||
|
Properties
|
||||||
|
{
|
||||||
|
[Header(Texture Maps)]
|
||||||
|
_Decal("Decal Texture", 2D) = "gray" {}
|
||||||
|
_BumpMap("Bump Map", 2D) = "bump" {}
|
||||||
|
_SpecMap("Specular Map", 2D) = "black" {}
|
||||||
|
|
||||||
|
_EdgeWearStrength("Edge Wear Strength", Range(0,100)) = 0
|
||||||
|
_EdgeWearOffset("Edge Wear Offset", Range(0,1)) = 0
|
||||||
|
|
||||||
|
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
|
||||||
|
_Opacity("_Opacity", Range(0,1) ) = 1
|
||||||
|
|
||||||
|
[Header(Specularity)]
|
||||||
|
_SpecColor ("_SpecColor", Color) = (0.5, 0.5, 0.5, 1)
|
||||||
|
_Shininess ("Shininess", Range (0.03, 10)) = 0.4
|
||||||
|
|
||||||
|
|
||||||
|
[Header(Effects)]
|
||||||
|
[PerRendererData]_Opacity("_Opacity", Range(0,1) ) = 1
|
||||||
|
[PerRendererData]_RimFalloff("_RimFalloff", Range(0.01,5) ) = 0.1
|
||||||
|
[PerRendererData]_RimColor("_RimColor", Color) = (0,0,0,0)
|
||||||
|
[PerRendererData]_UnderwaterFogFactor ("Underwater Fog Factor", Range(0,1)) = 0
|
||||||
|
}
|
||||||
|
SubShader
|
||||||
|
{
|
||||||
|
Tags { "Queue" = "Geometry+400" }
|
||||||
|
ZWrite Off
|
||||||
|
ZTest LEqual
|
||||||
|
Offset -1, -1
|
||||||
|
|
||||||
|
Pass
|
||||||
|
{
|
||||||
|
Name "FORWARD"
|
||||||
|
Tags { "LightMode" = "ForwardBase" }
|
||||||
|
Blend SrcAlpha OneMinusSrcAlpha
|
||||||
|
|
||||||
|
CGPROGRAM
|
||||||
|
#pragma vertex vert_forward
|
||||||
|
#pragma fragment frag_forward
|
||||||
|
|
||||||
|
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
|
||||||
|
|
||||||
|
sampler2D _Decal;
|
||||||
|
sampler2D _BumpMap;
|
||||||
|
sampler2D _SpecMap;
|
||||||
|
|
||||||
|
float4 _Decal_ST;
|
||||||
|
float4 _BumpMap_ST;
|
||||||
|
float4 _SpecMap_ST;
|
||||||
|
|
||||||
|
float _EdgeWearStrength;
|
||||||
|
float _EdgeWearOffset;
|
||||||
|
|
||||||
|
half _Shininess;
|
||||||
|
|
||||||
|
float _Cutoff;
|
||||||
|
float _Opacity;
|
||||||
|
float _RimFalloff;
|
||||||
|
float4 _RimColor;
|
||||||
|
|
||||||
|
#define DECAL_BASE_NORMAL
|
||||||
|
#define DECAL_SPECULAR
|
||||||
|
|
||||||
|
#include "UnityCG.cginc"
|
||||||
|
#include "Lighting.cginc"
|
||||||
|
#include "AutoLight.cginc"
|
||||||
|
#include "LightingKSP.cginc"
|
||||||
|
#include "DecalsCommon.cginc"
|
||||||
|
|
||||||
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||||
|
{
|
||||||
|
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||||
|
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base));
|
||||||
|
float3 specular = tex2D(_SpecMap, IN.uv_spec);
|
||||||
|
|
||||||
|
// clip alpha
|
||||||
|
clip(color.a - _Cutoff);
|
||||||
|
|
||||||
|
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
|
||||||
|
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
|
||||||
|
|
||||||
|
float wearFactor = 1 - normal.z;
|
||||||
|
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
|
||||||
|
|
||||||
|
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
|
||||||
|
color.a *= _Opacity;
|
||||||
|
|
||||||
|
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
|
||||||
|
o.Alpha = color.a;
|
||||||
|
o.Emission = emission;
|
||||||
|
o.Normal = normal;
|
||||||
|
o.Specular = _Shininess;
|
||||||
|
o.Gloss = specular.r * color.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
sampler2D _Decal;
|
||||||
|
sampler2D _BumpMap;
|
||||||
|
sampler2D _SpecMap;
|
||||||
|
|
||||||
|
float4 _Decal_ST;
|
||||||
|
float4 _BumpMap_ST;
|
||||||
|
float4 _SpecMap_ST;
|
||||||
|
|
||||||
|
float _EdgeWearStrength;
|
||||||
|
float _EdgeWearOffset;
|
||||||
|
|
||||||
|
half _Shininess;
|
||||||
|
|
||||||
|
float _Cutoff;
|
||||||
|
float _Opacity;
|
||||||
|
float _RimFalloff;
|
||||||
|
float4 _RimColor;
|
||||||
|
|
||||||
|
#define DECAL_BASE_NORMAL
|
||||||
|
#define DECAL_SPECULAR
|
||||||
|
|
||||||
|
#include "UnityCG.cginc"
|
||||||
|
#include "Lighting.cginc"
|
||||||
|
#include "AutoLight.cginc"
|
||||||
|
#include "LightingKSP.cginc"
|
||||||
|
#include "DecalsCommon.cginc"
|
||||||
|
|
||||||
|
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||||
|
{
|
||||||
|
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||||
|
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base));
|
||||||
|
float3 specular = tex2D(_SpecMap, IN.uv_spec);
|
||||||
|
|
||||||
|
// clip alpha
|
||||||
|
clip(color.a - _Cutoff);
|
||||||
|
|
||||||
|
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
|
||||||
|
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
|
||||||
|
|
||||||
|
float wearFactor = 1 - normal.z;
|
||||||
|
float wearFactorAlpha = saturate(_EdgeWearStrength * wearFactor);
|
||||||
|
|
||||||
|
color.a *= saturate(1 + _EdgeWearOffset - saturate(_EdgeWearStrength * wearFactor));
|
||||||
|
|
||||||
|
o.Albedo = UnderwaterFog(IN.worldPosition, color).rgb;
|
||||||
|
o.Alpha = color.a * _Opacity;
|
||||||
|
o.Emission = emission;
|
||||||
|
o.Normal = normal;
|
||||||
|
o.Specular = _Shininess;
|
||||||
|
o.Gloss = specular.r;
|
||||||
|
}
|
||||||
|
|
||||||
|
ENDCG
|
||||||
|
}
|
||||||
|
|
||||||
|
// shadow casting support
|
||||||
|
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
|
||||||
|
}
|
||||||
|
}
|
@ -4,9 +4,23 @@
|
|||||||
struct DecalSurfaceInput
|
struct DecalSurfaceInput
|
||||||
{
|
{
|
||||||
float2 uv_decal;
|
float2 uv_decal;
|
||||||
|
|
||||||
|
#ifdef DECAL_NORMAL
|
||||||
|
float2 uv_bump;
|
||||||
|
#endif //DECAL_NORMAL
|
||||||
|
|
||||||
|
#ifdef DECAL_SPECULAR
|
||||||
|
float2 uv_spec;
|
||||||
|
#endif //DECAL_SPECULAR
|
||||||
|
|
||||||
|
#ifdef DECAL_EMISSIVE
|
||||||
|
float2 uv_glow;
|
||||||
|
#endif //DECAL_EMISSIVE
|
||||||
|
|
||||||
#ifdef DECAL_BASE_NORMAL
|
#ifdef DECAL_BASE_NORMAL
|
||||||
float2 uv_base;
|
float2 uv_base;
|
||||||
#endif //DECAL_BASE_NORMAL
|
#endif //DECAL_BASE_NORMAL
|
||||||
|
|
||||||
float3 normal;
|
float3 normal;
|
||||||
float3 viewDir;
|
float3 viewDir;
|
||||||
float3 worldPosition;
|
float3 worldPosition;
|
||||||
@ -146,10 +160,24 @@ fixed4 frag_forward(v2f IN) : SV_Target
|
|||||||
|
|
||||||
// initialize surface input
|
// initialize surface input
|
||||||
UNITY_INITIALIZE_OUTPUT(DecalSurfaceInput, i)
|
UNITY_INITIALIZE_OUTPUT(DecalSurfaceInput, i)
|
||||||
i.uv_decal = TRANSFORM_TEX(uv_projected, _Decal);;
|
i.uv_decal = TRANSFORM_TEX(uv_projected, _Decal);
|
||||||
|
|
||||||
|
#ifdef DECAL_NORMAL
|
||||||
|
i.uv_bump = TRANSFORM_TEX(uv_projected, _BumpMap);
|
||||||
|
#endif //DECAL_NORMAL
|
||||||
|
|
||||||
|
#ifdef DECAL_SPECULAR
|
||||||
|
i.uv_spec = TRANSFORM_TEX(uv_projected, _SpecMap);
|
||||||
|
#endif //DECAL_SPECULAR
|
||||||
|
|
||||||
|
#ifdef DECAL_EMISSIVE
|
||||||
|
i.uv_glow = TRANSFORM_TEX(uv_projected, _GlowMap);
|
||||||
|
#endif //DECAL_EMISSIVE
|
||||||
|
|
||||||
#ifdef DECAL_BASE_NORMAL
|
#ifdef DECAL_BASE_NORMAL
|
||||||
i.uv_base = IN.uv_base;
|
i.uv_base = IN.uv_base;
|
||||||
#endif
|
#endif //DECAL_BASE_NORMAL
|
||||||
|
|
||||||
i.normal = IN.normal;
|
i.normal = IN.normal;
|
||||||
i.viewDir = viewDir;
|
i.viewDir = viewDir;
|
||||||
i.worldPosition = worldPosition;
|
i.worldPosition = worldPosition;
|
||||||
@ -178,12 +206,13 @@ fixed4 frag_forward(v2f IN) : SV_Target
|
|||||||
|
|
||||||
|
|
||||||
//KSP lighting function
|
//KSP lighting function
|
||||||
c += LightingBlinnPhongSmooth(o, lightDir, viewDir, atten);
|
c += LightingBlinnPhongSmooth(o, lightDir, worldViewDir, atten);
|
||||||
|
|
||||||
// Forward base emission and ambient/vertex lighting
|
// Forward base emission and ambient/vertex lighting
|
||||||
#ifdef UNITY_PASS_FORWARDBASE
|
#ifdef UNITY_PASS_FORWARDBASE
|
||||||
c.rgb += o.Emission;
|
c.rgb += o.Emission;
|
||||||
c.rgb += o.Albedo * IN.vlight;
|
c.rgb += o.Albedo * IN.vlight;
|
||||||
|
c.a = saturate(c.a);
|
||||||
#endif //UNITY_PASS_FORWARDBASE
|
#endif //UNITY_PASS_FORWARDBASE
|
||||||
|
|
||||||
// Forward add multiply by alpha
|
// Forward add multiply by alpha
|
||||||
|
3
Assets/Textures/Paint-Scratches.tif
Normal file
3
Assets/Textures/Paint-Scratches.tif
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:c1fdc5b0ace8225abd8a09a96f03666d5a127ac0ef1561eccde75a8df2dc885f
|
||||||
|
size 590087
|
3
Assets/Textures/Paint-Scuffs.tif
Normal file
3
Assets/Textures/Paint-Scuffs.tif
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:b107570db4498f60718879a417f1fc30322f3e6ac5f2029a45284b785b96de24
|
||||||
|
size 187725
|
Loading…
Reference in New Issue
Block a user