mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Move projection code into shared library
This commit is contained in:
parent
f630fb2215
commit
8ca3925e04
@ -34,12 +34,6 @@ Shader "ConformalDecals/Feature/Bumped"
|
||||
|
||||
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Lighting.cginc"
|
||||
#include "AutoLight.cginc"
|
||||
#include "LightingKSP.cginc"
|
||||
#include "DecalsCommon.cginc"
|
||||
|
||||
sampler2D _Decal;
|
||||
sampler2D _DecalBumpMap;
|
||||
|
||||
@ -49,22 +43,18 @@ Shader "ConformalDecals/Feature/Bumped"
|
||||
float _Cutoff;
|
||||
float _Opacity;
|
||||
float _RimFalloff;
|
||||
float4 _RimColor;
|
||||
float4 _RimColor;
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Lighting.cginc"
|
||||
#include "AutoLight.cginc"
|
||||
#include "LightingKSP.cginc"
|
||||
#include "DecalsCommon.cginc"
|
||||
|
||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||
{
|
||||
fixed4 uv_projected = UNITY_PROJ_COORD(IN.uv_decal);
|
||||
|
||||
// since I cant easily affect the clamping mode in KSP, do it here
|
||||
clip(uv_projected.xyz);
|
||||
clip(1-uv_projected.xyz);
|
||||
|
||||
// clip backsides
|
||||
clip(dot(_DecalNormal, IN.normal));
|
||||
|
||||
float2 uv_decal = TRANSFORM_TEX(uv_projected, _Decal);
|
||||
float4 color = tex2D(_Decal, uv_decal);
|
||||
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, uv_decal));
|
||||
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, IN.uv_decal));
|
||||
|
||||
// clip alpha
|
||||
clip(color.a - _Cutoff);
|
||||
@ -93,37 +83,27 @@ Shader "ConformalDecals/Feature/Bumped"
|
||||
|
||||
#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;
|
||||
|
||||
float4 _Decal_ST;
|
||||
float4 _DecalBumpMap_ST;
|
||||
|
||||
|
||||
float _Cutoff;
|
||||
float _Opacity;
|
||||
float _RimFalloff;
|
||||
float4 _RimColor;
|
||||
float4 _RimColor;
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Lighting.cginc"
|
||||
#include "AutoLight.cginc"
|
||||
#include "LightingKSP.cginc"
|
||||
#include "DecalsCommon.cginc"
|
||||
|
||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||
{
|
||||
fixed4 uv_projected = UNITY_PROJ_COORD(IN.uv_decal);
|
||||
|
||||
// since I cant easily affect the clamping mode in KSP, do it here
|
||||
clip(uv_projected.xyz);
|
||||
clip(1-uv_projected.xyz);
|
||||
|
||||
// clip backsides
|
||||
clip(dot(_DecalNormal, IN.normal));
|
||||
|
||||
float2 uv_decal = TRANSFORM_TEX(uv_projected, _Decal);
|
||||
float4 color = tex2D(_Decal, uv_decal);
|
||||
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, uv_decal));
|
||||
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||
float3 normal = UnpackNormal(tex2D(_DecalBumpMap, IN.uv_decal));
|
||||
|
||||
// clip alpha
|
||||
clip(color.a - _Cutoff);
|
||||
|
@ -61,22 +61,12 @@ Shader "ConformalDecals/Paint/Diffuse"
|
||||
|
||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||
{
|
||||
fixed4 uv_projected = UNITY_PROJ_COORD(IN.uv_decal);
|
||||
|
||||
// since I cant easily affect the clamping mode in KSP, do it here
|
||||
clip(uv_projected.xyz);
|
||||
clip(1-uv_projected.xyz);
|
||||
|
||||
// clip backsides
|
||||
clip(dot(_DecalNormal, IN.normal));
|
||||
|
||||
float2 uv_decal = TRANSFORM_TEX(uv_projected, _Decal);
|
||||
float4 color = tex2D(_Decal, uv_decal);
|
||||
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base));
|
||||
|
||||
// clip alpha
|
||||
clip(color.a - _Cutoff);
|
||||
|
||||
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base));
|
||||
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
|
||||
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
|
||||
|
||||
@ -130,22 +120,12 @@ Shader "ConformalDecals/Paint/Diffuse"
|
||||
|
||||
void surf (DecalSurfaceInput IN, inout SurfaceOutput o)
|
||||
{
|
||||
fixed4 uv_projected = UNITY_PROJ_COORD(IN.uv_decal);
|
||||
|
||||
// since I cant easily affect the clamping mode in KSP, do it here
|
||||
clip(uv_projected.xyz);
|
||||
clip(1-uv_projected.xyz);
|
||||
|
||||
// clip backsides
|
||||
clip(dot(_DecalNormal, IN.normal));
|
||||
|
||||
float2 uv_decal = TRANSFORM_TEX(uv_projected, _Decal);
|
||||
float4 color = tex2D(_Decal, uv_decal);
|
||||
float4 color = tex2D(_Decal, IN.uv_decal);
|
||||
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base));
|
||||
|
||||
// clip alpha
|
||||
clip(color.a - _Cutoff);
|
||||
|
||||
float3 normal = UnpackNormal(tex2D(_BumpMap, IN.uv_base));
|
||||
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), normal));
|
||||
float3 emission = (_RimColor.rgb * pow(rim, _RimFalloff)) * _RimColor.a;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
struct DecalSurfaceInput
|
||||
{
|
||||
float4 uv_decal;
|
||||
float2 uv_decal;
|
||||
#ifdef DECAL_BASE_NORMAL
|
||||
float2 uv_base;
|
||||
#endif //DECAL_BASE_NORMAL
|
||||
@ -134,9 +134,19 @@ fixed4 frag_forward(v2f IN) : SV_Target
|
||||
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPosition));
|
||||
float3 viewDir = _unity_tbn_0 * worldViewDir.x + _unity_tbn_1 * worldViewDir.y + _unity_tbn_2 * worldViewDir.z;
|
||||
|
||||
// perform decal projection
|
||||
fixed4 uv_projected = UNITY_PROJ_COORD(IN.uv_decal);
|
||||
|
||||
// clip texture outside of xyz bounds
|
||||
clip(uv_projected.xyz);
|
||||
clip(1-uv_projected.xyz);
|
||||
|
||||
// clip backsides
|
||||
clip(dot(_DecalNormal, IN.normal));
|
||||
|
||||
// initialize surface input
|
||||
UNITY_INITIALIZE_OUTPUT(DecalSurfaceInput, i)
|
||||
i.uv_decal = IN.uv_decal;
|
||||
i.uv_decal = TRANSFORM_TEX(uv_projected, _Decal);;
|
||||
#ifdef DECAL_BASE_NORMAL
|
||||
i.uv_base = IN.uv_base;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user