Tweak fog params
This commit is contained in:
parent
c0f41045da
commit
496eabcb27
2 changed files with 11 additions and 12 deletions
|
@ -5,9 +5,9 @@ const INV_SQRT_3 = 0.57735026918962576451; // 1 / sqrt(3)
|
||||||
// total = (2n + 1)^2
|
// total = (2n + 1)^2
|
||||||
const SHADOW_SAMPLES = 2;
|
const SHADOW_SAMPLES = 2;
|
||||||
const INV_SHADOW_SAMPLES = 1.0 / 25.0;
|
const INV_SHADOW_SAMPLES = 1.0 / 25.0;
|
||||||
const FOG_MAX_STEPS = 20;
|
const FOG_MAX_STEPS = 30;
|
||||||
const FOG_MAX_DIST = 300.0;
|
const FOG_STEP_SIZE = 5.0;
|
||||||
const FOG_SCALE = 0.01;
|
const FOG_SCALE = 0.01;
|
||||||
const FOG_DENSITY = 2.0;
|
const FOG_DENSITY = 2.0;
|
||||||
const FOG_ALPHA = 1.0;
|
const FOG_ALPHA = 1.0;
|
||||||
const FOG_BLEND_DIST = 10.0;
|
const FOG_BLEND_STEPS = 4;
|
||||||
|
|
|
@ -47,9 +47,9 @@ var s_geometry_depth: sampler;
|
||||||
|
|
||||||
fn fog_noise(pos: vec3<f32>) -> f32 {
|
fn fog_noise(pos: vec3<f32>) -> f32 {
|
||||||
var p = pos * FOG_SCALE;
|
var p = pos * FOG_SCALE;
|
||||||
p.x += global_uniforms.time * 0.01;
|
p.x += global_uniforms.time * 0.1;
|
||||||
p.y += global_uniforms.time * 0.2;
|
p.y += global_uniforms.time * 0.2;
|
||||||
p.z += sin(global_uniforms.time * 0.1) * 0.1;
|
p.z += sin(global_uniforms.time * 0.1) * 0.2;
|
||||||
return fbm(p);
|
return fbm(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ fn ray_march(origin: vec3<f32>, direction: vec3<f32>, scene_depth: f32) -> f32 {
|
||||||
for (var i = 0; i < FOG_MAX_STEPS; i++)
|
for (var i = 0; i < FOG_MAX_STEPS; i++)
|
||||||
{
|
{
|
||||||
let noise = fog_noise(origin + direction * depth);
|
let noise = fog_noise(origin + direction * depth);
|
||||||
depth += FOG_MAX_DIST / f32(FOG_MAX_STEPS);
|
depth += FOG_STEP_SIZE;
|
||||||
let blend = min(depth / FOG_BLEND_DIST, 1.0);
|
let blend = min(f32(i + 1) / f32(FOG_BLEND_STEPS), 1.0);
|
||||||
let contribution = FOG_DENSITY / f32(FOG_MAX_STEPS);
|
let contribution = FOG_DENSITY / f32(FOG_MAX_STEPS);
|
||||||
density += blend * noise * contribution;
|
density += blend * noise * contribution;
|
||||||
if (density >= 1.0)
|
if (density >= 1.0)
|
||||||
|
@ -96,7 +96,6 @@ fn fs_main(vert: FogVertexOutput) -> @location(0) vec4<f32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let density = ray_march(vert.world_position.xyz, direction, max_fog_depth);
|
let density = ray_march(vert.world_position.xyz, direction, max_fog_depth);
|
||||||
// return vec4<f32>(1.0, 1.0, 1.0, density);
|
|
||||||
|
|
||||||
var in_light = 0.0;
|
var in_light = 0.0;
|
||||||
if (global_uniforms.use_shadowmaps > 0u) {
|
if (global_uniforms.use_shadowmaps > 0u) {
|
||||||
|
@ -127,16 +126,16 @@ fn fs_main(vert: FogVertexOutput) -> @location(0) vec4<f32> {
|
||||||
in_light = 1.0;
|
in_light = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var base_color = vec3<f32>(mix(0.8, 0.4, density));
|
var base_color = vec3<f32>(mix(0.5, 0.1, density));
|
||||||
let ambient_strength = 0.02;
|
let ambient_strength = 0.04;
|
||||||
let ambient_color = base_color * ambient_strength;
|
let ambient_color = base_color * ambient_strength;
|
||||||
|
|
||||||
var radiance = vec3<f32>(0.0);
|
var radiance = vec3<f32>(0.0);
|
||||||
if (in_light > 0.0) {
|
if (in_light > 0.0) {
|
||||||
// attenuation
|
// attenuation
|
||||||
let light_dist = length(light.position - vert.world_position.xyz);
|
let light_dist = length(light.position - vert.world_position.xyz);
|
||||||
let coef_a = 2.0;
|
let coef_a = 0.0;
|
||||||
let coef_b = 4.0;
|
let coef_b = 1.0;
|
||||||
let light_attenuation = 1.0 / (1.0 + coef_a * light_dist + coef_b * light_dist * light_dist);
|
let light_attenuation = 1.0 / (1.0 + coef_a * light_dist + coef_b * light_dist * light_dist);
|
||||||
|
|
||||||
radiance = light.color.rgb * light.color.a * light_attenuation * in_light;
|
radiance = light.color.rgb * light.color.a * light_attenuation * in_light;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue