This commit is contained in:
StarBeats 2025-08-01 16:36:17 +08:00
parent 532647c7b9
commit e0f03b3e7f
10 changed files with 242 additions and 20 deletions

View File

@ -4862,6 +4862,10 @@ PrefabInstance:
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5777780407979046064, guid: c708a3b79cd542b42bbfedb17e213bc1, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7888303496483045073, guid: c708a3b79cd542b42bbfedb17e213bc1, type: 3}
propertyPath: m_IsActive
value: 0

View File

@ -0,0 +1,138 @@
Shader "Unlit/TestShader"
{
SubShader
{
Pass
{
Cull Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "./test.hlsl"
#pragma multi_compile_local_fragment __ _Red_ON
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag (v2f i) : SV_Target
{
return GetCol();
}
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags
{
"LightMode" = "DepthOnly"
}
// -------------------------------------
// Render State Commands
ZWrite On
ColorMask R
Cull Off
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
// -------------------------------------
// Unity defined keywords
#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
#pragma multi_compile_vertex _ ENABLE_VS_SKINNING
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
ENDHLSL
}
Pass
{
Name "DepthNormals"
Tags
{
"LightMode" = "DepthNormals"
}
// -------------------------------------
// Render State Commands
ZWrite On
Cull Off
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex DepthNormalsVertex
#pragma fragment DepthNormalsFragment
// -------------------------------------
// Material Keywords
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _PARALLAXMAP
#pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
// -------------------------------------
// Unity defined keywords
#pragma multi_compile_fragment _ LOD_FADE_CROSSFADE
// -------------------------------------
// Universal Pipeline keywords
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
#pragma multi_compile_vertex _ ENABLE_VS_SKINNING
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitDepthNormalsPass.hlsl"
ENDHLSL
}
}
}

View File

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

View File

