Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions Assets/Fur/Shaders/Fin/Lit.hlsl
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#ifndef FUR_FIN_LIT_HLSL
#define FUR_FIN_LIT_HLSL

#include "HLSLSupport.cginc"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "./Param.hlsl"
#include "../Common/Common.hlsl"

struct _Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 texcoord : TEXCOORD0;
float2 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

struct Varyings
Expand All @@ -25,11 +37,20 @@ struct Varyings
float4 fogFactorAndVertexLight : TEXCOORD4; // x: fogFactor, yzw: vertex light
float2 finUv : TEXCOORD5;
float3 finTangentWS : TEXCOORD6;
UNITY_VERTEX_OUTPUT_STEREO
};

Attributes vert(Attributes input)
Attributes vert(_Attributes input)
{
return input;
Attributes o;
UNITY_INITIALIZE_OUTPUT(Attributes, o);
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, o);
o.positionOS = input.positionOS;
o.normalOS = input.normalOS;
o.lightmapUV = input.lightmapUV;
o.texcoord = input.texcoord;
return o;
}

void AppendFinVertex(
Expand All @@ -39,9 +60,10 @@ void AppendFinVertex(
float3 posOS,
float3 normalOS,
float2 finUv,
float3 finSideDirWS)
float3 finSideDirWS,
Attributes input0)
{
Varyings output = (Varyings)0;
Varyings output;

VertexPositionInputs vertexInput = GetVertexPositionInputs(posOS);
output.positionCS = vertexInput.positionCS;
Expand All @@ -58,6 +80,7 @@ void AppendFinVertex(
OUTPUT_LIGHTMAP_UV(lightmapUV, unity_LightmapST, output.lightmapUV);
OUTPUT_SH(output.normalWS, output.vertexSH);

UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
stream.Append(output);
}

Expand Down Expand Up @@ -116,15 +139,15 @@ void AppendFinVertices(
{

float3 finNormalOS = normalize(lerp(normalOS0, faceNormalOS, _FaceNormalFactor));
AppendFinVertex(stream, uv0, lightmapUV0, posBeginOS, finNormalOS, float2(uvX1, finFactor), finSideDirWS);
AppendFinVertex(stream, uv12, lightmapUV12, posEndOS, finNormalOS, float2(uvX2, finFactor), finSideDirWS);
AppendFinVertex(stream, uv0, lightmapUV0, posBeginOS, finNormalOS, float2(uvX1, finFactor), finSideDirWS, input0);
AppendFinVertex(stream, uv12, lightmapUV12, posEndOS, finNormalOS, float2(uvX2, finFactor), finSideDirWS, input0);
}
else
{
faceNormalOS *= -1.0;
float3 finNormalOS = normalize(lerp(normalOS0, faceNormalOS, _FaceNormalFactor));
AppendFinVertex(stream, uv12, lightmapUV12, posEndOS, finNormalOS, float2(uvX2, finFactor), finSideDirWS);
AppendFinVertex(stream, uv0, lightmapUV0, posBeginOS, finNormalOS, float2(uvX1, finFactor), finSideDirWS);
AppendFinVertex(stream, uv12, lightmapUV12, posEndOS, finNormalOS, float2(uvX2, finFactor), finSideDirWS, input0);
AppendFinVertex(stream, uv0, lightmapUV0, posBeginOS, finNormalOS, float2(uvX1, finFactor), finSideDirWS, input0);
}
}

Expand All @@ -135,10 +158,12 @@ void AppendFinVertices(
[maxvertexcount(39)]
void geom(triangle Attributes input[3], inout TriangleStream<Varyings> stream)
{
UNITY_SETUP_INSTANCE_ID(input[0]);
#ifdef DRAW_ORIG_POLYGON
for (int i = 0; i < 3; ++i)
{
Varyings output = (Varyings)0;
Varyings output;
UNITY_INITIALIZE_OUTPUT(Varyings, output);

VertexPositionInputs vertexInput = GetVertexPositionInputs(input[i].positionOS.xyz);
output.positionCS = vertexInput.positionCS;
Expand All @@ -154,6 +179,7 @@ void geom(triangle Attributes input[3], inout TriangleStream<Varyings> stream)
OUTPUT_LIGHTMAP_UV(input[i].lightmapUV, unity_LightmapST, output.lightmapUV);
OUTPUT_SH(output.normalWS, output.vertexSH);

UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
stream.Append(output);
}
stream.RestartStrip();
Expand All @@ -172,6 +198,7 @@ void geom(triangle Attributes input[3], inout TriangleStream<Varyings> stream)

float4 frag(Varyings input) : SV_Target
{
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(input);
float4 furColor = SAMPLE_TEXTURE2D(_FurMap, sampler_FurMap, input.finUv);
if (input.finUv.x >= 0.0 && furColor.a < _AlphaCutout) discard;

Expand All @@ -193,7 +220,7 @@ float4 frag(Varyings input) : SV_Target
inputData.positionWS = input.positionWS;
inputData.normalWS = normalWS;
inputData.viewDirectionWS = viewDirWS;
#if defined(_MAIN_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF)
#if (defined(_MAIN_LIGHT_SHADOWS) || defined(_MAIN_LIGHT_SHADOWS_CASCADE) || defined(_MAIN_LIGHT_SHADOWS_SCREEN)) && !defined(_RECEIVE_SHADOWS_OFF)
inputData.shadowCoord = TransformWorldToShadowCoord(input.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
Expand All @@ -205,7 +232,7 @@ float4 frag(Varyings input) : SV_Target
float4 color = UniversalFragmentPBR(inputData, surfaceData);
ApplyRimLight(color.rgb, input.positionWS, viewDirWS, input.normalWS);
color.rgb += _AmbientColor.rgb;
color.rgb = MixFog(color.rgb, inputData.fogCoord);
color.rgb = clamp(MixFog(color.rgb, inputData.fogCoord), 0, 1);

return color;
}
Expand Down
10 changes: 10 additions & 0 deletions Assets/Fur/Shaders/Fin/Lit.shader
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ SubShader

HLSLPROGRAM
// URP
#if (UNITY_VERSION >= 202111)
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#else
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#endif
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile _ _SHADOWS_SOFT
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE

// Unity
#pragma multi_compile_instancing
#pragma multi_compile _ DOTS_INSTANCING_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_fog
Expand Down Expand Up @@ -96,6 +102,8 @@ SubShader
Cull Off

HLSLPROGRAM
#pragma multi_compile_instancing
#pragma multi_compile _ DOTS_INSTANCING_ON
#pragma exclude_renderers gles gles3 glcore
#pragma multi_compile_fog
#pragma multi_compile _ DRAW_ORIG_POLYGON
Expand Down Expand Up @@ -123,6 +131,8 @@ SubShader
Cull Off

HLSLPROGRAM
#pragma multi_compile_instancing
#pragma multi_compile _ DOTS_INSTANCING_ON
#pragma exclude_renderers gles gles3 glcore
#pragma multi_compile_fog
#pragma multi_compile _ DRAW_ORIG_POLYGON
Expand Down
5 changes: 4 additions & 1 deletion Assets/Fur/Shaders/Fin/LitTessellation.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct HsConstantOutput
[outputcontrolpoints(3)]
Attributes hull(InputPatch<Attributes, 3> input, uint id : SV_OutputControlPointID)
{
UNITY_SETUP_INSTANCE_ID(input[id]);
return input[id];
}

Expand Down Expand Up @@ -76,7 +77,9 @@ Attributes domain(
const OutputPatch<Attributes, 3> i,
float3 bary : SV_DomainLocation)
{
Attributes o = (Attributes)0;
Attributes o;
UNITY_INITIALIZE_OUTPUT(Attributes, o);
UNITY_TRANSFER_INSTANCE_ID(i[0], o);

float fU = bary.x;
float fV = bary.y;
Expand Down
37 changes: 30 additions & 7 deletions Assets/Fur/Shaders/Fin/Shadow.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
#include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
#include "./Param.hlsl"
#include "../Common/Common.hlsl"
#include "HLSLSupport.cginc"

struct _Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct Attributes
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

struct Varyings
Expand All @@ -18,21 +29,33 @@ struct Varyings
float2 uv : TEXCOORD0;
float fogCoord : TEXCOORD1;
float2 finUv : TEXCOORD2;
UNITY_VERTEX_OUTPUT_STEREO
};

Attributes vert(Attributes input)
Attributes vert(_Attributes input)
{
return input;
Attributes output;
UNITY_INITIALIZE_OUTPUT(Attributes, output);
//UNITY_SETUP_INSTANCE_ID(input); //Insert
//UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); //Insert
UNITY_TRANSFER_INSTANCE_ID(input, output);
output.positionOS = input.positionOS;
output.normalOS = input.normalOS;
output.uv = input.uv;
return output;
}

void AppendFinVertex(
inout TriangleStream<Varyings> stream,
float2 uv,
float3 posOS,
float3 normalWS,
float2 finUv)
float2 finUv,
Attributes input0)
{
Varyings output;
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input0, output);

#ifdef SHADOW_CASTER_PASS
float3 posWS = TransformObjectToWorld(posOS);
Expand Down Expand Up @@ -65,8 +88,8 @@ void AppendFinVertices(
float uvXScale = length(uv0 - uv12) * _Density;
float3 normalWS = TransformObjectToWorldNormal(normalOS);

AppendFinVertex(stream, uv0, posOS0, normalWS, float2(uvOffset, 0.0));
AppendFinVertex(stream, uv12, posOS3, normalWS, float2(uvOffset + uvXScale, 0.0));
AppendFinVertex(stream, uv0, posOS0, normalWS, float2(uvOffset, 0.0), input0);
AppendFinVertex(stream, uv12, posOS3, normalWS, float2(uvOffset + uvXScale, 0.0), input0);

float3 posWS = TransformObjectToWorld(posOS0);
float finStep = _FinLength / _FinJointNum;
Expand All @@ -82,8 +105,8 @@ void AppendFinVertices(
float3 moveOS = TransformWorldToObjectDir(moveWS, false);
posOS0 += moveOS;
posOS3 += moveOS;
AppendFinVertex(stream, uv0, posOS0, normalWS, float2(uvOffset, finFactor));
AppendFinVertex(stream, uv12, posOS3, normalWS, float2(uvOffset + uvXScale, finFactor));
AppendFinVertex(stream, uv0, posOS0, normalWS, float2(uvOffset, finFactor), input0);
AppendFinVertex(stream, uv12, posOS3, normalWS, float2(uvOffset + uvXScale, finFactor), input0);
}
stream.RestartStrip();
}
Expand Down
Loading