intial commit

This commit is contained in:
Caleb Sandford deQuincey
2025-06-27 23:27:49 +01:00
commit ecdd3e2a9e
31269 changed files with 4937644 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 424d16c89244f3e4685b81926e90cb4b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,226 @@
#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/AmbientOcclusion.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
float2 VFXGetNormalizedScreenSpaceUV(float4 clipPos)
{
return GetNormalizedScreenSpaceUV(clipPos);
}
void VFXEncodeMotionVector(float2 velocity, out float4 outBuffer)
{
outBuffer = float4(velocity.xy, 0, 0);
}
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)
#if defined(HAVE_VFX_MODIFICATION) && !defined(SHADER_STAGE_COMPUTE)
return GetSGVFXUnityObjectToWorld();
#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)
#if defined(HAVE_VFX_MODIFICATION) && !defined(SHADER_STAGE_COMPUTE)
return GetSGVFXUnityWorldToObject();
#else
return GetWorldToObjectMatrix();
#endif
}
float4 VFXTransformPositionWorldToClip(float3 posWS)
{
return TransformWorldToHClip(posWS);
}
float4 VFXTransformPositionWorldToNonJitteredClip(float3 posWS)
{
return mul(_NonJitteredViewProjMatrix, float4(posWS, 1.0f));
}
float4 VFXTransformPositionWorldToPreviousClip(float3 posWS)
{
return mul(_PrevViewProjMatrix, float4(posWS, 1.0f));
}
float4 VFXTransformPositionObjectToClip(float3 posOS)
{
float3 posWS = mul(VFXGetObjectToWorldMatrix(), float4(posOS,1)).xyz;
return VFXTransformPositionWorldToClip(posWS);
}
float4 VFXTransformPositionObjectToNonJitteredClip(float3 posOS)
{
float3 posWS = mul(VFXGetObjectToWorldMatrix(), float4(posOS,1)).xyz;
return VFXTransformPositionWorldToNonJitteredClip(posWS);
}
float3 VFXTransformPreviousObjectToWorld(float3 posOS)
{
return mul(GetPrevObjectToWorldMatrix(), float4(posOS, 1.0)).xyz;
}
float4 VFXTransformPositionObjectToPreviousClip(float3 posOS)
{
float3 posWS = VFXTransformPreviousObjectToWorld(posOS);
return VFXTransformPositionWorldToPreviousClip(posWS);
}
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;
}
//End of compatibility functions
float3x3 VFXGetWorldToViewRotMatrix()
{
return (float3x3)GetWorldToViewMatrix();
}
float3 VFXGetViewWorldPosition()
{
return GetCurrentViewPosition();
}
float4x4 VFXGetViewToWorldMatrix()
{
return UNITY_MATRIX_I_V;
}
#ifdef USING_STEREO_MATRICES
float3 GetWorldStereoOffset()
{
return unity_StereoWorldSpaceCameraPos[0].xyz - unity_StereoWorldSpaceCameraPos[1].xyz;
}
float4x4 GetNonJitteredViewProjMatrix(int eye)
{
return _NonJitteredViewProjMatrixStereo[eye];
}
#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 VFXApplyAO(float4 color, float4 posCS)
{
#if defined(_SCREEN_SPACE_OCCLUSION) && !defined(_SURFACE_TYPE_TRANSPARENT)
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(posCS);
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(normalizedScreenSpaceUV);
color.rgb *= aoFactor.directAmbientOcclusion;
#endif
return color;
}
float4 VFXTransformFinalColor(float4 color, float4 posCS)
{
if (IsOnlyAOLightingFeatureEnabled())
{
color.rgb = (float3)1.0f;
color = VFXApplyAO(color, posCS);
}
return color;
}
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;
}
#if defined(_GBUFFER_NORMALS_OCT)
#define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer) \
{ \
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
#define VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer) \
{ \
outNormalBuffer = float4(normalWS, 0.0); \
}
#endif

View File

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

View File

@@ -0,0 +1,45 @@
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#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
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
#define CameraBuffer Texture2DArray
#define VFXSamplerCameraBuffer VFXSampler2DArray
#else
#define CameraBuffer Texture2D
#define VFXSamplerCameraBuffer VFXSampler2D
#endif
#if IS_TRANSPARENT_PARTICLE
#define _SURFACE_TYPE_TRANSPARENT
#endif
#if VFX_SIX_WAY_COLOR_ABSORPTION
#define _SIX_WAY_COLOR_ABSORPTION
#endif
//URP currently does not allow to know the blend mode in the shader in general, but we have this information in VFX generated shaders.
#if VFX_BLENDMODE_PREMULTIPLY
#define _BLENDMODE_PREMULTIPLY
#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
#define USE_MULTI_COMPILE_XR_IN_OUTPUT_UPDATE 1
//Unlit can use the DepthNormal pass which creates a discrepancy while computing depth
#define FORCE_NORMAL_OUTPUT_UNLIT_VERTEX_SHADER 1
#if USE_GEOMETRY_SHADER
#define CULL_VERTEX(o) return;
#else
#define CULL_VERTEX(o) { o.VFX_VARYING_POSCS.x = VFX_NAN; return o; }
#endif
#if HAS_STRIPS
#define HAS_STRIPS_DATA 1
#endif

View File

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

View File

@@ -0,0 +1,275 @@
// Upgrade NOTE: replaced 'defined at' with 'defined (at)'
#ifndef SHADERPASS
#error SHADERPASS must be defined (at) this point
#endif
#if VFX_MATERIAL_TYPE_SIX_WAY_SMOKE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SixWayLighting.hlsl"
#include "Packages/com.unity.visualeffectgraph/Shaders/SixWay/VFXSixWayCommon.hlsl"
#else
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
#endif
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, float3 normalWS, bool frontFace)
{
InputData inputData = (InputData)0;
inputData.positionWS = posInputs.positionWS.xyz;
inputData.normalWS = normalWS;
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(inputData.positionWS);
inputData.positionCS = i.VFX_VARYING_POSCS;
#if defined(VFX_MATERIAL_TYPE_SIX_WAY_SMOKE) && defined(VFX_VARYING_TANGENT)
float signNormal = frontFace ? 1.0 : -1.0f;
float3 bitangent = cross(i.VFX_VARYING_NORMAL.xyz, i.VFX_VARYING_TANGENT.xyz);
inputData.tangentToWorld = half3x3(i.VFX_VARYING_TANGENT.xyz, bitangent.xyz, signNormal * i.VFX_VARYING_NORMAL.xyz);
#endif
//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
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
float4 unusedShadowmask;
inputData.bakedGI = SAMPLE_GI(0, // No vertex support
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
i.VFX_VARYING_POSCS.xy,
unusedShadowmask,
unusedShadowmask);
#else
inputData.bakedGI = SampleSH(normalWS);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(i.VFX_VARYING_POSCS);
//No static light map in VFX
//inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
return inputData;
}
#ifndef VFX_SHADERGRAPH
float4 GetSurfaceColor(VFX_VARYING_PS_INPUTS i, const VFXUVData uvData)
{
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 = VFXApplySoftParticleFade(i, color);
return color;
}
float3 GetSurfaceEmissive(VFX_VARYING_PS_INPUTS i, const VFXUVData uvData)
{
float3 emission = float3(1, 1, 1);
#if URP_USE_EMISSIVE_MAP
float emissiveScale = 1.0f;
#ifdef VFX_VARYING_EMISSIVESCALE
emissiveScale = i.VFX_VARYING_EMISSIVESCALE;
#endif
emission *= SampleTexture(VFX_SAMPLER(emissiveMap), uvData).rgb * emissiveScale;
#endif
#if defined(VFX_VARYING_EMISSIVE) && (URP_USE_EMISSIVE_COLOR || URP_USE_ADDITIONAL_EMISSIVE_COLOR)
emission *= i.VFX_VARYING_EMISSIVE;
#endif
#ifdef VFX_VARYING_EXPOSUREWEIGHT
emission *= lerp(GetInverseCurrentExposureMultiplier(), 1.0f, i.VFX_VARYING_EXPOSUREWEIGHT);
#endif
return emission;
}
#if VFX_MATERIAL_TYPE_SIX_WAY_SMOKE
SixWaySurfaceData VFXGetSurfaceData(const VFX_VARYING_PS_INPUTS i, float3 normalWS, const VFXUVData uvData)
{
SixWaySurfaceData surfaceData = (SixWaySurfaceData)0;
float4 color = GetSurfaceColor(i, uvData);
surfaceData.absorptionRange = 1.0f;
#ifdef VFX_VARYING_ABSORPTIONRANGE
surfaceData.absorptionRange = i.VFX_VARYING_ABSORPTIONRANGE;
#endif
float4 lightmapPositive = SampleTexture(VFX_SAMPLER(positiveAxesLightmap),uvData);
float4 lightmapNegative = SampleTexture(VFX_SAMPLER(negativeAxesLightmap),uvData);
surfaceData.rightTopBack = lightmapPositive.rgb;
surfaceData.leftBottomFront = lightmapNegative.rgb;
#if VFX_STRIPS_SWAP_UV
SixWaySwapUV(surfaceData.rightTopBack, surfaceData.leftBottomFront);
#endif
float mapAlpha = lightmapPositive.a;
color.a *= mapAlpha;
#if VFX_SIX_WAY_REMAP
#if VFX_BLENDMODE_PREMULTIPLY
surfaceData.rightTopBack /= (mapAlpha + VFX_EPSILON);
surfaceData.leftBottomFront /= (mapAlpha + VFX_EPSILON);
#endif
#if defined(VFX_VARYING_LIGHTMAP_REMAP_RANGES)
float4 remapRanges = i.VFX_VARYING_LIGHTMAP_REMAP_RANGES;
RemapLightMapsRangesFrom(surfaceData.rightTopBack, surfaceData.leftBottomFront, mapAlpha, remapRanges);
#endif
#if defined(VFX_VARYING_LIGHTMAP_REMAP_CONTROLS)
float2 lightmapControls = i.VFX_VARYING_LIGHTMAP_REMAP_CONTROLS;
RemapLightMaps(surfaceData.rightTopBack, surfaceData.leftBottomFront, lightmapControls);
#elif defined(VFX_VARYING_LIGHTMAP_REMAP_CURVE)
float4 remapCurve = i.VFX_VARYING_LIGHTMAP_REMAP_CURVE;
RemapLightMaps(surfaceData.rightTopBack, surfaceData.leftBottomFront, remapCurve);
#endif
#if defined(VFX_VARYING_LIGHTMAP_REMAP_RANGES)
RemapLightMapsRangesTo(surfaceData.rightTopBack, surfaceData.leftBottomFront, mapAlpha, remapRanges);
#endif
#if VFX_BLENDMODE_PREMULTIPLY
surfaceData.rightTopBack *= (mapAlpha + VFX_EPSILON);
surfaceData.leftBottomFront *= (mapAlpha + VFX_EPSILON);
#endif
#endif
float invEnergy = INV_PI;
surfaceData.rightTopBack *= invEnergy;
surfaceData.leftBottomFront *= invEnergy;
#if defined(VFX_VARYING_ALPHA_REMAP)
color.a = SampleCurve(i.VFX_VARYING_ALPHA_REMAP, color.a);
#endif
VFXClipFragmentColor(color.a,i);
#if defined(VFX_VARYING_BAKE_DIFFUSE_LIGHTING)
surfaceData.diffuseGIData0 = i.VFX_VARYING_BAKE_DIFFUSE_LIGHTING[0];
surfaceData.diffuseGIData1 = i.VFX_VARYING_BAKE_DIFFUSE_LIGHTING[1];
surfaceData.diffuseGIData2 = i.VFX_VARYING_BAKE_DIFFUSE_LIGHTING[2];
#endif
#if URP_USE_EMISSIVE
#if defined(VFX_VARYING_EMISSIVE_GRADIENT)
float emissiveChannel = SampleTexture(VFX_SAMPLER(negativeAxesLightmap),uvData).a;
#if defined(VFX_VARYING_EMISSIVE_CHANNEL_SCALE)
emissiveChannel *= i.VFX_VARYING_EMISSIVE_CHANNEL_SCALE;
#endif
surfaceData.emission = SampleGradient(i.VFX_VARYING_EMISSIVE_GRADIENT, emissiveChannel).rgb;
#if defined(VFX_VARYING_EMISSIVE_MULTIPLIER)
surfaceData.emission *= i.VFX_VARYING_EMISSIVE_MULTIPLIER;
#endif
#ifdef VFX_VARYING_EXPOSUREWEIGHT
surfaceData.emission *= lerp(GetInverseCurrentExposureMultiplier(),1.0f,i.VFX_VARYING_EXPOSUREWEIGHT);
#endif
#else
surfaceData.emission = GetSurfaceEmissive(i, uvData);
#endif
surfaceData.emission *= saturate(color.a);
#endif
surfaceData.baseColor.rgb = color.rgb;
surfaceData.alpha = saturate(color.a);
surfaceData.occlusion = 1.0f;
return surfaceData;
}
#else
SurfaceData VFXGetSurfaceData(const VFX_VARYING_PS_INPUTS i, float3 normalWS, const VFXUVData uvData)
{
SurfaceData surfaceData = (SurfaceData)0;
float4 color = GetSurfaceColor(i, uvData);
VFXClipFragmentColor(color.a,i);
surfaceData.albedo = saturate(color.rgb);
#if IS_OPAQUE_PARTICLE
surfaceData.alpha = 1.0f;
#else
surfaceData.alpha = saturate(color.a);
#endif
float4 metallicMapSample = (float4)1.0f;
float4 specularMapSample = (float4)1.0f;
#if URP_WORKFLOW_MODE_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_WORKFLOW_MODE_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 *= SampleTexture(VFX_SAMPLER(baseColorMap),uvData).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 = GetSurfaceEmissive(i, uvData);
#endif
return surfaceData;
}
#endif
#endif

