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,194 @@
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
float3 _LightDirection;
#ifdef VFX_VARYING_PS_INPUTS
void VFXTransformPSInputs(inout VFX_VARYING_PS_INPUTS input) {}
float4 VFXApplyPreExposure(float4 color, float exposureWeight)
{
return color;
}
float4 VFXApplyPreExposure(float4 color, VFX_VARYING_PS_INPUTS input)
{
return color;
}
#endif
float4 VFXTransformFinalColor(float4 color)
{
return color;
}
float2 VFXGetNormalizedScreenSpaceUV(float4 clipPos)
{
return GetNormalizedScreenSpaceUV(clipPos);
}
void VFXEncodeMotionVector(float2 velocity, out float4 outBuffer)
{
//TODO : LWRP doesn't support motion vector & TAA yet
outBuffer = (float4)0.0f;
}
float4 VFXTransformPositionWorldToClip(float3 posWS)
{
return TransformWorldToHClip(posWS);
}
float4 VFXTransformPositionWorldToNonJitteredClip(float3 posWS)
{
//TODO : LWRP doesn't support motion vector & TAA yet
return VFXTransformPositionWorldToClip(posWS);
}
float4 VFXTransformPositionWorldToPreviousClip(float3 posWS)
{
//TODO : LWRP doesn't support motion vector & TAA yet
return VFXTransformPositionWorldToClip(posWS);
}
float4 VFXTransformPositionObjectToClip(float3 posOS)
{
float3 posWS = TransformObjectToWorld(posOS);
return VFXTransformPositionWorldToClip(posWS);
}
float4 VFXTransformPositionObjectToNonJitteredClip(float3 posOS)
{
//TODO : LWRP doesn't support motion vector & TAA yet
return VFXTransformPositionObjectToClip(posOS);
}
float4 VFXTransformPositionObjectToPreviousClip(float3 posOS)
{
//TODO : LWRP doesn't support motion vector & TAA yet
return VFXTransformPositionObjectToClip(posOS);
}
float3 VFXTransformPositionWorldToView(float3 posWS)
{
return TransformWorldToView(posWS);
}
float3 VFXTransformPositionWorldToCameraRelative(float3 posWS)
{
#if SHADEROPTIONS_CAMERA_RELATIVE_RENDERING
#error VFX Camera Relative rendering isn't supported in URP.
#endif
return posWS;
}
//Compatibility functions for the common ShaderGraph integration
float4x4 ApplyCameraTranslationToMatrix(float4x4 modelMatrix)
{
return modelMatrix;
}
float4x4 ApplyCameraTranslationToInverseMatrix(float4x4 inverseModelMatrix)
{
return inverseModelMatrix;
}
float4x4 GetRawUnityObjectToWorld()
{
return unity_ObjectToWorld;
}
float4x4 GetRawUnityWorldToObject()
{
return unity_WorldToObject;
}
//End of compatibility functions
float4x4 VFXGetObjectToWorldMatrix()
{
// NOTE: If using the new generation path, explicitly call the object matrix (since the particle matrix is now baked into UNITY_MATRIX_M)
#ifdef HAVE_VFX_MODIFICATION
return GetRawUnityObjectToWorld();
#else
return GetObjectToWorldMatrix();
#endif
}
float4x4 VFXGetWorldToObjectMatrix()
{
// NOTE: If using the new generation path, explicitly call the object matrix (since the particle matrix is now baked into UNITY_MATRIX_I_M)
#ifdef HAVE_VFX_MODIFICATION
return GetRawUnityWorldToObject();
#else
return GetWorldToObjectMatrix();
#endif
}
float3x3 VFXGetWorldToViewRotMatrix()
{
return (float3x3)GetWorldToViewMatrix();
}
float3 VFXGetViewWorldPosition()
{
return GetCurrentViewPosition();
}
float4x4 VFXGetViewToWorldMatrix()
{
return UNITY_MATRIX_I_V;
}
#ifdef USING_STEREO_MATRICES
float3 GetWorldStereoOffset()
{
return float3(0.0f, 0.0f, 0.0f);
}
#endif
float VFXSampleDepth(float4 posSS)
{
float2 screenUV = GetNormalizedScreenSpaceUV(posSS.xy);
// In URP, the depth texture is optional and could be 4x4 white texture, Load isn't appropriate in that case.
//float depth = LoadSceneDepth(screenUV * _ScreenParams.xy);
float depth = SampleSceneDepth(screenUV);
return depth;
}
void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS, float3 normalWS)
{
posWS = ApplyShadowBias(posWS, normalWS, _LightDirection);
posCS = VFXTransformPositionWorldToClip(posWS);
}
void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS)
{
posWS = ApplyShadowBias(posWS, _LightDirection, _LightDirection);
posCS = VFXTransformPositionWorldToClip(posWS);
}
float4 VFXApplyFog(float4 color,float4 posCS,float3 posWS)
{
float4 fog = (float4)0;
fog.rgb = unity_FogColor.rgb;
float fogFactor = ComputeFogFactor(posCS.z * posCS.w);
fog.a = ComputeFogIntensity(fogFactor);
#if VFX_BLENDMODE_ALPHA || IS_OPAQUE_PARTICLE
color.rgb = lerp(fog.rgb, color.rgb, fog.a);
#elif VFX_BLENDMODE_ADD
color.rgb *= fog.a;
#elif VFX_BLENDMODE_PREMULTIPLY
color.rgb = lerp(fog.rgb * color.a, color.rgb, fog.a);
#endif
return color;
}
float3 VFXGetCameraWorldDirection()
{
return unity_CameraToWorld._m02_m12_m22;
}

