Skip to content
Merged
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Move Assets/Create/Rendering/Universal Render Pipeline/Forward Renderer to Assets/Create/Rendering/URP Forward Renderer
- Removing unused temporary depth buffers for Depth of Field and Panini Projection.
- Optimized the Bokeh Depth of Field shader on mobile by using half precision floats.
- Added Depth and DepthNormals passes to particles shaders.

### Fixed
- Fixed an issue where ShadowCaster2D was generating garbage when running in the editor. [case 1304158](https://issuetracker.unity3d.com/product/unity/issues/guid/1304158/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#ifndef UNIVERSAL_PARTICLES_LIT_DEPTH_NORMALS_PASS_INCLUDED
#define UNIVERSAL_PARTICLES_LIT_DEPTH_NORMALS_PASS_INCLUDED

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

VaryingsDepthNormalsParticle DepthNormalsVertex(AttributesDepthNormalsParticle input)
{
VaryingsDepthNormalsParticle output = (VaryingsDepthNormalsParticle)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

VertexPositionInputs vertexInput = GetVertexPositionInputs(input.vertex.xyz);
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normal, input.tangent);

half3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS);
#if !SHADER_HINT_NICE_QUALITY
viewDirWS = SafeNormalize(viewDirWS);
#endif

#if defined(_NORMALMAP)
output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
#else
output.normalWS = normalInput.normalWS;
output.viewDirWS = viewDirWS;
#endif

output.clipPos = vertexInput.positionCS;

#if defined(_ALPHATEST_ON)
output.color = GetParticleColor(input.color);
#endif

#if defined(_ALPHATEST_ON) || defined(_NORMALMAP)
#if defined(_FLIPBOOKBLENDING_ON)
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords.xyxy, 0.0);
#else
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords, input.texcoordBlend);
#endif
#else
GetParticleTexcoords(output.texcoord, input.texcoords.xy);
#endif
#endif

return output;
}

half4 DepthNormalsFragment(VaryingsDepthNormalsParticle input) : SV_TARGET
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

// Inputs...
#if defined(_ALPHATEST_ON) || defined(_NORMALMAP)
float2 uv = input.texcoord;

#if defined(_FLIPBOOKBLENDING_ON)
float3 blendUv = input.texcoord2AndBlend;
#else
float3 blendUv = float3(0,0,0);
#endif
#endif

// Check if we need to discard...
#if defined(_ALPHATEST_ON)
half4 vertexColor = input.color;
half4 baseColor = _BaseColor;
half4 albedo = BlendTexture(TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap), uv, blendUv) * baseColor;

half4 colorAddSubDiff = half4(0, 0, 0, 0);
#if defined(_COLORADDSUBDIFF_ON)
colorAddSubDiff = _BaseColorAddSubDiff;
#endif

albedo = MixParticleColor(albedo, vertexColor, colorAddSubDiff);
AlphaDiscard(albedo.a, _Cutoff);
#endif

// Normals...
#ifdef _NORMALMAP
half3 normalTS = SampleNormalTS(uv, blendUv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
float3 normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
#else
float3 normalWS = input.normalWS;
#endif

// Output...
#if defined(_GBUFFER_NORMALS_OCT)
float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on Nintendo Switch.
float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
return half4(packedNormalWS, 0.0);
#else
return half4(NormalizeNormalPerPixel(normalWS), 0.0);
#endif
}

#endif // UNIVERSAL_PARTICLES_LIT_DEPTH_NORMALS_PASS_INCLUDED

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef UNIVERSAL_PARTICLES_LIT_DEPTH_ONLY_PASS_INCLUDED
#define UNIVERSAL_PARTICLES_LIT_DEPTH_ONLY_PASS_INCLUDED

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

VaryingsDepthOnlyParticle DepthOnlyVertex(AttributesDepthOnlyParticle input)
{
VaryingsDepthOnlyParticle output = (VaryingsDepthOnlyParticle)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

VertexPositionInputs vertexInput = GetVertexPositionInputs(input.vertex.xyz);
output.clipPos = vertexInput.positionCS;

#if defined(_ALPHATEST_ON)
output.color = GetParticleColor(input.color);

#if defined(_FLIPBOOKBLENDING_ON)
#if defined(UNITY_PARTICLE_INSTANCING_ENABLED)
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords.xyxy, 0.0);
#else
GetParticleTexcoords(output.texcoord, output.texcoord2AndBlend, input.texcoords, input.texcoordBlend);
#endif
#else
GetParticleTexcoords(output.texcoord, input.texcoords.xy);
#endif
#endif

return output;
}

half4 DepthOnlyFragment(VaryingsDepthOnlyParticle input) : SV_TARGET
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

// Check if we need to discard...
#if defined(_ALPHATEST_ON)
float2 uv = input.texcoord;
half4 vertexColor = input.color;
half4 baseColor = _BaseColor;

#if defined(_FLIPBOOKBLENDING_ON)
float3 blendUv = input.texcoord2AndBlend;
#else
float3 blendUv = float3(0,0,0);
#endif

half4 albedo = BlendTexture(TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap), uv, blendUv) * baseColor;
half4 colorAddSubDiff = half4(0, 0, 0, 0);
#if defined (_COLORADDSUBDIFF_ON)
colorAddSubDiff = _BaseColorAddSubDiff;
#endif

albedo = MixParticleColor(albedo, vertexColor, colorAddSubDiff);
AlphaDiscard(albedo.a, _Cutoff);
#endif

