You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.1 KiB
161 lines
5.1 KiB
#ifndef SKELETONLIT_FORWARD_PASS_URP_INCLUDED
|
|
#define SKELETONLIT_FORWARD_PASS_URP_INCLUDED
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
#include "SpineCoreShaders/Spine-Common.cginc"
|
|
#include "Spine-Common-URP.hlsl"
|
|
|
|
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(MAIN_LIGHT_CALCULATE_SHADOWS)) && !defined(_RECEIVE_SHADOWS_OFF)
|
|
#define SKELETONLIT_RECEIVE_SHADOWS
|
|
#endif
|
|
|
|
struct appdata {
|
|
float3 pos : POSITION;
|
|
float3 normal : NORMAL;
|
|
half4 color : COLOR;
|
|
float2 uv0 : TEXCOORD0;
|
|
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct VertexOutput {
|
|
half4 color : COLOR0;
|
|
float2 uv0 : TEXCOORD0;
|
|
float4 pos : SV_POSITION;
|
|
|
|
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
|
float4 shadowCoord : TEXCOORD1;
|
|
half3 shadowedColor : TEXCOORD2;
|
|
#endif
|
|
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
half3 ProcessLight(float3 positionWS, half3 normalWS, uint meshRenderingLayers, int lightIndex)
|
|
{
|
|
Light light = GetAdditionalLight(lightIndex, positionWS);
|
|
#ifdef _LIGHT_LAYERS
|
|
if (!IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
|
return half3(0, 0, 0);
|
|
#endif
|
|
|
|
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
|
return LightingLambert(attenuatedLightColor, light.direction, normalWS);
|
|
}
|
|
|
|
half3 LightweightLightVertexSimplified(float3 positionWS, float3 positionCS, half3 normalWS, out half3 shadowedColor) {
|
|
Light mainLight = GetMainLight();
|
|
half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
|
|
half3 mainLightColor = LightingLambert(attenuatedLightColor, mainLight.direction, normalWS);
|
|
|
|
half3 additionalLightColor = half3(0, 0, 0);
|
|
// Note: we don't add any lighting in the fragment shader, thus we include both variants below
|
|
#if defined(_ADDITIONAL_LIGHTS) || defined(_ADDITIONAL_LIGHTS_VERTEX)
|
|
uint meshRenderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
|
#if USE_FORWARD_PLUS
|
|
for (uint lightIndex = 0; lightIndex < min(_AdditionalLightsDirectionalCount, MAX_VISIBLE_LIGHTS); lightIndex++)
|
|
{
|
|
additionalLightColor += ProcessLight(positionWS, normalWS, meshRenderingLayers, lightIndex);
|
|
}
|
|
#endif
|
|
int pixelLightCount = GetAdditionalLightsCount();
|
|
// fill out InputData struct
|
|
InputData inputData; // LIGHT_LOOP_BEGIN macro requires InputData struct in USE_FORWARD_PLUS branch
|
|
inputData.positionWS = positionWS;
|
|
#if defined(_ADDITIONAL_LIGHTS) && USE_FORWARD_PLUS
|
|
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(positionCS);
|
|
#else
|
|
inputData.normalizedScreenSpaceUV = 0;
|
|
#endif
|
|
|
|
LIGHT_LOOP_BEGIN_SPINE(pixelLightCount)
|
|
additionalLightColor += ProcessLight(positionWS, normalWS, meshRenderingLayers, lightIndex);
|
|
LIGHT_LOOP_END_SPINE
|
|
#endif
|
|
shadowedColor = additionalLightColor;
|
|
return mainLightColor + additionalLightColor;
|
|
}
|
|
|
|
VertexOutput vert(appdata v) {
|
|
VertexOutput o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
|
|
half4 color = PMAGammaToTargetSpace(v.color);
|
|
float3 positionWS = TransformObjectToWorld(v.pos);
|
|
half3 fixedNormal = half3(0, 0, -1);
|
|
half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal));
|
|
o.uv0 = v.uv0;
|
|
o.pos = TransformWorldToHClip(positionWS);
|
|
float3 positionCS = o.pos;
|
|
|
|
#ifdef _DOUBLE_SIDED_LIGHTING
|
|
// unfortunately we have to compute the sign here in the vertex shader
|
|
// instead of using VFACE in fragment shader stage.
|
|
half3 viewDirWS = UNITY_MATRIX_V[2].xyz;
|
|
half faceSign = sign(dot(viewDirWS, normalWS));
|
|
normalWS *= faceSign;
|
|
#endif
|
|
|
|
half3 shadowedColor;
|
|
#if !defined(_LIGHT_AFFECTS_ADDITIVE)
|
|
if (color.a == 0) {
|
|
o.color = color;
|
|
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
|
o.shadowedColor = color;
|
|
o.shadowCoord = float4(0, 0, 0, 0);
|
|
#endif
|
|
return o;
|
|
}
|
|
#endif // !defined(_LIGHT_AFFECTS_ADDITIVE)
|
|
|
|
color.rgb *= LightweightLightVertexSimplified(positionWS, positionCS, normalWS, shadowedColor);
|
|
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
|
o.shadowedColor = shadowedColor;
|
|
#endif
|
|
|
|
// Note: ambient light is also handled via SH.
|
|
half3 vertexSH;
|
|
OUTPUT_SH(normalWS.xyz, vertexSH);
|
|
color.rgb += SAMPLE_GI(input.lightmapUV, vertexSH, normalWS);
|
|
o.color = color;
|
|
|
|
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
|
VertexPositionInputs vertexInput;
|
|
vertexInput.positionWS = positionWS;
|
|
vertexInput.positionCS = o.pos;
|
|
o.shadowCoord = GetShadowCoord(vertexInput);
|
|
#endif
|
|
return o;
|
|
}
|
|
|
|
half4 frag(VertexOutput i
|
|
#ifdef _WRITE_RENDERING_LAYERS
|
|
, out float4 outRenderingLayers : SV_Target1
|
|
#endif
|
|
) : SV_Target0
|
|
{
|
|
half4 tex = tex2D(_MainTex, i.uv0);
|
|
#if defined(_STRAIGHT_ALPHA_INPUT)
|
|
tex.rgb *= tex.a;
|
|
#endif
|
|
|
|
if (i.color.a == 0)
|
|
return tex * i.color;
|
|
|
|
#if defined(SKELETONLIT_RECEIVE_SHADOWS)
|
|
half shadowAttenuation = MainLightRealtimeShadow(i.shadowCoord);
|
|
i.color.rgb = lerp(i.shadowedColor, i.color.rgb, shadowAttenuation);
|
|
#endif
|
|
|
|
#ifdef _WRITE_RENDERING_LAYERS
|
|
uint renderingLayers = GetMeshRenderingLayerBackwardsCompatible();
|
|
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
|
|
#endif
|
|
|
|
return tex * i.color;
|
|
}
|
|
|
|
#endif
|