This commit is contained in:
2021-06-13 10:28:03 +02:00
parent eb70603c85
commit df2d24cbd3
7487 changed files with 943244 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
#if !defined(COMBINED_SHAPE_LIGHT_PASS)
#define COMBINED_SHAPE_LIGHT_PASS
half _HDREmulationScale;
half _UseSceneLighting;
half4 _RendererColor;
half4 CombinedShapeLightShared(half4 color, half4 mask, half2 lightingUV)
{
if (color.a == 0.0)
discard;
color = color * _RendererColor; // This is needed for sprite shape
#if USE_SHAPE_LIGHT_TYPE_0
half4 shapeLight0 = SAMPLE_TEXTURE2D(_ShapeLightTexture0, sampler_ShapeLightTexture0, lightingUV);
if (any(_ShapeLightMaskFilter0))
{
half4 processedMask = (1 - _ShapeLightInvertedFilter0) * mask + _ShapeLightInvertedFilter0 * (1 - mask);
shapeLight0 *= dot(processedMask, _ShapeLightMaskFilter0);
}
half4 shapeLight0Modulate = shapeLight0 * _ShapeLightBlendFactors0.x;
half4 shapeLight0Additive = shapeLight0 * _ShapeLightBlendFactors0.y;
#else
half4 shapeLight0Modulate = 0;
half4 shapeLight0Additive = 0;
#endif
#if USE_SHAPE_LIGHT_TYPE_1
half4 shapeLight1 = SAMPLE_TEXTURE2D(_ShapeLightTexture1, sampler_ShapeLightTexture1, lightingUV);
if (any(_ShapeLightMaskFilter1))
{
half4 processedMask = (1 - _ShapeLightInvertedFilter1) * mask + _ShapeLightInvertedFilter1 * (1 - mask);
shapeLight1 *= dot(processedMask, _ShapeLightMaskFilter1);
}
half4 shapeLight1Modulate = shapeLight1 * _ShapeLightBlendFactors1.x;
half4 shapeLight1Additive = shapeLight1 * _ShapeLightBlendFactors1.y;
#else
half4 shapeLight1Modulate = 0;
half4 shapeLight1Additive = 0;
#endif
#if USE_SHAPE_LIGHT_TYPE_2
half4 shapeLight2 = SAMPLE_TEXTURE2D(_ShapeLightTexture2, sampler_ShapeLightTexture2, lightingUV);
if (any(_ShapeLightMaskFilter2))
{
half4 processedMask = (1 - _ShapeLightInvertedFilter2) * mask + _ShapeLightInvertedFilter2 * (1 - mask);
shapeLight2 *= dot(processedMask, _ShapeLightMaskFilter2);
}
half4 shapeLight2Modulate = shapeLight2 * _ShapeLightBlendFactors2.x;
half4 shapeLight2Additive = shapeLight2 * _ShapeLightBlendFactors2.y;
#else
half4 shapeLight2Modulate = 0;
half4 shapeLight2Additive = 0;
#endif
#if USE_SHAPE_LIGHT_TYPE_3
half4 shapeLight3 = SAMPLE_TEXTURE2D(_ShapeLightTexture3, sampler_ShapeLightTexture3, lightingUV);
if (any(_ShapeLightMaskFilter3))
{
half4 processedMask = (1 - _ShapeLightInvertedFilter3) * mask + _ShapeLightInvertedFilter3 * (1 - mask);
shapeLight3 *= dot(processedMask, _ShapeLightMaskFilter3);
}
half4 shapeLight3Modulate = shapeLight3 * _ShapeLightBlendFactors3.x;
half4 shapeLight3Additive = shapeLight3 * _ShapeLightBlendFactors3.y;
#else
half4 shapeLight3Modulate = 0;
half4 shapeLight3Additive = 0;
#endif
half4 finalOutput;
#if !USE_SHAPE_LIGHT_TYPE_0 && !USE_SHAPE_LIGHT_TYPE_1 && !USE_SHAPE_LIGHT_TYPE_2 && ! USE_SHAPE_LIGHT_TYPE_3
finalOutput = color;
#else
half4 finalModulate = shapeLight0Modulate + shapeLight1Modulate + shapeLight2Modulate + shapeLight3Modulate;
half4 finalAdditve = shapeLight0Additive + shapeLight1Additive + shapeLight2Additive + shapeLight3Additive;
finalOutput = _HDREmulationScale * (color * finalModulate + finalAdditve);
#endif
finalOutput.a = color.a;
finalOutput = finalOutput *_UseSceneLighting + (1 - _UseSceneLighting)*color;
return max(0, finalOutput);
}
#endif

