add : unabomber scene
This commit is contained in:
@@ -0,0 +1,303 @@
|
||||
// Local URP 17.3 LitInput extension: keep all material properties in the same unconditional UnityPerMaterial buffer across every pass.
|
||||
#ifndef UNIVERSAL_LIT_INPUT_INCLUDED
|
||||
#define UNIVERSAL_LIT_INPUT_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ParallaxMapping.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
||||
|
||||
#if defined(_DETAIL_MULX2) || defined(_DETAIL_SCALED)
|
||||
#define _DETAIL
|
||||
#endif
|
||||
|
||||
// NOTE: Do not ifdef the properties here as SRP batcher can not handle different layouts.
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _BaseMap_ST;
|
||||
float4 _BaseMap_TexelSize;
|
||||
float4 _DetailAlbedoMap_ST;
|
||||
half4 _BaseColor;
|
||||
half4 _SpecColor;
|
||||
half4 _EmissionColor;
|
||||
half _Cutoff;
|
||||
half _Smoothness;
|
||||
half _Metallic;
|
||||
half _BumpScale;
|
||||
half _Parallax;
|
||||
half _OcclusionStrength;
|
||||
half _ClearCoatMask;
|
||||
half _ClearCoatSmoothness;
|
||||
half _DetailAlbedoMapScale;
|
||||
half _DetailNormalMapScale;
|
||||
half _Surface;
|
||||
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
||||
// Shared by every server pass, including DOTS/GPU Resident Drawer variants.
|
||||
float _Curvature;
|
||||
float _StartDistance;
|
||||
float _HorizontalInfluence;
|
||||
float _BendAngle;
|
||||
float4 _MeadowRegion;
|
||||
float4 _MeadowEdgeColor;
|
||||
float _MeadowEdgeFade;
|
||||
float4x4 _MeadowWorldToLocal;
|
||||
float _MaskID;
|
||||
CBUFFER_END
|
||||
|
||||
// NOTE: Do not ifdef the properties for dots instancing, but ifdef the actual usage.
|
||||
// Otherwise you might break CPU-side as property constant-buffer offsets change per variant.
|
||||
// NOTE: Dots instancing is orthogonal to the constant buffer above.
|
||||
#ifdef UNITY_DOTS_INSTANCING_ENABLED
|
||||
|
||||
UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
|
||||
UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor)
|
||||
UNITY_DOTS_INSTANCED_PROP(float4, _SpecColor)
|
||||
UNITY_DOTS_INSTANCED_PROP(float4, _EmissionColor)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _Cutoff)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _Smoothness)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _Metallic)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _BumpScale)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _Parallax)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _OcclusionStrength)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _ClearCoatMask)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _ClearCoatSmoothness)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _DetailAlbedoMapScale)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _DetailNormalMapScale)
|
||||
UNITY_DOTS_INSTANCED_PROP(float , _Surface)
|
||||
UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
|
||||
|
||||
// Here, we want to avoid overriding a property like e.g. _BaseColor with something like this:
|
||||
// #define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _BaseColor0)
|
||||
//
|
||||
// It would be simpler, but it can cause the compiler to regenerate the property loading code for each use of _BaseColor.
|
||||
//
|
||||
// To avoid this, the property loads are cached in some static values at the beginning of the shader.
|
||||
// The properties such as _BaseColor are then overridden so that it expand directly to the static value like this:
|
||||
// #define _BaseColor unity_DOTS_Sampled_BaseColor
|
||||
//
|
||||
// This simple fix happened to improve GPU performances by ~10% on Meta Quest 2 with URP on some scenes.
|
||||
static float4 unity_DOTS_Sampled_BaseColor;
|
||||
static float4 unity_DOTS_Sampled_SpecColor;
|
||||
static float4 unity_DOTS_Sampled_EmissionColor;
|
||||
static float unity_DOTS_Sampled_Cutoff;
|
||||
static float unity_DOTS_Sampled_Smoothness;
|
||||
static float unity_DOTS_Sampled_Metallic;
|
||||
static float unity_DOTS_Sampled_BumpScale;
|
||||
static float unity_DOTS_Sampled_Parallax;
|
||||
static float unity_DOTS_Sampled_OcclusionStrength;
|
||||
static float unity_DOTS_Sampled_ClearCoatMask;
|
||||
static float unity_DOTS_Sampled_ClearCoatSmoothness;
|
||||
static float unity_DOTS_Sampled_DetailAlbedoMapScale;
|
||||
static float unity_DOTS_Sampled_DetailNormalMapScale;
|
||||
static float unity_DOTS_Sampled_Surface;
|
||||
|
||||
void SetupDOTSLitMaterialPropertyCaches()
|
||||
{
|
||||
unity_DOTS_Sampled_BaseColor = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _BaseColor);
|
||||
unity_DOTS_Sampled_SpecColor = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _SpecColor);
|
||||
unity_DOTS_Sampled_EmissionColor = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _EmissionColor);
|
||||
unity_DOTS_Sampled_Cutoff = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Cutoff);
|
||||
unity_DOTS_Sampled_Smoothness = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Smoothness);
|
||||
unity_DOTS_Sampled_Metallic = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Metallic);
|
||||
unity_DOTS_Sampled_BumpScale = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _BumpScale);
|
||||
unity_DOTS_Sampled_Parallax = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Parallax);
|
||||
unity_DOTS_Sampled_OcclusionStrength = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _OcclusionStrength);
|
||||
unity_DOTS_Sampled_ClearCoatMask = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _ClearCoatMask);
|
||||
unity_DOTS_Sampled_ClearCoatSmoothness = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _ClearCoatSmoothness);
|
||||
unity_DOTS_Sampled_DetailAlbedoMapScale = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _DetailAlbedoMapScale);
|
||||
unity_DOTS_Sampled_DetailNormalMapScale = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _DetailNormalMapScale);
|
||||
unity_DOTS_Sampled_Surface = UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float , _Surface);
|
||||
}
|
||||
|
||||
#undef UNITY_SETUP_DOTS_MATERIAL_PROPERTY_CACHES
|
||||
#define UNITY_SETUP_DOTS_MATERIAL_PROPERTY_CACHES() SetupDOTSLitMaterialPropertyCaches()
|
||||
|
||||
#define _BaseColor unity_DOTS_Sampled_BaseColor
|
||||
#define _SpecColor unity_DOTS_Sampled_SpecColor
|
||||
#define _EmissionColor unity_DOTS_Sampled_EmissionColor
|
||||
#define _Cutoff unity_DOTS_Sampled_Cutoff
|
||||
#define _Smoothness unity_DOTS_Sampled_Smoothness
|
||||
#define _Metallic unity_DOTS_Sampled_Metallic
|
||||
#define _BumpScale unity_DOTS_Sampled_BumpScale
|
||||
#define _Parallax unity_DOTS_Sampled_Parallax
|
||||
#define _OcclusionStrength unity_DOTS_Sampled_OcclusionStrength
|
||||
#define _ClearCoatMask unity_DOTS_Sampled_ClearCoatMask
|
||||
#define _ClearCoatSmoothness unity_DOTS_Sampled_ClearCoatSmoothness
|
||||
#define _DetailAlbedoMapScale unity_DOTS_Sampled_DetailAlbedoMapScale
|
||||
#define _DetailNormalMapScale unity_DOTS_Sampled_DetailNormalMapScale
|
||||
#define _Surface unity_DOTS_Sampled_Surface
|
||||
|
||||
#endif
|
||||
|
||||
TEXTURE2D(_ParallaxMap); SAMPLER(sampler_ParallaxMap);
|
||||
TEXTURE2D(_OcclusionMap); SAMPLER(sampler_OcclusionMap);
|
||||
TEXTURE2D(_DetailMask); SAMPLER(sampler_DetailMask);
|
||||
TEXTURE2D(_DetailAlbedoMap); SAMPLER(sampler_DetailAlbedoMap);
|
||||
TEXTURE2D(_DetailNormalMap); SAMPLER(sampler_DetailNormalMap);
|
||||
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap);
|
||||
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap);
|
||||
TEXTURE2D(_ClearCoatMap); SAMPLER(sampler_ClearCoatMap);
|
||||
|
||||
#ifdef _SPECULAR_SETUP
|
||||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_SpecGlossMap, sampler_SpecGlossMap, uv)
|
||||
#else
|
||||
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_MetallicGlossMap, sampler_MetallicGlossMap, uv)
|
||||
#endif
|
||||
|
||||
half4 SampleMetallicSpecGloss(float2 uv, half albedoAlpha)
|
||||
{
|
||||
half4 specGloss;
|
||||
|
||||
#ifdef _METALLICSPECGLOSSMAP
|
||||
specGloss = half4(SAMPLE_METALLICSPECULAR(uv));
|
||||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
||||
specGloss.a = albedoAlpha * _Smoothness;
|
||||
#else
|
||||
specGloss.a *= _Smoothness;
|
||||
#endif
|
||||
#else // _METALLICSPECGLOSSMAP
|
||||
#if _SPECULAR_SETUP
|
||||
specGloss.rgb = _SpecColor.rgb;
|
||||
#else
|
||||
specGloss.rgb = _Metallic.rrr;
|
||||
#endif
|
||||
|
||||
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
||||
specGloss.a = albedoAlpha * _Smoothness;
|
||||
#else
|
||||
specGloss.a = _Smoothness;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return specGloss;
|
||||
}
|
||||
|
||||
half SampleOcclusion(float2 uv)
|
||||
{
|
||||
#ifdef _OCCLUSIONMAP
|
||||
half occ = SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g;
|
||||
return LerpWhiteTo(occ, _OcclusionStrength);
|
||||
#else
|
||||
return half(1.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Returns clear coat parameters
|
||||
// .x/.r == mask
|
||||
// .y/.g == smoothness
|
||||
half2 SampleClearCoat(float2 uv)
|
||||
{
|
||||
#if defined(_CLEARCOAT) || defined(_CLEARCOATMAP)
|
||||
half2 clearCoatMaskSmoothness = half2(_ClearCoatMask, _ClearCoatSmoothness);
|
||||
|
||||
#if defined(_CLEARCOATMAP)
|
||||
clearCoatMaskSmoothness *= SAMPLE_TEXTURE2D(_ClearCoatMap, sampler_ClearCoatMap, uv).rg;
|
||||
#endif
|
||||
|
||||
return clearCoatMaskSmoothness;
|
||||
#else
|
||||
return half2(0.0, 1.0);
|
||||
#endif // _CLEARCOAT
|
||||
}
|
||||
|
||||
void ApplyPerPixelDisplacement(half3 viewDirTS, inout float2 uv)
|
||||
{
|
||||
#if defined(_PARALLAXMAP)
|
||||
uv += ParallaxMapping(TEXTURE2D_ARGS(_ParallaxMap, sampler_ParallaxMap), viewDirTS, _Parallax, uv);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Used for scaling detail albedo. Main features:
|
||||
// - Depending if detailAlbedo brightens or darkens, scale magnifies effect.
|
||||
// - No effect is applied if detailAlbedo is 0.5.
|
||||
half3 ScaleDetailAlbedo(half3 detailAlbedo, half scale)
|
||||
{
|
||||
// detailAlbedo = detailAlbedo * 2.0h - 1.0h;
|
||||
// detailAlbedo *= _DetailAlbedoMapScale;
|
||||
// detailAlbedo = detailAlbedo * 0.5h + 0.5h;
|
||||
// return detailAlbedo * 2.0f;
|
||||
|
||||
// A bit more optimized
|
||||
return half(2.0) * detailAlbedo * scale - scale + half(1.0);
|
||||
}
|
||||
|
||||
half3 ApplyDetailAlbedo(float2 detailUv, half3 albedo, half detailMask)
|
||||
{
|
||||
#if defined(_DETAIL)
|
||||
half3 detailAlbedo = SAMPLE_TEXTURE2D(_DetailAlbedoMap, sampler_DetailAlbedoMap, detailUv).rgb;
|
||||
|
||||
// In order to have same performance as builtin, we do scaling only if scale is not 1.0 (Scaled version has 6 additional instructions)
|
||||
#if defined(_DETAIL_SCALED)
|
||||
detailAlbedo = ScaleDetailAlbedo(detailAlbedo, _DetailAlbedoMapScale);
|
||||
#else
|
||||
detailAlbedo = half(2.0) * detailAlbedo;
|
||||
#endif
|
||||
|
||||
return albedo * LerpWhiteTo(detailAlbedo, detailMask);
|
||||
#else
|
||||
return albedo;
|
||||
#endif
|
||||
}
|
||||
|
||||
half3 ApplyDetailNormal(float2 detailUv, half3 normalTS, half detailMask)
|
||||
{
|
||||
#if defined(_DETAIL)
|
||||
#if BUMP_SCALE_NOT_SUPPORTED
|
||||
half3 detailNormalTS = UnpackNormal(SAMPLE_TEXTURE2D(_DetailNormalMap, sampler_DetailNormalMap, detailUv));
|
||||
#else
|
||||
half3 detailNormalTS = UnpackNormalScale(SAMPLE_TEXTURE2D(_DetailNormalMap, sampler_DetailNormalMap, detailUv), _DetailNormalMapScale);
|
||||
#endif
|
||||
|
||||
// With UNITY_NO_DXT5nm unpacked vector is not normalized for BlendNormalRNM
|
||||
// For visual consistancy we going to do in all cases
|
||||
detailNormalTS = normalize(detailNormalTS);
|
||||
|
||||
return lerp(normalTS, BlendNormalRNM(normalTS, detailNormalTS), detailMask); // todo: detailMask should lerp the angle of the quaternion rotation, not the normals
|
||||
#else
|
||||
return normalTS;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
|
||||
{
|
||||
half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
|
||||
outSurfaceData.alpha = Alpha(albedoAlpha.a, _BaseColor, _Cutoff);
|
||||
|
||||
half4 specGloss = SampleMetallicSpecGloss(uv, albedoAlpha.a);
|
||||
outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
|
||||
outSurfaceData.albedo = AlphaModulate(outSurfaceData.albedo, outSurfaceData.alpha);
|
||||
|
||||
#if _SPECULAR_SETUP
|
||||
outSurfaceData.metallic = half(1.0);
|
||||
outSurfaceData.specular = specGloss.rgb;
|
||||
#else
|
||||
outSurfaceData.metallic = specGloss.r;
|
||||
outSurfaceData.specular = half3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
|
||||
outSurfaceData.smoothness = specGloss.a;
|
||||
outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
|
||||
outSurfaceData.occlusion = SampleOcclusion(uv);
|
||||
outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap));
|
||||
|
||||
#if defined(_CLEARCOAT) || defined(_CLEARCOATMAP)
|
||||
half2 clearCoat = SampleClearCoat(uv);
|
||||
outSurfaceData.clearCoatMask = clearCoat.r;
|
||||
outSurfaceData.clearCoatSmoothness = clearCoat.g;
|
||||
#else
|
||||
outSurfaceData.clearCoatMask = half(0.0);
|
||||
outSurfaceData.clearCoatSmoothness = half(0.0);
|
||||
#endif
|
||||
|
||||
#if defined(_DETAIL)
|
||||
half detailMask = SAMPLE_TEXTURE2D(_DetailMask, sampler_DetailMask, uv).a;
|
||||
float2 detailUv = uv * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
|
||||
outSurfaceData.albedo = ApplyDetailAlbedo(detailUv, outSurfaceData.albedo, detailMask);
|
||||
outSurfaceData.normalTS = ApplyDetailNormal(detailUv, outSurfaceData.normalTS, detailMask);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // UNIVERSAL_INPUT_SURFACE_PBR_INCLUDED
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56cb9e4ad60a490c915b3b29e855a15b
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef CURVED_SERVER_VERTEX_INCLUDED
|
||||
#define CURVED_SERVER_VERTEX_INCLUDED
|
||||
#include "CurvedWorld.hlsl"
|
||||
#include "PortalMeadowRegion.hlsl"
|
||||
#include "Assets/_Content/Shaders/EnkiBilal/Include/Mask.hlsl"
|
||||
|
||||
// Parameters are declared in CurvedServerLitInput.hlsl's UnityPerMaterial cbuffer.
|
||||
// Portal masks are global matrices written by PortalManager.
|
||||
float4x4 _Mask0, _Mask1, _Mask2;
|
||||
|
||||
void ClipServerRegion(float4 positionCS)
|
||||
{
|
||||
float depth = positionCS.z;
|
||||
#if !UNITY_REVERSED_Z
|
||||
depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, depth);
|
||||
#endif
|
||||
float3 bentWS = ComputeWorldSpacePosition(GetNormalizedScreenSpaceUV(positionCS), depth, UNITY_MATRIX_I_VP);
|
||||
// The mask is a camera projection, so it uses the displayed (bent) position.
|
||||
float maskAlpha;
|
||||
Mask_float(bentWS, _MaskID, _Mask0, _Mask1, _Mask2, maskAlpha);
|
||||
clip(maskAlpha - 0.5);
|
||||
if (_MeadowRegion.w <= 0) return;
|
||||
float3 view = CurvedWorldToFrame(bentWS);
|
||||
float s, c;
|
||||
sincos(radians(_BendAngle), s, c);
|
||||
// This bend is a shear: depth and the perpendicular lateral axis stay unchanged.
|
||||
float lateral = dot(view.xy, float2(c, s));
|
||||
float distance = max(0, -view.z - _StartDistance);
|
||||
view.xy -= float2(s, -c) * (distance * distance + lateral * lateral * _HorizontalInfluence) * _Curvature;
|
||||
float3 originalWS = CurvedFrameToWorld(view);
|
||||
ClipMeadowRegion(originalWS, positionCS.xy);
|
||||
}
|
||||
|
||||
void BendServerFrame(inout float3 positionOS, inout float3 normalOS, inout float4 tangentOS)
|
||||
{
|
||||
float3 positionVS = CurvedWorldToFrame(TransformObjectToWorld(positionOS));
|
||||
float3 normalVS = CurvedWorldDirToFrame(TransformObjectToWorldNormal(normalOS));
|
||||
normalVS = CurvedWorldNormalVS(positionVS, normalVS, _Curvature,
|
||||
_StartDistance, _HorizontalInfluence, _BendAngle);
|
||||
normalOS = TransformWorldToObjectNormal(CurvedFrameDirToWorld(normalVS));
|
||||
|
||||
// Deform the tangent with the Jacobian to preserve the server's normal map.
|
||||
float s, c;
|
||||
sincos(radians(_BendAngle), s, c);
|
||||
float lateral = dot(positionVS.xy, float2(c, s));
|
||||
float3 gradient = 2 * _Curvature * float3(_HorizontalInfluence * lateral * float2(c, s),
|
||||
-max(0.0, -positionVS.z - _StartDistance));
|
||||
float3 tangentVS = CurvedWorldDirToFrame(TransformObjectToWorldDir(tangentOS.xyz));
|
||||
tangentVS += float3(s, -c, 0) * dot(gradient, tangentVS);
|
||||
tangentOS.xyz = TransformWorldToObjectDir(CurvedFrameDirToWorld(tangentVS));
|
||||
CurvedWorld_float(positionOS, _Curvature, _StartDistance, _HorizontalInfluence, _BendAngle, positionOS);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f6e3d5e375c4eac8f2c8141d65b037b
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef CURVED_WORLD_INCLUDED
|
||||
#define CURVED_WORLD_INCLUDED
|
||||
|
||||
// Bend frame: the camera view by default. PortalMeadow can pin it to a fixed world-space frame
|
||||
// (e.g. a portal) so the bend stays still while the world is only seen through that portal.
|
||||
float4x4 _CurvedWorldFrame, _CurvedWorldFrameInv;
|
||||
float _CurvedWorldFrameFixed;
|
||||
|
||||
float3 CurvedWorldToFrame(float3 positionWS)
|
||||
{
|
||||
return _CurvedWorldFrameFixed > 0.5 ? mul(_CurvedWorldFrame, float4(positionWS, 1)).xyz : TransformWorldToView(positionWS);
|
||||
}
|
||||
float3 CurvedFrameToWorld(float3 positionFS)
|
||||
{
|
||||
return mul(_CurvedWorldFrameFixed > 0.5 ? _CurvedWorldFrameInv : UNITY_MATRIX_I_V, float4(positionFS, 1)).xyz;
|
||||
}
|
||||
float3 CurvedWorldDirToFrame(float3 directionWS)
|
||||
{
|
||||
return mul((float3x3)(_CurvedWorldFrameFixed > 0.5 ? _CurvedWorldFrame : UNITY_MATRIX_V), directionWS);
|
||||
}
|
||||
float3 CurvedFrameDirToWorld(float3 directionFS)
|
||||
{
|
||||
return mul((float3x3)(_CurvedWorldFrameFixed > 0.5 ? _CurvedWorldFrameInv : UNITY_MATRIX_I_V), directionFS);
|
||||
}
|
||||
|
||||
// Shared by the ground and the grass; also usable as a Shader Graph custom function.
|
||||
void CurvedWorld_float(float3 PositionOS, float Curvature, float StartDistance,
|
||||
float HorizontalInfluence, float BendAngle, out float3 Out)
|
||||
{
|
||||
#ifdef SHADERGRAPH_PREVIEW
|
||||
Out = PositionOS;
|
||||
#else
|
||||
float3 positionVS = CurvedWorldToFrame(TransformObjectToWorld(PositionOS));
|
||||
// Rotate the bend frame around the camera's forward axis (degrees).
|
||||
// 0 = down, 90 = right, 180 = up, 270 = left.
|
||||
float s, c;
|
||||
sincos(radians(BendAngle), s, c);
|
||||
float lateral = dot(positionVS.xy, float2(c, s));
|
||||
float distanceFromCamera = max(0.0, -positionVS.z - StartDistance);
|
||||
float bend = (distanceFromCamera * distanceFromCamera
|
||||
+ lateral * lateral * HorizontalInfluence) * Curvature;
|
||||
positionVS.xy += float2(s, -c) * bend;
|
||||
Out = TransformWorldToObject(CurvedFrameToWorld(positionVS));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Preserve existing Shader Graph custom functions using the original signature.
|
||||
void CurvedWorld_float(float3 PositionOS, float Curvature, float StartDistance,
|
||||
float HorizontalInfluence, out float3 Out)
|
||||
{
|
||||
CurvedWorld_float(PositionOS, Curvature, StartDistance, HorizontalInfluence, 0, Out);
|
||||
}
|
||||
|
||||
float3 CurvedWorldNormalVS(float3 positionVS, float3 normalVS, float Curvature,
|
||||
float StartDistance, float HorizontalInfluence, float BendAngle)
|
||||
{
|
||||
float s, c;
|
||||
sincos(radians(BendAngle), s, c);
|
||||
float lateral = dot(positionVS.xy, float2(c, s));
|
||||
float3 gradient = 2 * Curvature * float3(HorizontalInfluence * lateral * float2(c, s),
|
||||
-max(0.0, -positionVS.z - StartDistance));
|
||||
// Inverse transpose of the bend Jacobian; the gradient is perpendicular to its direction.
|
||||
return normalVS - gradient * dot(float2(s, -c), normalVS.xy);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 323e136332b04410aaac77b2b92b8966
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef PORTAL_MEADOW_REGION_INCLUDED
|
||||
#define PORTAL_MEADOW_REGION_INCLUDED
|
||||
// Uniforms are supplied by each shader's UnityPerMaterial buffer.
|
||||
float MeadowRegionFade(float3 originalWS)
|
||||
{
|
||||
if (_MeadowRegion.w <= 0) return 1;
|
||||
float3 local = mul(_MeadowWorldToLocal, float4(originalWS, 1)).xyz;
|
||||
float distanceToEdge = _MeadowRegion.w - length(local.xz - _MeadowRegion.xz);
|
||||
clip(distanceToEdge);
|
||||
return saturate(distanceToEdge / max(_MeadowEdgeFade, 0.001));
|
||||
}
|
||||
float ClipMeadowRegion(float3 originalWS, float2 pixel)
|
||||
{
|
||||
float fade = MeadowRegionFade(originalWS);
|
||||
float threshold = frac(52.9829189 * frac(dot(floor(pixel), float2(0.06711056, 0.00583715))));
|
||||
clip(fade - threshold);
|
||||
return fade;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb3e643eb7b5481dbb5c97aad043eea4
|
||||
Reference in New Issue
Block a user