initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,110 @@
#ifndef COMBINED_SHAPE_LIGHT_PASS
#define COMBINED_SHAPE_LIGHT_PASS
#include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
half _HDREmulationScale;
half _UseSceneLighting;
half4 _RendererColor;
half4 CombinedShapeLightShared(in SurfaceData2D surfaceData, in InputData2D inputData)
{
#if defined(DEBUG_DISPLAY)
half4 debugColor = 0;
if (CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
{
return debugColor;
}
#endif
half alpha = surfaceData.alpha;
half4 color = half4(surfaceData.albedo, alpha);
const half4 mask = surfaceData.mask;
const half2 lightingUV = inputData.lightingUV;
if (alpha == 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 = alpha;
finalOutput = lerp(color, finalOutput, _UseSceneLighting);
return max(0, finalOutput);
}
#endif

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e7ee44e4db2311b428e6f789318838f8
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,31 @@
#ifndef INPUT_DATA_2D_INCLUDED
#define INPUT_DATA_2D_INCLUDED
struct InputData2D
{
float2 uv;
half2 lightingUV;
#if defined(DEBUG_DISPLAY)
float3 positionWS;
float4 texelSize;
float4 mipInfo;
uint mipCount;
#endif
};
void InitializeInputData(float2 uv, half2 lightingUV, out InputData2D inputData)
{
inputData = (InputData2D)0;
inputData.uv = uv;
inputData.lightingUV = lightingUV;
}
void InitializeInputData(float2 uv, out InputData2D inputData)
{
InitializeInputData(uv, 0, inputData);
}
#endif

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 15c09e9f82634f5881e6676d62f25bcb
timeCreated: 1614177501

View file

@ -0,0 +1,86 @@
#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;\
half4 _ShadowColorMask = 1;\
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));\
// }
//half shadowIntensity = 1-dot(_ShadowColorMask, shadow); \
//color.rgb = (color.rgb * shadowIntensity) + (color.rgb * intensity*(1 - shadowIntensity));\
// Need to look at shadow caster to remove issue with shadows
#define APPLY_SHADOWS(input, color, intensity)\
if(intensity < 1)\
{\
half4 shadow = saturate(SAMPLE_TEXTURE2D(_ShadowTex, sampler_ShadowTex, input.shadowUV)); \
half shadowIntensity = 1-dot(_ShadowColorMask, shadow.rgba) ; \
color.rgb = (color.rgb * shadowIntensity) + (color.rgb * intensity*(1 - shadowIntensity));\
}
#define TRANSFER_SHADOWS(output)\
output.shadowUV = ComputeNormalizedDeviceCoordinates(output.positionCS.xyz / output.positionCS.w);
#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,9 @@
fileFormatVersion: 2
guid: 931e5ffca47cea54783e99bf989216b5
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

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,9 @@
fileFormatVersion: 2
guid: b9c3f97797bd9374cb2607614554fe54
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,64 @@
#if !defined(SHADOW_PROJECT_VERTEX)
#define SHADOW_PROJECT_VERTEX
struct Attributes
{
float3 vertex : POSITION;
float4 tangent: TANGENT;
float4 extrusion : COLOR;
};
struct Varyings
{
float4 vertex : SV_POSITION;
};
uniform float3 _LightPos;
uniform float4x4 _ShadowModelMatrix; // This is a custom model matrix without scaling
uniform float4x4 _ShadowModelInvMatrix;
uniform float3 _ShadowModelScale; // This is the scale
uniform float _ShadowRadius;
Varyings ProjectShadow(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);
float adjShadowRadius = 1.4143 * _ShadowRadius; // Needed as our shadow fits like a circumscribed box around our light radius
float3 endpoint = vertexWS + (adjShadowRadius * -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 * adjShadowRadius * shadowDir;
float3 position;
position = vertexWS + sharedShadowOffset;
o.vertex = TransformWorldToHClip(position);
return o;
}
#endif

View file

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 97832dc646b4fb4498bf5aa61e366c13
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,43 @@
#if !defined(SPRITE_MASK_SHARED)
#define SPRITE_MASK_SHARED
// alpha below which a mask should discard a pixel, thereby preventing the stencil buffer from being marked with the Mask's presence
half _Cutoff;
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
struct Attributes
{
float4 positionOS : POSITION;
half2 texcoord : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
half2 uv : TEXCOORD0;
};
Varyings MaskRenderingVertex(Attributes input)
{
Varyings output;
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
output.uv = input.texcoord;
return output;
}
half4 MaskRenderingFragment(Varyings input) : SV_Target
{
half4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
// for masks: discard pixel if alpha falls below MaskingCutoff
clip(c.a - _Cutoff);
return half4(1, 1, 1, 0.2);
}
#endif

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c9ac51d204bc24b118ec6bc5ab6c29c6
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,35 @@
#ifndef SURFACE_DATA_2D_INCLUDED
#define SURFACE_DATA_2D_INCLUDED
struct SurfaceData2D
{
half3 albedo;
half alpha;
half4 mask;
half3 normalTS;
};
void InitializeSurfaceData(half3 albedo, half alpha, half4 mask, half3 normalTS, out SurfaceData2D surfaceData)
{
surfaceData = (SurfaceData2D)0;
surfaceData.albedo = albedo;
surfaceData.alpha = alpha;
surfaceData.mask = mask;
surfaceData.normalTS = normalTS;
}
void InitializeSurfaceData(half3 albedo, half alpha, half4 mask, out SurfaceData2D surfaceData)
{
const half3 normalTS = half3(0, 0, 1);
InitializeSurfaceData(albedo, alpha, mask, normalTS, surfaceData);
}
void InitializeSurfaceData(half3 albedo, half alpha, out SurfaceData2D surfaceData)
{
InitializeSurfaceData(albedo, alpha, 1, surfaceData);
}
#endif

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2861459260b14a2481f8f8e7f6637d8f
timeCreated: 1614008064