View File

@@ -0,0 +1,75 @@
#if USE_NORMAL_MAP
#if LIGHT_QUALITY_FAST
#define NORMALS_LIGHTING_COORDS(TEXCOORDA, TEXCOORDB) \
half4 lightDirection : TEXCOORDA;\
half2 screenUV : TEXCOORDB;
#define TRANSFER_NORMALS_LIGHTING(output, worldSpacePos)\
output.screenUV = ComputeNormalizedDeviceCoordinates(output.positionCS.xyz / output.positionCS.w);\
half3 planeNormal = -GetViewForwardDir();\
half3 projLightPos = _LightPosition.xyz - (dot(_LightPosition.xyz - worldSpacePos.xyz, planeNormal) - _LightZDistance) * planeNormal;\
output.lightDirection.xyz = normalize(projLightPos - worldSpacePos.xyz);\
output.lightDirection.w = 0;
#define APPLY_NORMALS_LIGHTING(input, lightColor)\
half4 normal = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.screenUV);\
half3 normalUnpacked = UnpackNormalRGBNoScale(normal);\
lightColor = lightColor * saturate(dot(input.lightDirection.xyz, normalUnpacked));
#else
#define NORMALS_LIGHTING_COORDS(TEXCOORDA, TEXCOORDB) \
half4 positionWS : TEXCOORDA;\
half2 screenUV : TEXCOORDB;
#define TRANSFER_NORMALS_LIGHTING(output, worldSpacePos) \
output.screenUV = ComputeNormalizedDeviceCoordinates(output.positionCS.xyz / output.positionCS.w); \
output.positionWS = worldSpacePos;
#define APPLY_NORMALS_LIGHTING(input, lightColor)\
half4 normal = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.screenUV);\
half3 normalUnpacked = UnpackNormalRGBNoScale(normal);\
half3 planeNormal = -GetViewForwardDir();\
half3 projLightPos = _LightPosition.xyz - (dot(_LightPosition.xyz - input.positionWS.xyz, planeNormal) - _LightZDistance) * planeNormal;\
half3 dirToLight = normalize(projLightPos - input.positionWS.xyz);\
lightColor = lightColor * saturate(dot(dirToLight, normalUnpacked));
#endif
#define NORMALS_LIGHTING_VARIABLES \
TEXTURE2D(_NormalMap); \
SAMPLER(sampler_NormalMap); \
half4 _LightPosition;\
half _LightZDistance;
#else
#define NORMALS_LIGHTING_COORDS(TEXCOORDA, TEXCOORDB)
#define NORMALS_LIGHTING_VARIABLES
#define TRANSFER_NORMALS_LIGHTING(output, worldSpacePos)
#define APPLY_NORMALS_LIGHTING(input, lightColor)
#endif
#define SHADOW_COORDS(TEXCOORDA)\
float2 shadowUV : TEXCOORDA;
#define SHADOW_VARIABLES\
float _ShadowIntensity;\
float _ShadowVolumeIntensity;\
TEXTURE2D(_ShadowTex);\
SAMPLER(sampler_ShadowTex);
#define APPLY_SHADOWS(input, color, intensity)\
if(intensity < 1)\
{\
half4 shadow = saturate(SAMPLE_TEXTURE2D(_ShadowTex, sampler_ShadowTex, input.shadowUV)); \
half shadowIntensity = 1 - (shadow.r * saturate(2 * (shadow.g - 0.5f * shadow.b))); \
color.rgb = (color.rgb * shadowIntensity) + (color.rgb * intensity*(1 - shadowIntensity));\
}
#define TRANSFER_SHADOWS(output)\
output.shadowUV = ComputeNormalizedDeviceCoordinates(output.positionCS.xyz);
#define SHAPE_LIGHT(index)\
TEXTURE2D(_ShapeLightTexture##index);\
SAMPLER(sampler_ShapeLightTexture##index);\
half2 _ShapeLightBlendFactors##index;\
half4 _ShapeLightMaskFilter##index;\
half4 _ShapeLightInvertedFilter##index;

View File

@@ -0,0 +1,16 @@
#if !defined(NORMALS_RENDERING_PASS)
#define NORMALS_RENDERING_PASS
half4 NormalsRenderingShared(half4 color, half3 normalTS, half3 tangent, half3 bitangent, half3 normal)
{
half4 normalColor;
half3 normalWS = TransformTangentToWorld(normalTS, half3x3(tangent.xyz, bitangent.xyz, normal.xyz));
normalColor.rgb = 0.5 * ((normalWS)+1);
normalColor.a = color.a; // used for blending
return normalColor;
}
#endif

View File

@@ -0,0 +1,113 @@
Shader "Hidden/Light2d-Point-Volumetric"
{
SubShader
{
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Blend One One
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local USE_POINT_LIGHT_COOKIES __
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
struct Attributes
{
float3 positionOS : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half2 uv : TEXCOORD0;
half2 lookupUV : TEXCOORD2; // This is used for light relative direction
SHADOW_COORDS(TEXCOORD5)
};
#if USE_POINT_LIGHT_COOKIES
TEXTURE2D(_PointLightCookieTex);
SAMPLER(sampler_PointLightCookieTex);
#endif
TEXTURE2D(_FalloffLookup);
SAMPLER(sampler_FalloffLookup);
half _FalloffIntensity;
TEXTURE2D(_LightLookup);
SAMPLER(sampler_LightLookup);
half4 _LightLookup_TexelSize;
half4 _LightColor;
half _VolumeOpacity;
float4 _LightPosition;
float4x4 _LightInvMatrix;
float4x4 _LightNoRotInvMatrix;
half _LightZDistance;
half _OuterAngle; // 1-0 where 1 is the value at 0 degrees and 1 is the value at 180 degrees
half _InnerAngleMult; // 1-0 where 1 is the value at 0 degrees and 1 is the value at 180 degrees
half _InnerRadiusMult; // 1-0 where 1 is the value at the center and 0 is the value at the outer radius
half _InverseHDREmulationScale;
half _IsFullSpotlight;
SHADOW_VARIABLES
Varyings vert(Attributes input)
{
Varyings output = (Varyings)0;
output.positionCS = TransformObjectToHClip(input.positionOS);
output.uv = input.texcoord;
float4 worldSpacePos;
worldSpacePos.xyz = TransformObjectToWorld(input.positionOS);
worldSpacePos.w = 1;
float4 lightSpacePos = mul(_LightInvMatrix, worldSpacePos);
float4 lightSpaceNoRotPos = mul(_LightNoRotInvMatrix, worldSpacePos);
float halfTexelOffset = 0.5 * _LightLookup_TexelSize.x;
output.lookupUV = 0.5 * (lightSpacePos.xy + 1) + halfTexelOffset;
TRANSFER_SHADOWS(output)
return output;
}
half4 frag(Varyings input) : SV_Target
{
half4 lookupValue = SAMPLE_TEXTURE2D(_LightLookup, sampler_LightLookup, input.lookupUV); // r = distance, g = angle, b = x direction, a = y direction
// Inner Radius
half attenuation = saturate(_InnerRadiusMult * lookupValue.r); // This is the code to take care of our inner radius
// Spotlight
half spotAttenuation = saturate((_OuterAngle - lookupValue.g + _IsFullSpotlight) * _InnerAngleMult);
attenuation = attenuation * spotAttenuation;
half2 mappedUV;
mappedUV.x = attenuation;
mappedUV.y = _FalloffIntensity;
attenuation = SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, mappedUV).r;
#if USE_POINT_LIGHT_COOKIES
half4 cookieColor = SAMPLE_TEXTURE2D(_PointLightCookieTex, sampler_PointLightCookieTex, input.lookupUV);
half4 lightColor = cookieColor * _LightColor * attenuation;
#else
half4 lightColor = _LightColor * attenuation;
#endif
APPLY_SHADOWS(input, lightColor, _ShadowVolumeIntensity);
return _VolumeOpacity * lightColor * _InverseHDREmulationScale;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,129 @@
Shader "Hidden/Light2D-Point"
{
Properties
{
[HideInInspector] _SrcBlend("__src", Float) = 1.0
[HideInInspector] _DstBlend("__dst", Float) = 0.0
}
SubShader
{
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Blend [_SrcBlend][_DstBlend]
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local USE_POINT_LIGHT_COOKIES __
#pragma multi_compile_local LIGHT_QUALITY_FAST __
#pragma multi_compile_local USE_NORMAL_MAP __
#pragma multi_compile_local USE_ADDITIVE_BLENDING __
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
struct Attributes
{
float3 positionOS : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half2 uv : TEXCOORD0;
half2 lookupUV : TEXCOORD2; // This is used for light relative direction
NORMALS_LIGHTING_COORDS(TEXCOORD4, TEXCOORD5)
SHADOW_COORDS(TEXCOORD6)
};
#if USE_POINT_LIGHT_COOKIES
TEXTURE2D(_PointLightCookieTex);
SAMPLER(sampler_PointLightCookieTex);
#endif
TEXTURE2D(_FalloffLookup);
SAMPLER(sampler_FalloffLookup);
half _FalloffIntensity;
TEXTURE2D(_LightLookup);
SAMPLER(sampler_LightLookup);
half4 _LightLookup_TexelSize;
NORMALS_LIGHTING_VARIABLES
SHADOW_VARIABLES
half4 _LightColor;
float4x4 _LightInvMatrix;
float4x4 _LightNoRotInvMatrix;
half _OuterAngle; // 1-0 where 1 is the value at 0 degrees and 1 is the value at 180 degrees
half _InnerAngleMult; // 1-0 where 1 is the value at 0 degrees and 1 is the value at 180 degrees
half _InnerRadiusMult; // 1-0 where 1 is the value at the center and 0 is the value at the outer radius
half _InverseHDREmulationScale;
half _IsFullSpotlight;
Varyings vert(Attributes input)
{
Varyings output = (Varyings)0;
output.positionCS = TransformObjectToHClip(input.positionOS);
output.uv = input.texcoord;
float4 worldSpacePos;
worldSpacePos.xyz = TransformObjectToWorld(input.positionOS);
worldSpacePos.w = 1;
float4 lightSpacePos = mul(_LightInvMatrix, worldSpacePos);
float4 lightSpaceNoRotPos = mul(_LightNoRotInvMatrix, worldSpacePos);
float halfTexelOffset = 0.5 * _LightLookup_TexelSize.x;
output.lookupUV = 0.5 * (lightSpacePos.xy + 1) + halfTexelOffset;
TRANSFER_NORMALS_LIGHTING(output, worldSpacePos)
TRANSFER_SHADOWS(output)
return output;
}
half4 frag(Varyings input) : SV_Target
{
half4 lookupValue = SAMPLE_TEXTURE2D(_LightLookup, sampler_LightLookup, input.lookupUV); // r = distance, g = angle, b = x direction, a = y direction
// Inner Radius
half attenuation = saturate(_InnerRadiusMult * lookupValue.r); // This is the code to take care of our inner radius
// Spotlight
half spotAttenuation = saturate((_OuterAngle - lookupValue.g + _IsFullSpotlight) * _InnerAngleMult);
attenuation = attenuation * spotAttenuation;
half2 mappedUV;
mappedUV.x = attenuation;
mappedUV.y = _FalloffIntensity;
attenuation = SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, mappedUV).r;
#if USE_POINT_LIGHT_COOKIES
half4 cookieColor = SAMPLE_TEXTURE2D(_PointLightCookieTex, sampler_PointLightCookieTex, input.lookupUV);
half4 lightColor = cookieColor * _LightColor;
#else
half4 lightColor = _LightColor;
#endif
#if USE_ADDITIVE_BLENDING
lightColor *= attenuation;
#else
lightColor.a = attenuation;
#endif
APPLY_NORMALS_LIGHTING(input, lightColor);
APPLY_SHADOWS(input, lightColor, _ShadowIntensity);
return lightColor * _InverseHDREmulationScale;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,95 @@
Shader "Hidden/Light2D-Shape-Volumetric"
{
SubShader
{
Tags { "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Blend SrcAlpha One
ZWrite Off
ZTest Off
Cull Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local SPRITE_LIGHT __
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
struct Attributes
{
float3 positionOS : POSITION;
float4 color : COLOR;
half2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half4 color : COLOR;
half2 uv : TEXCOORD0;
SHADOW_COORDS(TEXCOORD1)
};
half4 _LightColor;
half _FalloffDistance;
half _VolumeOpacity;
half _InverseHDREmulationScale;
#ifdef SPRITE_LIGHT
TEXTURE2D(_CookieTex); // This can either be a sprite texture uv or a falloff texture
SAMPLER(sampler_CookieTex);
#else
uniform half _FalloffIntensity;
TEXTURE2D(_FalloffLookup);
SAMPLER(sampler_FalloffLookup);
#endif
SHADOW_VARIABLES
Varyings vert(Attributes attributes)
{
Varyings o = (Varyings)0;
float3 positionOS = attributes.positionOS;
positionOS.x = positionOS.x + _FalloffDistance * attributes.color.r;
positionOS.y = positionOS.y + _FalloffDistance * attributes.color.g;
o.positionCS = TransformObjectToHClip(positionOS);
o.color = _LightColor * _InverseHDREmulationScale;
o.color.a = _LightColor.a * _VolumeOpacity;
#ifdef SPRITE_LIGHT
o.uv = attributes.uv;
#else
o.uv = float2(attributes.color.a, _FalloffIntensity);
#endif
TRANSFER_SHADOWS(o)
return o;
}
half4 frag(Varyings i) : SV_Target
{
half4 color = i.color;
#if SPRITE_LIGHT
color *= SAMPLE_TEXTURE2D(_CookieTex, sampler_CookieTex, i.uv);
#else
color.a = i.color.a * SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, i.uv).r;
#endif
APPLY_SHADOWS(i, color, _ShadowVolumeIntensity);
return color;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,115 @@
Shader "Hidden/Light2D-Shape"
{
Properties
{
[HideInInspector] _SrcBlend("__src", Float) = 1.0
[HideInInspector] _DstBlend("__dst", Float) = 0.0
}
SubShader
{
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
Pass
{
Blend[_SrcBlend][_DstBlend]
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local SPRITE_LIGHT __
#pragma multi_compile_local USE_NORMAL_MAP __
#pragma multi_compile_local USE_ADDITIVE_BLENDING __
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
struct Attributes
{
float3 positionOS : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half4 color : COLOR;
half2 uv : TEXCOORD0;
SHADOW_COORDS(TEXCOORD1)
NORMALS_LIGHTING_COORDS(TEXCOORD2, TEXCOORD3)
};
half _InverseHDREmulationScale;
half4 _LightColor;
half _FalloffDistance;
#ifdef SPRITE_LIGHT
TEXTURE2D(_CookieTex); // This can either be a sprite texture uv or a falloff texture
SAMPLER(sampler_CookieTex);
#else
half _FalloffIntensity;
TEXTURE2D(_FalloffLookup);
SAMPLER(sampler_FalloffLookup);
#endif
NORMALS_LIGHTING_VARIABLES
SHADOW_VARIABLES
Varyings vert(Attributes attributes)
{
Varyings o = (Varyings)0;
float3 positionOS = attributes.positionOS;
positionOS.x = positionOS.x + _FalloffDistance * attributes.color.r;
positionOS.y = positionOS.y + _FalloffDistance * attributes.color.g;
o.positionCS = TransformObjectToHClip(positionOS);
o.color = _LightColor * _InverseHDREmulationScale;
o.color.a = attributes.color.a;
#ifdef SPRITE_LIGHT
o.uv = attributes.uv;
#else
o.uv = float2(o.color.a, _FalloffIntensity);
#endif
float4 worldSpacePos;
worldSpacePos.xyz = TransformObjectToWorld(positionOS);
worldSpacePos.w = 1;
TRANSFER_NORMALS_LIGHTING(o, worldSpacePos)
TRANSFER_SHADOWS(o)
return o;
}
half4 frag(Varyings i) : SV_Target
{
half4 color = i.color;
#if SPRITE_LIGHT
half4 cookie = SAMPLE_TEXTURE2D(_CookieTex, sampler_CookieTex, i.uv);
#if USE_ADDITIVE_BLENDING
color *= cookie * cookie.a;
#else
color *= cookie;
#endif
#else
#if USE_ADDITIVE_BLENDING
color *= SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, i.uv).r;
#else
color.a = SAMPLE_TEXTURE2D(_FalloffLookup, sampler_FalloffLookup, i.uv).r;
#endif
#endif
APPLY_NORMALS_LIGHTING(i, color);
APPLY_SHADOWS(i, color, _ShadowIntensity);
return color;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,71 @@
Shader "Hidden/Shadow2DRemoveSelf"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
[PerRendererData][HideInInspector] _ShadowStencilGroup("__ShadowStencilGroup", Float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull Off
BlendOp Add
Blend One One
ZWrite Off
Pass
{
Stencil
{
Ref [_ShadowStencilGroup]
Comp Equal
Pass Keep
Fail Keep
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _ReceivesShadows;
Varyings vert (Attributes v)
{
Varyings o;
o.vertex = TransformObjectToHClip(v.vertex.xyz);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
half4 frag(Varyings i) : SV_Target
{
half4 main = tex2D(_MainTex, i.uv);
half4 col;
col.r = 0;
col.g = 0;
col.b = main.a;
col.a = 0;
return col;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,169 @@
Shader "Hidden/ShadowGroup2D"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_ShadowStencilGroup("__ShadowStencilGroup", Float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull Off
BlendOp Add
Blend One One
ZWrite Off
Pass
{
Stencil
{
Ref [_ShadowStencilGroup]
Comp NotEqual
Pass Replace
Fail Keep
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float3 vertex : POSITION;
float4 tangent: TANGENT;
float2 uv : TEXCOORD0;
float4 extrusion : COLOR;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
uniform float3 _LightPos;
uniform float _ShadowRadius;
Varyings vert (Attributes v)
{
Varyings o;
float3 vertexWS = TransformObjectToWorld(v.vertex); // This should be in world space
float3 lightDir = _LightPos - vertexWS;
lightDir.z = 0;
// Start of code to see if this point should be extruded
float3 lightDirection = normalize(lightDir);
float3 endpoint = vertexWS + (_ShadowRadius * -lightDirection);
float3 worldTangent = TransformObjectToWorldDir(v.tangent.xyz);
float sharedShadowTest = saturate(ceil(dot(lightDirection, worldTangent)));
// Start of code to calculate offset
float3 vertexWS0 = TransformObjectToWorld(float3(v.extrusion.xy, 0));
float3 vertexWS1 = TransformObjectToWorld(float3(v.extrusion.zw, 0));
float3 shadowDir0 = vertexWS0 - _LightPos;
shadowDir0.z = 0;
shadowDir0 = normalize(shadowDir0);
float3 shadowDir1 = vertexWS1 -_LightPos;
shadowDir1.z = 0;
shadowDir1 = normalize(shadowDir1);
float3 shadowDir = normalize(shadowDir0 + shadowDir1);
float3 sharedShadowOffset = sharedShadowTest * _ShadowRadius * shadowDir;
float3 position;
position = vertexWS + sharedShadowOffset;
o.vertex = TransformWorldToHClip(position);
// RGB - R is shadow value (to support soft shadows), G is Self Shadow Mask, B is No Shadow Mask
o.color = 1; // v.color;
o.color.g = 0.5;
o.color.b = 0;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
float4 frag (Varyings i) : SV_Target
{
float4 main = tex2D(_MainTex, i.uv);
float4 col = i.color;
col.g = main.a * col.g;
return col;
}
ENDHLSL
}
Pass
{
Stencil
{
Ref [_ShadowStencilGroup]
Comp NotEqual
Pass Replace
Fail Keep
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float3 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
Varyings vert (Attributes v)
{
Varyings o;
o.vertex = TransformObjectToHClip(v.vertex);
// RGB - R is shadow value (to support soft shadows), G is Self Shadow Mask, B is No Shadow Mask
o.color = 1;
o.color.g = 0.5;
o.color.b = 1;
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
half4 frag (Varyings i) : SV_Target
{
half4 main = tex2D(_MainTex, i.uv);
half4 color = i.color;
color.b = 1 - main.a;
return color;
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,214 @@
Shader "Universal Render Pipeline/2D/Sprite-Lit-Default"
{
Properties
{
_MainTex("Diffuse", 2D) = "white" {}
_MaskTex("Mask", 2D) = "white" {}
_NormalMap("Normal Map", 2D) = "bump" {}
// Legacy properties. They're here so that materials using this shader can gracefully fallback to the legacy sprite shader.
[HideInInspector] _Color("Tint", Color) = (1,1,1,1)
[HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip("Flip", Vector) = (1,1,1,1)
[HideInInspector] _AlphaTex("External Alpha", 2D) = "white" {}
[HideInInspector] _EnableExternalAlpha("Enable External Alpha", Float) = 0
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
ENDHLSL
SubShader
{
Tags {"Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
ZWrite Off
Pass
{
Tags { "LightMode" = "Universal2D" }
HLSLPROGRAM
#pragma vertex CombinedShapeLightVertex
#pragma fragment CombinedShapeLightFragment
#pragma multi_compile USE_SHAPE_LIGHT_TYPE_0 __
#pragma multi_compile USE_SHAPE_LIGHT_TYPE_1 __
#pragma multi_compile USE_SHAPE_LIGHT_TYPE_2 __
#pragma multi_compile USE_SHAPE_LIGHT_TYPE_3 __
struct Attributes
{
float3 positionOS : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half4 color : COLOR;
float2 uv : TEXCOORD0;
half2 lightingUV : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/LightingUtility.hlsl"
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
TEXTURE2D(_MaskTex);
SAMPLER(sampler_MaskTex);
half4 _MainTex_ST;
#if USE_SHAPE_LIGHT_TYPE_0
SHAPE_LIGHT(0)
#endif
#if USE_SHAPE_LIGHT_TYPE_1
SHAPE_LIGHT(1)
#endif
#if USE_SHAPE_LIGHT_TYPE_2
SHAPE_LIGHT(2)
#endif
#if USE_SHAPE_LIGHT_TYPE_3
SHAPE_LIGHT(3)
#endif
Varyings CombinedShapeLightVertex(Attributes v)
{
Varyings o = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.positionCS = TransformObjectToHClip(v.positionOS);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.lightingUV = ComputeNormalizedDeviceCoordinates(o.positionCS.xyz / o.positionCS.w);
o.color = v.color;
return o;
}
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/CombinedShapeLightShared.hlsl"
half4 CombinedShapeLightFragment(Varyings i) : SV_Target
{
half4 main = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
return CombinedShapeLightShared(main, mask, i.lightingUV);
}
ENDHLSL
}
Pass
{
Tags { "LightMode" = "NormalsRendering"}
HLSLPROGRAM
#pragma vertex NormalsRenderingVertex
#pragma fragment NormalsRenderingFragment
struct Attributes
{
float3 positionOS : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
float4 tangent : TANGENT;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half4 color : COLOR;
float2 uv : TEXCOORD0;
half3 normalWS : TEXCOORD1;
half3 tangentWS : TEXCOORD2;
half3 bitangentWS : TEXCOORD3;
UNITY_VERTEX_OUTPUT_STEREO
};
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
TEXTURE2D(_NormalMap);
SAMPLER(sampler_NormalMap);
half4 _NormalMap_ST; // Is this the right way to do this?
Varyings NormalsRenderingVertex(Attributes attributes)
{
Varyings o = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(attributes);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.positionCS = TransformObjectToHClip(attributes.positionOS);
o.uv = TRANSFORM_TEX(attributes.uv, _NormalMap);
o.color = attributes.color;
o.normalWS = -GetViewForwardDir();
o.tangentWS = TransformObjectToWorldDir(attributes.tangent.xyz);
o.bitangentWS = cross(o.normalWS, o.tangentWS) * attributes.tangent.w;
return o;
}
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/NormalsRenderingShared.hlsl"
half4 NormalsRenderingFragment(Varyings i) : SV_Target
{
half4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
half3 normalTS = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, i.uv));
return NormalsRenderingShared(mainTex, normalTS, i.tangentWS.xyz, i.bitangentWS.xyz, i.normalWS.xyz);
}
ENDHLSL
}
Pass
{
Tags { "LightMode" = "UniversalForward" "Queue"="Transparent" "RenderType"="Transparent"}
HLSLPROGRAM
#pragma vertex UnlitVertex
#pragma fragment UnlitFragment
struct Attributes
{
float3 positionOS : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
float4 _MainTex_ST;
Varyings UnlitVertex(Attributes attributes)
{
Varyings o = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(attributes);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.positionCS = TransformObjectToHClip(attributes.positionOS);
o.uv = TRANSFORM_TEX(attributes.uv, _MainTex);
o.color = attributes.color;
return o;
}
float4 UnlitFragment(Varyings i) : SV_Target
{
float4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
return mainTex;
}
ENDHLSL
}
}
Fallback "Sprites/Default"
}