View file

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

View file

@ -0,0 +1,9 @@
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#define USE_FOG 1
#endif
// this is only necessary for the old VFXTarget pathway
// it defines the macro used to access hybrid instanced properties
// (new HDRP/URP Target pathway overrides the type so this is never used)
#define UNITY_ACCESS_HYBRID_INSTANCED_PROP(name, type) name

View file

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

View file

@ -0,0 +1,152 @@
// Upgrade NOTE: replaced 'defined at' with 'defined (at)'
#ifndef SHADERPASS
#error SHADERPASS must be defined (at) this point
#endif
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
float3 VFXGetPositionRWS(VFX_VARYING_PS_INPUTS i)
{
float3 posWS = (float3)0;
#ifdef VFX_VARYING_POSWS
posWS = i.VFX_VARYING_POSWS;
#endif
return VFXGetPositionRWS(posWS);
}
InputData VFXGetInputData(const VFX_VARYING_PS_INPUTS i, const PositionInputs posInputs, const SurfaceData surfaceData, float3 normalWS)
{
InputData inputData = (InputData)0;
inputData.positionWS = posInputs.positionWS.xyz;
inputData.normalWS = normalWS;
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(inputData.positionWS);
//When there is only one cascaded, this shadowCoord can be computed at vertex stage
//#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
// inputData.shadowCoord = inputData.shadowCoord;
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
//This ComputeFogFactor can be moved to vertex and use interpolator instead
float fogFactor = ComputeFogFactor(i.VFX_VARYING_POSCS.z);
inputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), fogFactor);
//SampleSH could partially be done on vertex using SampleSHVertex & SampleSHPixel
//For now, use directly the simpler per pixel fallback
inputData.bakedGI = SampleSH(normalWS);
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(i.VFX_VARYING_POSCS);
//No static light map in VFX
//inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
return inputData;
}
#ifndef VFX_SHADERGRAPH
SurfaceData VFXGetSurfaceData(const VFX_VARYING_PS_INPUTS i, float3 normalWS, const VFXUVData uvData, out float opacity)
{
SurfaceData surfaceData = (SurfaceData)0;
float4 baseColorMapSample = (float4)1.0f;
float4 color = float4(1,1,1,1);
#if URP_USE_BASE_COLOR
color *= VFXGetParticleColor(i);
#elif URP_USE_ADDITIONAL_BASE_COLOR
#if defined(VFX_VARYING_COLOR)
color.xyz *= i.VFX_VARYING_COLOR;
#endif
#if defined(VFX_VARYING_ALPHA)
color.a *= i.VFX_VARYING_ALPHA;
#endif
#endif
#if URP_USE_BASE_COLOR_MAP
baseColorMapSample = SampleTexture(VFX_SAMPLER(baseColorMap),uvData);
#if URP_USE_BASE_COLOR_MAP_COLOR
color.xyz *= baseColorMapSample.xyz;
#endif
#if URP_USE_BASE_COLOR_MAP_ALPHA
color.a *= baseColorMapSample.a;
#endif
#endif
color.a *= VFXGetSoftParticleFade(i);
VFXClipFragmentColor(color.a,i);
surfaceData.albedo = saturate(color.rgb);
#if IS_OPAQUE_PARTICLE
opacity = 1.0f;
#else
opacity = saturate(color.a);
#endif
surfaceData.alpha = opacity;
float4 metallicMapSample = (float4)1.0f;
float4 specularMapSample = (float4)1.0f;
#if URP_MATERIAL_TYPE_METALLIC
surfaceData.metallic = 1.0f;
#ifdef VFX_VARYING_METALLIC
surfaceData.metallic *= i.VFX_VARYING_METALLIC;
#endif
#if URP_USE_METALLIC_MAP
metallicMapSample = SampleTexture(VFX_SAMPLER(metallicMap), uvData);
surfaceData.metallic *= metallicMapSample.r;
#endif
#elif URP_MATERIAL_TYPE_SPECULAR
surfaceData.specular = (float3)1.0f;
#ifdef VFX_VARYING_SPECULAR
surfaceData.specular *= saturate(i.VFX_VARYING_SPECULAR);
#endif
#if URP_USE_SPECULAR_MAP
specularMapSample = SampleTexture(VFX_SAMPLER(specularMap), uvData);
surfaceData.specular *= specularMapSample.rgb;
#endif
#endif
surfaceData.normalTS = float3(1.0f, 0.0f, 0.0f); //NormalWS is directly modified in VFX
surfaceData.smoothness = 1.0f;
#ifdef VFX_VARYING_SMOOTHNESS
surfaceData.smoothness *= i.VFX_VARYING_SMOOTHNESS;
#endif
#if URP_USE_SMOOTHNESS_IN_ALBEDO
surfaceData.smoothness *= baseColorMapSample.a;
#elif URP_USE_SMOOTHNESS_IN_METALLIC
surfaceData.smoothness *= metallicMapSample.a;
#elif URP_USE_SMOOTHNESS_IN_SPECULAR
surfaceData.smoothness *= specularMapSample.a;
#endif
surfaceData.occlusion = 1.0f;
#if URP_USE_OCCLUSION_MAP
float4 mask = SampleTexture(VFX_SAMPLER(occlusionMap),uvData);
surfaceData.occlusion *= mask.g;
#endif
#if URP_USE_EMISSIVE
surfaceData.emission = float3(1, 1, 1);
#if URP_USE_EMISSIVE_MAP
float emissiveScale = 1.0f;
#ifdef VFX_VARYING_EMISSIVESCALE
emissiveScale = i.VFX_VARYING_EMISSIVESCALE;
#endif
surfaceData.emission *= SampleTexture(VFX_SAMPLER(emissiveMap), uvData).rgb * emissiveScale;
#endif
#if defined(VFX_VARYING_EMISSIVE) && (URP_USE_EMISSIVE_COLOR || URP_USE_ADDITIONAL_EMISSIVE_COLOR)
surfaceData.emission *= i.VFX_VARYING_EMISSIVE;
#endif
#ifdef VFX_VARYING_EXPOSUREWEIGHT
surfaceData.emission *= lerp(GetInverseCurrentExposureMultiplier(), 1.0f, i.VFX_VARYING_EXPOSUREWEIGHT);
#endif
#endif
return surfaceData;
}
#endif