@ -0,0 +1,35 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Unlit_TestShader
m_Shader: {fileID: 4800000, guid: 6cc859748a9d4c740811e9fd3e05c334, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _Red_ON
m_InvalidKeywords:
-
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 2000
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats: []
m_Colors: []
m_BuildTextureStacks: []

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b1767071aeb17c44591105092b5c2e68
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
#ifndef UNITY_TEST_INCLUDED
#define UNITY_TEST_INCLUDED
half4 GetCol()
{
#if _Red_ON
return half4(1,0,0,1);
#else
return half4(0,0,0,1);
#endif
}
#endif

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3cc7817acce74f94b83ee7d9e35e0a5a
timeCreated: 1754031989

View File

@ -142,10 +142,10 @@ MonoBehaviour:
m_Active: 1
settings:
RenderPassEvent: 450
AmbientIntensity: 1.63
ShadowIntensity: 0
ShadowSharpness: 0
ConeAngle: 8.1
AmbientIntensity: 1.44
ShadowIntensity: 0.2
ShadowSharpness: 0.9
ConeAngle: 16.21
CapsuleAOMat: {fileID: 2100000, guid: c90d40f0d9828744b916dbed0eed9db6, type: 2}
--- !u!114 &-5418649131825517062
MonoBehaviour:

View File

@ -42,7 +42,6 @@ namespace X.Rendering.Feature
CapsuleAOPass capsuleAOPass;
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
if (renderingData.cameraData.cameraType == CameraType.Game)
{
renderer.EnqueuePass(capsuleAOPass);
}

View File

@ -158,15 +158,30 @@ Shader "XRP/CapsuleAO"
// 地面点 p 到 ab 最近点 x, 向量 xp = d
float3 d = pa - h * ba;
float l = length(d);
float o = 1.0 - max(0.0, dot(-d, n)) * r * r / (l * l * l);
float nl = dot(-d, n);
float o = 1.0 - max(0.0, nl) * r * r / (l * l * l);
// multiplier o *= 1.0 + r*(l-r)/(l*l);
o = sqrt(o * o * o);
ao *= o;
}
ao = saturate(lerp(1, ao, intensity));
return clamp(lerp(1, ao, _AmbientIntensity), 0.6, 1);
}
float CalcSphereOcclusion2(in float3 pos, in float3 nor, in float4 sph)
{
float3 di = sph.xyz - pos;
float l = length(di);
float rad = sph.w;
float nl = max(0.0, dot(nor, di / l));
return (1.0 - nl * rad * rad / (l * l ));
// float3 di = (sph.xyz - pos) / sph.w;
// float sqL = dot(di, di);
// return clamp(1.0 - dot(nor, di) * rsqrt(sqL * sqL * sqL), 0.1, 1);
}
// Sphere occlusion
float CalcSphereOcclusion( in float3 pos, in float3 nor, in float4 sph )
{
@ -174,10 +189,11 @@ Shader "XRP/CapsuleAO"
float l = length(di);
float nl = (dot(nor,di/l));
float rad = sph.w;
float v = 1 - rad - nl;
if(l < 0.55)
return abs((1 - rad - nl));// + _ShadowSharpness;
// float v = 1-nl-rad;
// if(l < 0.95 && v < _ShadowSharpness)
// {
// return abs(v);
// }
float h = l < rad ? 1.0 : l / rad;
@ -203,7 +219,7 @@ Shader "XRP/CapsuleAO"
#endif
}
return clamp(1.0 - res, 0.6, 1);
return 1.0 - res;
}
float CalcCapsuleOcclusionByIndexV2(float3 p, float3 n, uint s, uint e, float4 cone, float intensity)
@ -211,16 +227,15 @@ Shader "XRP/CapsuleAO"
float ao = 1.0;
for (uint i = s; i < e; ++i)
{
Capsule capsule = _CapsuleData[i + int(_ShadowIntensity)];
Capsule capsule = _CapsuleData[i];
float3 ba = capsule.b - capsule.a;
float3 pa = p - capsule.a;
float l = dot(ba, ba);
// p 在 ba 上投影长度与 ba 长度比值
float t = /* abs(l) < 1e-8f ? 0.0 : */ saturate(dot(pa, ba) / l);
float3 positionToRay = capsule.a + t * ba;
ao = min(ao, CalcSphereOcclusion(p, n, float4(positionToRay, capsule.radius)));
ao *= CalcSphereOcclusion2(p, n, float4(positionToRay, capsule.radius));
}
return ao;
ao = saturate(lerp(1, ao, intensity));
return saturate(lerp(1, ao, _AmbientIntensity));
}
@ -369,14 +384,14 @@ Shader "XRP/CapsuleAO"
{
float intensity = 1;
Character c = _CharacterData[i];
// if (IsInBounds(worldPos, c.position, c.radius*10, intensity))
if (IsInBounds(worldPos, c.position, c.radius*2, intensity))
{
float tempIntensity = intensity / saturate(1 * smoothstep(0.1, 2, c.lightDir.w));
// float tempShadow = CalcCapsuleShadowByIndex(worldPos, _MainLightPosition.xyz, c.startID, c.endID, _ShadowSharpness, tempIntensity);
// float tempShadow = CalcCapsuleShadowByIndexV2(worldPos, cone, c.startID, c.endID, _ShadowSharpness, tempIntensity);
// //float tempShadow = CalcCapsuleShadowByIndexV2(worldPos, cone, c.startID, c.endID, _ShadowSharpness, tempIntensity);
// shadow = min(shadow, tempShadow);
// occlusion *= CalcCapsuleOcclusionByIndex(worldPos, worldNormal, c.startID, c.endID, intensity);
occlusion *= CalcCapsuleOcclusionByIndexV2(worldPos, worldNormal, c.startID, c.endID,cone, intensity);
//occlusion *= CalcCapsuleOcclusionByIndex(worldPos, worldNormal, c.startID, c.endID, intensity);
occlusion *= CalcCapsuleOcclusionByIndexV2(worldPos, worldNormal, c.startID, c.endID,cone, intensity);
}
}
return shadow * occlusion;