Dir light test

This commit is contained in:
max 2022-04-03 17:47:44 +02:00
parent 20c2847d23
commit f153209bbc
6 changed files with 91 additions and 58 deletions

View File

@ -113,10 +113,17 @@ public partial class FogLight : LightOverride
currentRes /= 2;
}
//var directionalShadowmapBlurred = Shader.PropertyToID("_DirectionalShadowmapBlurred");
//m_BufGrabShadowmap.GetTemporaryRT(directionalShadowmapBlurred, 1024, 1024, 0, FilterMode.Bilinear, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
//m_BufGrabShadowmap.Blit(shadowmap, m_Shadowmap);
//m_BufGrabShadowmap.SetGlobalTexture(directionalShadowmapBlurred, directionalShadowmapBlurred);
RenderTexture blur = RenderTexture.GetTemporary(targetRes, targetRes, 0, format, RenderTextureReadWrite.Linear);
m_BufGrabShadowmap.SetGlobalVector("_TexelSize", new Vector4(1.0f / targetRes, 1.0f / targetRes, 0, 0));
m_BufGrabShadowmap.SetGlobalFloat("_BlurSize", m_BlurSize);
for (int i = 0; i < m_BlurIterations; i++)
{
m_BufGrabShadowmap.Blit(m_Shadowmap, blur, m_BlurShadowmapMaterial, 2);
m_BufGrabShadowmap.Blit(blur, m_Shadowmap, m_BlurShadowmapMaterial, 3);
}
blur.Release();
}
private Vector4 GetZParams()

View File

@ -74,6 +74,13 @@ public class VolumetricFog : MonoBehaviour
[Range(0.0f, 1.0f)]
public float m_Z = 1.0f;
[SerializeField]
private float m_dirLightOffset;
[SerializeField]
private float m_vsmBias;
[SerializeField]
private float m_dirBias;
struct PointLightParams
{
public Vector3 pos;
@ -292,7 +299,9 @@ public class VolumetricFog : MonoBehaviour
m_dirLightDir[1] = dir.y;
m_dirLightDir[2] = dir.z;
m_InjectLightingAndDensity.SetFloats("_DirLightDir", m_dirLightDir);
m_InjectLightingAndDensity.SetFloat("_DirLightOffset", m_dirLightOffset);
m_InjectLightingAndDensity.SetFloat("_VSMBias", m_vsmBias);
m_InjectLightingAndDensity.SetFloat("_DirBias", m_dirBias);
}
float[] m_fogParams;

View File

@ -37,6 +37,8 @@ CGPROGRAM
half4 frag(v2f i) : SV_Target
{
//return half4(i.uv, 0, 1);
half linear01Depth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv));
half4 fog = Fog(linear01Depth, i.uv);
return tex2D(_MainTex, i.uv) * fog.a + fog;

View File

@ -130,7 +130,7 @@ Shader "Hidden/BlurShadowmap" {
struct v2f
{
float4 pos : SV_POSITION;
half4 uv : TEXCOORD0;
half2 uv : TEXCOORD0;
half2 offs : TEXCOORD1;
};
@ -139,9 +139,11 @@ Shader "Hidden/BlurShadowmap" {
v2f vertBlurHorizontal (appdata_img v)
{
v2f o;
o.pos = v.vertex;
o.uv = half4(v.texcoord.xy,1,1);
o.pos = UnityObjectToClipPos(v.vertex);
//o.pos = v.vertex;
o.uv = v.texcoord;
o.offs = _TexelSize.xy * half2(1.0, 0.0) * _BlurSize;
return o;
@ -150,9 +152,11 @@ Shader "Hidden/BlurShadowmap" {
v2f vertBlurVertical (appdata_img v)
{
v2f o;
o.pos = v.vertex;
o.uv = half4(v.texcoord.xy, 1, 1);
o.pos = UnityObjectToClipPos(v.vertex);
//o.pos = v.vertex;
o.uv = v.texcoord;
o.offs = _TexelSize.xy * half2(0.0, 1.0) * _BlurSize;
return o;
@ -160,6 +164,7 @@ Shader "Hidden/BlurShadowmap" {
float4 fragBlur8(v2f i) : SV_Target
{
//half2 coords = i.uv.xy;
half2 coords = i.uv.xy - i.offs * 5.0;
float4 color = 0;

View File

@ -33,6 +33,10 @@ float3 _DirLightDir;
#ifdef DIR_LIGHT_SHADOWS
float _DirLightShadows;
float _ESMExponentDirLight;
float _DirLightOffset;
float _VSMBias;
float _DirBias;
struct ShadowParams
{
float4x4 worldToShadow[4];
@ -258,7 +262,6 @@ float ChebyshevUpperBound(float2 moments, float mean)
{
// Compute variance
float variance = moments.y - (moments.x * moments.x);
float _VSMBias = 0.001f;
variance = max(variance, _VSMBias * mean * mean);
// Compute probabilistic upper bound
@ -298,12 +301,19 @@ float3 DirectionalLight(float3 pos)
if (_DirLightShadows > 0.0)
{
float4 cascadeWeights = getCascadeWeights_splitSpheres(pos);
float4 samplePos = getShadowCoord(pos, cascadeWeights).xyzw;
float3 spos = pos + (_DirLightDir * _DirLightOffset);
float4 samplePos = getShadowCoord(spos, cascadeWeights).xyzw;
//---
//att *= _DirectionalShadowmap.SampleLevel(sampler_DirectionalShadowmap, samplePos.xy, 0).r < samplePos.z;
//---
float2 shadowmap = _DirectionalShadowmap.SampleLevel(sampler_DirectionalShadowmap, samplePos.xy, 0).xy;
att *= ChebyshevUpperBound(shadowmap.xy, samplePos.z / samplePos.w);
float shadow = ChebyshevUpperBound(shadowmap.xy, samplePos.z / samplePos.w);
shadow = saturate(lerp(shadow, 1.0, _DirBias));
att = shadow;
//---
//float depth = exp(-40.0 * samplePos.z);
//att = saturate(shadowmap.r * depth);

View File

@ -29,6 +29,6 @@ half4 Fog(half linear01Depth, half2 screenuv)
return half4(0, 0, 0, 1);
half3 uvw = half3(screenuv.x, screenuv.y, z);
uvw.xy += cellNoise(uvw.xy * _Screen_TexelSize.zw) * _VolumeScatter_TexelSize.xy * 0.8;
//uvw.xy += cellNoise(uvw.xy * _Screen_TexelSize.zw) * _VolumeScatter_TexelSize.xy * 0.8;
return tex3D(_VolumeScatter, uvw);
}