opti : shaders rework test
This commit is contained in:
@@ -1,31 +1,68 @@
|
||||
#ifndef ENKI_BILAL_INCLUDED
|
||||
#define ENKI_BILAL_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
/*
|
||||
ENKI BILLAL - MEDIUM VERSION WITH SECOND DETAIL LAYER
|
||||
|
||||
Goal:
|
||||
Keep the optimized stylized render while allowing DetailTexB to be tested again.
|
||||
|
||||
Changes from the original version:
|
||||
- Removed custom shadow sampling.
|
||||
In the original shader, shadowAtten was calculated but never used.
|
||||
This was pure GPU overhead.
|
||||
- Removed Lighting.hlsl include.
|
||||
GetMainLight / GetAdditionalLight are no longer used here.
|
||||
- Uses the optimized SampleProjectedDetailLOD from Details.hlsl.
|
||||
- DetailTexA is active when DetailIntensityA > 0.
|
||||
- DetailTexB is active when DetailIntensityB > 0.
|
||||
- Both details are limited by camera distance.
|
||||
- World/Object conversions are computed only once if at least one detail layer is used.
|
||||
- Simple fog is preserved.
|
||||
|
||||
Cost with the new Details.hlsl:
|
||||
- DetailTexA only: 6 texture samples.
|
||||
- DetailTexA + DetailTexB: 12 texture samples.
|
||||
|
||||
This is still much cheaper than the original setup.
|
||||
*/
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Assets/_Content/Shaders/Include/Noises.hlsl"
|
||||
#include "Assets/_Content/Shaders/Include/Details.hlsl"
|
||||
#include "Assets/_Content/Shaders/Include/Utilities.hlsl"
|
||||
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/AmbientOcclusion.hlsl"
|
||||
|
||||
/*
|
||||
Maximum distance for projected details.
|
||||
|
||||
Lower value = better GPU performance.
|
||||
Higher value = details visible farther from the camera.
|
||||
|
||||
Recommended range:
|
||||
- 12 to 18 for dense scenes.
|
||||
- 25 to 30 if details disappear too aggressively in depth.
|
||||
*/
|
||||
#define ENKI_DETAIL_MAX_DISTANCE 18.0
|
||||
|
||||
/*
|
||||
Fade range used to avoid a hard cutoff.
|
||||
|
||||
Detail starts fading at:
|
||||
ENKI_DETAIL_MAX_DISTANCE - ENKI_DETAIL_FADE_DISTANCE.
|
||||
*/
|
||||
#define ENKI_DETAIL_FADE_DISTANCE 4.0
|
||||
|
||||
/*
|
||||
Safety stub.
|
||||
|
||||
If another include or older graph version still calls GetShadow,
|
||||
the shader will compile and return "no custom shadow".
|
||||
|
||||
In this Medium version, custom shadow sampling is intentionally disabled.
|
||||
*/
|
||||
float GetShadow(float3 PositionWS)
|
||||
{
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(PositionWS);
|
||||
Light mainLight = GetMainLight(shadowCoord);
|
||||
|
||||
float shadow = 1 - mainLight.shadowAttenuation;
|
||||
|
||||
#if defined(_ADDITIONAL_LIGHTS)
|
||||
uint lightsCount = GetAdditionalLightsCount();
|
||||
|
||||
[loop]
|
||||
for (uint i = 0; i < lightsCount; i++)
|
||||
{
|
||||
Light light = GetAdditionalLight(i, PositionWS);
|
||||
shadow = max(shadow, 1 - light.shadowAttenuation);
|
||||
}
|
||||
#endif
|
||||
|
||||
return saturate(shadow);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void EnkiBillal_float
|
||||
@@ -49,64 +86,99 @@ void EnkiBillal_float
|
||||
out float Alpha
|
||||
)
|
||||
{
|
||||
// Common
|
||||
float depth = length(PositionWS - _WorldSpaceCameraPos.xyz);
|
||||
|
||||
float3 pivotWS = TransformObjectToWorld(float3(0, 0, 0));
|
||||
|
||||
float3 scale = GetScale(pivotWS);
|
||||
|
||||
float3 positionOS = TransformWorldToObject(PositionWS) * scale;
|
||||
float3 normalOS = normalize(TransformWorldToObjectDir(NormalWS));
|
||||
|
||||
//float ao = GetScreenSpaceAmbientOcclusion(ScreenUV).directAmbientOcclusion;
|
||||
|
||||
// Shadow
|
||||
|
||||
float shadow = GetShadow(PositionWS);
|
||||
float shadowAtten = Remap(1, 0, .6, 1, shadow);
|
||||
|
||||
// Detail
|
||||
|
||||
float4 detailA = SampleProjectedDetailLOD
|
||||
(
|
||||
DetailTexA,
|
||||
positionOS,
|
||||
normalOS,
|
||||
ProjectionsBlend,
|
||||
DetailSizeA,
|
||||
depth
|
||||
|
||||
);
|
||||
|
||||
float4 detailB = SampleProjectedDetailLOD
|
||||
(
|
||||
DetailTexB,
|
||||
positionOS,
|
||||
normalOS,
|
||||
ProjectionsBlend,
|
||||
DetailSizeB,
|
||||
depth
|
||||
|
||||
);
|
||||
|
||||
float detailMaskA = smoothstep(0, .8, detailA.a);
|
||||
float detailMaskB = smoothstep(0, .8, detailB.a);
|
||||
|
||||
// Fog
|
||||
|
||||
// Output
|
||||
|
||||
/*
|
||||
Base output.
|
||||
If no extra effect is applied, this function remains very cheap.
|
||||
*/
|
||||
Output = Color.rgb;
|
||||
Output = lerp(Output.rgb, detailA.rgb, detailMaskA * DetailIntensityA);
|
||||
Output = lerp(Output.rgb, detailB.rgb, detailMaskB * DetailIntensityB);
|
||||
|
||||
Alpha = Color.a;
|
||||
|
||||
/*
|
||||
Camera-to-fragment distance.
|
||||
Used for projected detail distance limiting and optional fog.
|
||||
*/
|
||||
float depth = length(PositionWS - _WorldSpaceCameraPos.xyz);
|
||||
|
||||
/*
|
||||
Distance fade for projected details.
|
||||
|
||||
detailFade is:
|
||||
- 1 near the camera.
|
||||
- 0 beyond ENKI_DETAIL_MAX_DISTANCE.
|
||||
*/
|
||||
float detailFadeStart = ENKI_DETAIL_MAX_DISTANCE - ENKI_DETAIL_FADE_DISTANCE;
|
||||
float detailFade = 1.0 - smoothstep(detailFadeStart, ENKI_DETAIL_MAX_DISTANCE, depth);
|
||||
|
||||
float detailWeightA = DetailIntensityA * detailFade;
|
||||
float detailWeightB = DetailIntensityB * detailFade;
|
||||
|
||||
/*
|
||||
Only compute object-space data if at least one detail layer is actually used.
|
||||
*/
|
||||
if (detailWeightA > 0.001 || detailWeightB > 0.001)
|
||||
{
|
||||
float3 pivotWS = TransformObjectToWorld(float3(0.0, 0.0, 0.0));
|
||||
float3 scale = GetScale(pivotWS);
|
||||
|
||||
float3 positionOS = TransformWorldToObject(PositionWS) * scale;
|
||||
float3 normalOS = normalize(TransformWorldToObjectDir(NormalWS));
|
||||
|
||||
/*
|
||||
Detail layer A.
|
||||
*/
|
||||
if (detailWeightA > 0.001)
|
||||
{
|
||||
float4 detailA = SampleProjectedDetailLOD
|
||||
(
|
||||
DetailTexA,
|
||||
positionOS,
|
||||
normalOS,
|
||||
ProjectionsBlend,
|
||||
DetailSizeA,
|
||||
depth
|
||||
);
|
||||
|
||||
float detailMaskA = smoothstep(0.0, 0.8, detailA.a);
|
||||
|
||||
Output = lerp(Output, detailA.rgb, detailMaskA * detailWeightA);
|
||||
}
|
||||
|
||||
/*
|
||||
Detail layer B.
|
||||
|
||||
This is intentionally restored for testing.
|
||||
If performance drops too much, set DetailIntensityB to 0
|
||||
or remove this block again.
|
||||
*/
|
||||
if (detailWeightB > 0.001)
|
||||
{
|
||||
float4 detailB = SampleProjectedDetailLOD
|
||||
(
|
||||
DetailTexB,
|
||||
positionOS,
|
||||
normalOS,
|
||||
ProjectionsBlend,
|
||||
DetailSizeB,
|
||||
depth
|
||||
);
|
||||
|
||||
float detailMaskB = smoothstep(0.0, 0.8, detailB.a);
|
||||
|
||||
Output = lerp(Output, detailB.rgb, detailMaskB * detailWeightB);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Simple fog is preserved.
|
||||
|
||||
If fog becomes a measurable cost later, it can be moved to a cheaper global pass
|
||||
or replaced with a simpler approximation.
|
||||
*/
|
||||
if (FogUse)
|
||||
{
|
||||
Output = lerp(Output.rgb, FogColor.rgb, smoothstep(FogMin, FogMax, depth) * FogColor.a);
|
||||
float fogFactor = smoothstep(FogMin, FogMax, depth) * FogColor.a;
|
||||
Output = lerp(Output, FogColor.rgb, fogFactor);
|
||||
}
|
||||
|
||||
Alpha = Color.a;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user