return 0;
}

#endif // UNIVERSAL_PARTICLES_LIT_DEPTH_ONLY_PASS_INCLUDED

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

struct AttributesParticle
{
float4 vertex : POSITION;
half4 color : COLOR;
float4 vertex : POSITION;
half4 color : COLOR;

#if defined(_FLIPBOOKBLENDING_ON) && !defined(UNITY_PARTICLE_INSTANCING_ENABLED)
float4 texcoords : TEXCOORD0;
float texcoordBlend : TEXCOORD1;
float4 texcoords : TEXCOORD0;
float texcoordBlend : TEXCOORD1;
#else
float2 texcoords : TEXCOORD0;
float2 texcoords : TEXCOORD0;
#endif

#if !defined(PARTICLES_EDITOR_META_PASS)
float3 normal : NORMAL;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 tangent : TANGENT;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Expand Down Expand Up @@ -59,4 +59,91 @@ struct VaryingsParticle
UNITY_VERTEX_OUTPUT_STEREO
};

struct AttributesDepthOnlyParticle
{
float4 vertex : POSITION;

#if defined(_ALPHATEST_ON)
half4 color : COLOR;

#if defined(_FLIPBOOKBLENDING_ON) && !defined(UNITY_PARTICLE_INSTANCING_ENABLED)
float4 texcoords : TEXCOORD0;
float texcoordBlend : TEXCOORD1;
#else
float2 texcoords : TEXCOORD0;
#endif
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct VaryingsDepthOnlyParticle
{
float4 clipPos : SV_POSITION;

#if defined(_ALPHATEST_ON)
float2 texcoord : TEXCOORD0;
half4 color : COLOR;

#if defined(_FLIPBOOKBLENDING_ON)
float3 texcoord2AndBlend : TEXCOORD5;
#endif
#endif

UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

struct AttributesDepthNormalsParticle
{
float4 vertex : POSITION;

#if defined(_ALPHATEST_ON)
half4 color : COLOR;
#endif

#if defined(_ALPHATEST_ON) || defined(_NORMALMAP)
#if defined(_FLIPBOOKBLENDING_ON) && !defined(UNITY_PARTICLE_INSTANCING_ENABLED)
float4 texcoords : TEXCOORD0;
float texcoordBlend : TEXCOORD1;
#else
float2 texcoords : TEXCOORD0;
#endif
#endif

float3 normal : NORMAL;
float4 tangent : TANGENT;

UNITY_VERTEX_INPUT_INSTANCE_ID
};


struct VaryingsDepthNormalsParticle
{
float4 clipPos : SV_POSITION;

#if defined(_ALPHATEST_ON)
half4 color : COLOR;
#endif

#if defined(_ALPHATEST_ON) || defined(_NORMALMAP)
float2 texcoord : TEXCOORD0;

#if defined(_FLIPBOOKBLENDING_ON)
float3 texcoord2AndBlend : TEXCOORD5;
#endif
#endif

#if defined(_NORMALMAP)
float4 normalWS : TEXCOORD2; // xyz: normal, w: viewDir.x
float4 tangentWS : TEXCOORD3; // xyz: tangent, w: viewDir.y
float4 bitangentWS : TEXCOORD4; // xyz: bitangent, w: viewDir.z
#else
float3 normalWS : TEXCOORD2;
float3 viewDirWS : TEXCOORD3;
#endif

UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};

#endif // UNIVERSAL_PARTICLES_INPUT_INCLUDED
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Shader "Universal Render Pipeline/Particles/Lit"
// -------------------------------------
// Particle Keywords
#pragma shader_feature_local_fragment _ _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON
#pragma shader_feature_local_fragment _ALPHATEST_ON
#pragma shader_feature_local_fragment _ _ALPHATEST_ON
#pragma shader_feature_local_fragment _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON
#pragma shader_feature_local _FLIPBOOKBLENDING_ON
#pragma shader_feature_local _SOFTPARTICLES_ON
Expand Down Expand Up @@ -172,6 +172,69 @@ Shader "Universal Render Pipeline/Particles/Lit"
ENDHLSL
}
// ------------------------------------------------------------------
// Depth Only pass.
Pass
{
Name "DepthOnly"
Tags{"LightMode" = "DepthOnly"}

ZWrite On
ColorMask 0
Cull[_Cull]

HLSLPROGRAM
#pragma target 2.0

// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ _ALPHATEST_ON
#pragma shader_feature_local _ _FLIPBOOKBLENDING_ON
#pragma shader_feature_local_fragment _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON

// -------------------------------------
// Unity defined keywords
#pragma multi_compile_instancing
#pragma instancing_options procedural:ParticleInstancingSetup

#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment

#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl"
ENDHLSL
}
// This pass is used when drawing to a _CameraNormalsTexture texture
Pass
{
Name "DepthNormals"
Tags{"LightMode" = "DepthNormals"}

ZWrite On
Cull[_Cull]

HLSLPROGRAM
#pragma target 2.0

// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ _NORMALMAP
#pragma shader_feature_local _ _FLIPBOOKBLENDING_ON
#pragma shader_feature_local _ _ALPHATEST_ON
#pragma shader_feature_local_fragment _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON

// -------------------------------------
// Unity defined keywords
#pragma multi_compile_instancing
#pragma instancing_options procedural:ParticleInstancingSetup

#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment

#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthNormalsPass.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Scene view outline pass.
Pass
{
Expand Down
Loading