Golden Ratio Blue Noise Sampling

Improved fog sampling and stochastic transparency by generating low discrepancy temporal sequences using the golden ratio on blue noise samples
This commit is contained in:
Reinier Vens 2021-04-12 14:36:32 +01:00
commit ec1f8f56d4
8 changed files with 41 additions and 25 deletions

View file

@ -86,7 +86,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Scale: 1.2708329
- _Scale: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1

View file

@ -67,7 +67,7 @@ TextureImporter:
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureFormat: 63
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
@ -79,7 +79,7 @@ TextureImporter:
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureFormat: 63
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0

View file

@ -802,8 +802,8 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 741153267}
m_LocalRotation: {x: 0.0155069195, y: 0.9502416, z: -0.30741316, w: 0.047933277}
m_LocalPosition: {x: -117.52002, y: -77.087425, z: 149.09026}
m_LocalRotation: {x: 0.015506901, y: 0.9502416, z: -0.30741307, w: 0.047933236}
m_LocalPosition: {x: -117.51998, y: -77.08744, z: 149.09026}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 412917866}
@ -820,6 +820,7 @@ GameObject:
m_Component:
- component: {fileID: 750375534}
- component: {fileID: 750375535}
- component: {fileID: 750375536}
m_Layer: 0
m_Name: Manager
m_TagString: Untagged
@ -867,6 +868,19 @@ MonoBehaviour:
Heightmap: {fileID: 8400000, guid: 2fc21a9d3e9647948b56e384cd9378b3, type: 2}
ParticleColors: {fileID: 2800000, guid: 56db63da398b2d04394ddbccedce943c, type: 3}
GravityCamera: {fileID: 2103364771}
--- !u!114 &750375536
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 750375533}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 13f1fa636e0245e42be783568a76e3d6, type: 3}
m_Name:
m_EditorClassIdentifier:
NoiseTexture: {fileID: 2800000, guid: 7c0a392de8821f345824a79dea0d0d41, type: 3}
--- !u!1 &765320284
GameObject:
m_ObjectHideFlags: 0
@ -1220,8 +1234,8 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 965376321}
m_LocalRotation: {x: 0.0155069195, y: 0.9502416, z: -0.30741316, w: 0.047933277}
m_LocalPosition: {x: -117.52002, y: -77.087425, z: 149.09026}
m_LocalRotation: {x: 0.015506901, y: 0.9502416, z: -0.30741307, w: 0.047933236}
m_LocalPosition: {x: -117.51998, y: -77.08744, z: 149.09026}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -2297,12 +2311,12 @@ PrefabInstance:
- target: {fileID: 3664209305474245377, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3664209305474245377, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3664209305474245377, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
@ -2317,17 +2331,17 @@ PrefabInstance:
- target: {fileID: 3664209305474245377, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
value: -16
objectReference: {fileID: 0}
- target: {fileID: 3664209306888449100, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3664209306888449100, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3664209306888449100, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
@ -2342,7 +2356,7 @@ PrefabInstance:
- target: {fileID: 3664209306888449100, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
value: -16
objectReference: {fileID: 0}
- target: {fileID: 4533226043449861658, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
@ -2542,12 +2556,12 @@ PrefabInstance:
- target: {fileID: 7329274283166941234, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7329274283166941234, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7329274283166941234, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
@ -2557,7 +2571,7 @@ PrefabInstance:
- target: {fileID: 7329274283166941234, guid: 3d8d9cbf10b12214e98891c1f03c1e99,
type: 3}
propertyPath: m_SizeDelta.y
value: 0
value: 144.0148
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3d8d9cbf10b12214e98891c1f03c1e99, type: 3}

View file

@ -26,9 +26,10 @@ public class BlueNoiseProvider : MonoBehaviour
{
Shader.SetGlobalVector("_DitheringCoords", new Vector4(
(float)_camera.scaledPixelWidth / (float)NoiseTexture.width,
(float)_camera.scaledPixelWidth / (float)NoiseTexture.height,
(float)_camera.scaledPixelHeight / (float)NoiseTexture.height,
Random.value,
Random.value
));
Shader.SetGlobalInt("_FrameNumber", Time.frameCount);
}
}

View file

@ -4,9 +4,11 @@
sampler2D _DitheringTex;
float4 _DitheringCoords;
uniform int _FrameNumber;
float isDithered(float2 pos, float alpha) {
float dither = tex2D(_DitheringTex, pos * _DitheringCoords.xy + _DitheringCoords.zw).r;
half dither = frac(tex2D(_DitheringTex, pos * _DitheringCoords.xy).r + _FrameNumber * 1.61803398875);
//float dither = tex2D(_DitheringTex, pos * _DitheringCoords.xy + _DitheringCoords.zw).r;
return alpha - dither - 0.0001 * (1 - ceil(alpha));
}

View file

@ -44,9 +44,6 @@
// the number of volume samples to take
#define SAMPLE_COUNT 128
// spacing between samples
//#define SAMPLE_PERIOD 16
// Shared shader code for pixel view rays, given screen pos and camera frame vectors.
// Camera vectors are passed in as this shader is run from a post proc camera, so the unity built-in values are not useful.
uniform float4x4 _CamProj;
@ -55,6 +52,7 @@
uniform float3 _CamForward;
uniform float3 _CamRight;
uniform float _HalfFov;
uniform int _FrameNumber;
uniform float _StepExponent;
@ -157,8 +155,8 @@
float4 RayMarch( in float3 origin, in float3 direction, in float zbuf, in float2 screenUV, out float scatterSum )
{
//half rand = tex2D(_DitheringTex, screenUV * _DitheringCoords.xy + _DitheringCoords.zw).r*2;
half rand = nrand(screenUV + frac(_Time.x)) * 2;
half rand = frac(tex2D(_DitheringTex, screenUV * _DitheringCoords.xy).r + _FrameNumber * 1.61803398875);
//half rand = nrand(screenUV + frac(_Time.x)) * 2;
float4 sum = (float4)0.;
scatterSum = 0.;

View file

@ -108,7 +108,8 @@ Shader "Aetheria/Volume Sun"
float3 rayPos = IN.worldNormal;
float3 rayStep = normalize(IN.viewDir)*_RayStepSize*(2-rim);
float dither = tex2D(_DitheringTex, (screenPos + .5) * _DitheringCoords.xy + _DitheringCoords.zw).r * 2;
half dither = frac(tex2D(_DitheringTex, (screenPos + .5) * _DitheringCoords.xy).r + _FrameNumber * 1.61803398875);
//float dither = tex2D(_DitheringTex, (screenPos + .5) * _DitheringCoords.xy + _DitheringCoords.zw).r * 2;
rayPos += rayStep * dither;
float3 accum = 0;

BIN
GameData/PlayerSettings.msgpack (Stored with Git LFS)

Binary file not shown.