View file

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

View file

@ -0,0 +1,100 @@
#ifndef SHADERPASS
#error SHADERPASS must be defined
#endif
#ifndef UNIVERSAL_SHADERPASS_INCLUDED
#error ShaderPass has to be included
#endif
#if (SHADERPASS == SHADERPASS_FORWARD)
float4 VFXCalcPixelOutputForward(const SurfaceData surfaceData, const InputData inputData)
{
float4 color = UniversalFragmentPBR(inputData, surfaceData);
color.rgb = MixFog(color.rgb, inputData.fogCoord);
#if IS_OPAQUE_PARTICLE
float _Surface = 0.0f;
#else
float _Surface = 1.0f;
#endif
color.a = OutputAlpha(color.a, _Surface);
return color;
}
#ifndef VFX_SHADERGRAPH
float4 VFXGetPixelOutputForward(const VFX_VARYING_PS_INPUTS i, float3 normalWS, const VFXUVData uvData)
{
SurfaceData surfaceData;
InputData inputData;
VFXGetURPLitData(surfaceData, inputData, i, normalWS, uvData, (uint2)0);
return VFXCalcPixelOutputForward(surfaceData, inputData);
}
#else
float4 VFXGetPixelOutputForwardShaderGraph(const VFX_VARYING_PS_INPUTS i, SurfaceData surfaceData, float3 normalWS)
{
float3 posRWS = VFXGetPositionRWS(i);
float4 posSS = i.VFX_VARYING_POSCS;
PositionInputs posInput = GetPositionInput(posSS.xy, _ScreenSize.zw, posSS.z, posSS.w, posRWS, (uint2)0);
VFXUVData uvData = (VFXUVData)0;
InputData inputData = VFXGetInputData(i, posInput, surfaceData, normalWS);
return VFXCalcPixelOutputForward(surfaceData, inputData);
}
#endif
#elif (SHADERPASS == SHADERPASS_DEPTHNORMALSONLY)
void VFXComputePixelOutputToNormalBuffer(float3 normalWS, out float4 outNormalBuffer)
{
#if defined(_GBUFFER_NORMALS_OCT)
float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms
float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
outNormalBuffer = float4(packedNormalWS, 0.0);
#else
outNormalBuffer = float4(normalWS, 0.0);
#endif
}
#else
#ifndef VFX_SHADERGRAPH
void VFXComputePixelOutputToGBuffer(const VFX_VARYING_PS_INPUTS i, const float3 normalWS, const VFXUVData uvData, out FragmentOutput gBuffer)
{
SurfaceData surfaceData;
InputData inputData;
VFXGetURPLitData(surfaceData, inputData, i, normalWS, uvData, (uint2)0);
BRDFData brdfData;
InitializeBRDFData(surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.alpha, brdfData);
half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surfaceData.occlusion, inputData.positionWS, inputData.normalWS, inputData.viewDirectionWS);
gBuffer = BRDFDataToGbuffer(brdfData, inputData, surfaceData.smoothness, surfaceData.emission + color, surfaceData.occlusion);
}
#else
void VFXComputePixelOutputToGBufferShaderGraph(const VFX_VARYING_PS_INPUTS i, SurfaceData surfaceData, const float3 normalWS, out FragmentOutput gBuffer)
{
float3 posRWS = VFXGetPositionRWS(i);
float4 posSS = i.VFX_VARYING_POSCS;
PositionInputs posInput = GetPositionInput(posSS.xy, _ScreenSize.zw, posSS.z, posSS.w, posRWS, (uint2)0);
VFXUVData uvData = (VFXUVData)0;
InputData inputData = VFXGetInputData(i, posInput, surfaceData, normalWS);
BRDFData brdfData;
InitializeBRDFData(surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.alpha, brdfData);
half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surfaceData.occlusion, inputData.positionWS, inputData.normalWS, inputData.viewDirectionWS);
gBuffer = BRDFDataToGbuffer(brdfData, inputData, surfaceData.smoothness, surfaceData.emission + color, surfaceData.occlusion);
}
#endif
#endif

View file

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