View File

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

View File

@@ -0,0 +1,94 @@
#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)
{
#if VFX_MATERIAL_TYPE_SIX_WAY_SMOKE
float4 color = UniversalFragmentSixWay(inputData, surfaceData);
#else
float4 color = UniversalFragmentPBR(inputData, surfaceData);
#endif
color.rgb = MixFog(color.rgb, inputData.fogCoord);
#if IS_OPAQUE_PARTICLE
bool isTransparent = false;
#else
bool isTransparent = true;
#endif
color.a = OutputAlpha(color.a, isTransparent);
return color;
}
#ifndef VFX_SHADERGRAPH
#if VFX_MATERIAL_TYPE_SIX_WAY_SMOKE
#define SurfaceData SixWaySurfaceData
#endif
float4 VFXGetPixelOutputForward(const VFX_VARYING_PS_INPUTS i, float3 normalWS, const VFXUVData uvData, bool frontFace)
{
SurfaceData surfaceData;
InputData inputData;
VFXGetURPLitData(surfaceData, inputData, i, normalWS, uvData, frontFace, (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, normalWS, true);
return VFXCalcPixelOutputForward(surfaceData, inputData);
}
#endif
#elif (SHADERPASS == SHADERPASS_GBUFFER)
#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, true, (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, normalWS, true);
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:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cebf9c6bb6e199e4db858b1ca6525e5d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fec7a2969fc9f3e428ddfeba3654b66a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,195 @@
#if VISUAL_EFFECT_GRAPH_0_0_1_OR_NEWER
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace UnityEngine.VFX.Utility
{
/// <summary>
/// Camera parameter binding helper class.
/// </summary>
[VFXBinder("URP/URP Camera")]
public class URPCameraBinder : VFXBinderBase
{
/// <summary>
/// Camera URP additional data.
/// </summary>
public UniversalAdditionalCameraData AdditionalData;
Camera m_Camera;
[VFXPropertyBinding("UnityEditor.VFX.CameraType"), SerializeField]
ExposedProperty CameraProperty = "Camera";
ExposedProperty m_Position;
ExposedProperty m_Angles;
ExposedProperty m_Scale;
ExposedProperty m_FieldOfView;
ExposedProperty m_NearPlane;
ExposedProperty m_FarPlane;
ExposedProperty m_AspectRatio;
ExposedProperty m_Dimensions;
ExposedProperty m_ScaledDimensions;
ExposedProperty m_DepthBuffer;
ExposedProperty m_ColorBuffer;
ExposedProperty m_Orthographic;
ExposedProperty m_OrthographicSize;
ExposedProperty m_LensShift;
/// <summary>
/// Set a camera property.
/// </summary>
/// <param name="name">Property name.</param>
public void SetCameraProperty(string name)
{
CameraProperty = name;
UpdateSubProperties();
}
void UpdateSubProperties()
{
// Get Camera component from URP additional data
if (AdditionalData != null)
{
m_Camera = AdditionalData.GetComponent<Camera>();
}
// Update VFX Sub Properties
m_Position = CameraProperty + "_transform_position";
m_Angles = CameraProperty + "_transform_angles";
m_Scale = CameraProperty + "_transform_scale";
m_Orthographic = CameraProperty + "_orthographic";
m_FieldOfView = CameraProperty + "_fieldOfView";
m_NearPlane = CameraProperty + "_nearPlane";
m_FarPlane = CameraProperty + "_farPlane";
m_OrthographicSize = CameraProperty + "_orthographicSize";
m_AspectRatio = CameraProperty + "_aspectRatio";
m_Dimensions = CameraProperty + "_pixelDimensions";
m_LensShift = CameraProperty + "_lensShift";
m_DepthBuffer = CameraProperty + "_depthBuffer";
m_ColorBuffer = CameraProperty + "_colorBuffer";
m_ScaledDimensions = CameraProperty + "_scaledPixelDimensions";
}
static void RequestHistoryAccess(IPerFrameHistoryAccessTracker access)
{
access?.RequestAccess<RawColorHistory>();
access?.RequestAccess<RawDepthHistory>();
}
/// <summary>
/// OnEnable implementation.
/// </summary>
protected override void OnEnable()
{
base.OnEnable();
if (AdditionalData != null)
AdditionalData.history.OnGatherHistoryRequests += RequestHistoryAccess;
UpdateSubProperties();
}
/// <summary>
/// OnDisable implementation.
/// </summary>
protected override void OnDisable()
{
base.OnDisable();
if (AdditionalData != null)
AdditionalData.history.OnGatherHistoryRequests -= RequestHistoryAccess;
}
private void OnValidate()
{
UpdateSubProperties();
if (AdditionalData != null)
AdditionalData.history.OnGatherHistoryRequests += RequestHistoryAccess;
}
/// <summary>
/// Returns true if the Visual Effect and the configuration of the binder are valid to perform the binding.
/// </summary>
/// <param name="component">Component to be tested.</param>
/// <returns>True if the Visual Effect and the configuration of the binder are valid to perform the binding.</returns>
public override bool IsValid(VisualEffect component)
{
return AdditionalData != null
&& m_Camera != null
&& component.HasVector3(m_Position)
&& component.HasVector3(m_Angles)
&& component.HasVector3(m_Scale)
&& component.HasBool(m_Orthographic)
&& component.HasFloat(m_FieldOfView)
&& component.HasFloat(m_NearPlane)
&& component.HasFloat(m_FarPlane)
&& component.HasFloat(m_OrthographicSize)
&& component.HasFloat(m_AspectRatio)
&& component.HasVector2(m_Dimensions)
&& component.HasVector2(m_LensShift)
&& component.HasTexture(m_DepthBuffer)
&& component.HasTexture(m_ColorBuffer)
&& component.HasVector2(m_ScaledDimensions);
}
/// <summary>
/// Update bindings for a visual effect.
/// </summary>
/// <param name="component">Component to update.</param>
public override void UpdateBinding(VisualEffect component)
{
var asset = UniversalRenderPipeline.asset;
if (AdditionalData == null || asset == null)
return;
var targetSpace = component.visualEffectAsset.GetExposedSpace(m_Position);
Matrix4x4 readTransform;
if (targetSpace == VFXSpace.Local)
{
readTransform = component.transform.worldToLocalMatrix * AdditionalData.transform.localToWorldMatrix;
}
else
{
readTransform = AdditionalData.transform.localToWorldMatrix;
}
component.SetVector3(m_Position, readTransform.GetPosition());
component.SetVector3(m_Angles, readTransform.rotation.eulerAngles);
component.SetVector3(m_Scale, readTransform.lossyScale);
component.SetBool(m_Orthographic, m_Camera.orthographic);
component.SetFloat(m_OrthographicSize, m_Camera.orthographicSize);
// While field of View is set in degrees for the camera, it is expected in radians in VFX
component.SetFloat(m_FieldOfView, Mathf.Deg2Rad * m_Camera.fieldOfView);
component.SetFloat(m_NearPlane, m_Camera.nearClipPlane);
component.SetFloat(m_FarPlane, m_Camera.farClipPlane);
component.SetVector2(m_LensShift, m_Camera.lensShift);
component.SetFloat(m_AspectRatio, m_Camera.aspect);
var cameraSize = new Vector2(m_Camera.pixelWidth, m_Camera.pixelHeight);
component.SetVector2(m_Dimensions, cameraSize);
var scaledSize = new Vector2(m_Camera.scaledPixelWidth, m_Camera.scaledPixelHeight) * asset.renderScale;
component.SetVector2(m_ScaledDimensions, scaledSize);
var depth = AdditionalData.history.GetHistoryForRead<RawDepthHistory>()?.GetCurrentTexture();
var color = AdditionalData.history.GetHistoryForRead<RawColorHistory>()?.GetCurrentTexture();
if (depth != null)
component.SetTexture(m_DepthBuffer, depth);
if (color != null)
component.SetTexture(m_ColorBuffer, color);
}
/// <summary>
/// To string implementation.
/// </summary>
/// <returns>String containing the binder information.</returns>
public override string ToString()
{
return string.Format($"URP Camera : '{(AdditionalData == null ? "null" : AdditionalData.gameObject.name)}' -> {CameraProperty}");
}
}
}
#endif

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5c847e0daeb638146931797574071502