Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul of volume Raymarching #206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f8b0429
Refactored volume.glsl for clarity.
shadielhajj Aug 13, 2024
6f3d7d1
Merge branch 'main' into refactor/volume
shadielhajj Aug 15, 2024
4919b5e
Rewrote volume renderer (GLSL)
shadielhajj Aug 15, 2024
e0a4e2d
Minor refactor for clarity.
shadielhajj Aug 15, 2024
b34a91c
Added energy-conserving scattering integration
shadielhajj Aug 15, 2024
9f0d87a
Added offset jittering.
shadielhajj Aug 15, 2024
6da4312
Clean-up
shadielhajj Aug 15, 2024
1d43f01
Renamed volume options and added RAYMARCH_VOLUME_MAP_FNC
shadielhajj Aug 16, 2024
834faa8
Added volume material.
shadielhajj Aug 16, 2024
6ab889e
Restored default renderer.
shadielhajj Aug 16, 2024
243b5c0
Support for volume to co-exist with PBR.
shadielhajj Aug 16, 2024
7877ea8
Merge branch 'main' into refactor/volume
shadielhajj Aug 16, 2024
c87fd14
HLSL port.
shadielhajj Aug 19, 2024
7a70ef0
Added license, updated doc.
shadielhajj Aug 19, 2024
42597a9
Added license.
shadielhajj Aug 19, 2024
235deee
Factored out beerLambert.
shadielhajj Aug 19, 2024
c74c62f
Missing include.
shadielhajj Aug 19, 2024
9a809bf
Added attenuation.
shadielhajj Aug 19, 2024
e01ed48
Fixed light direction.
shadielhajj Aug 19, 2024
dd0cd61
Added support for point light.
shadielhajj Aug 19, 2024
9a0d178
Added point light attenuation (GLSL)
shadielhajj Aug 19, 2024
86addc3
Support for point lights (HLSL)
shadielhajj Aug 19, 2024
13cbdb5
Fixed light direction
shadielhajj Aug 19, 2024
fd32b4a
Fixed self-shadowing error.
shadielhajj Aug 19, 2024
b94ee28
Renamed color to albedo
shadielhajj Aug 19, 2024
843fb6e
Refactor volume (GLSL)
shadielhajj Aug 20, 2024
c40e3e6
Physically accurate volume single-scattering equation.
shadielhajj Aug 20, 2024
1331a29
Volume: Swapped scattering an absorption
shadielhajj Aug 20, 2024
4b65612
Volume: Added opaque shadowing
shadielhajj Aug 20, 2024
b884979
Merge branch 'doc/license' into refactor/volume
shadielhajj Aug 20, 2024
d180c3d
Renamed VolumeMaterial to Volume.
shadielhajj Aug 20, 2024
833fd4b
Refactored raymarch.*
shadielhajj Aug 20, 2024
c9de711
Refactored RAYMARCH_AOV interface.
shadielhajj Aug 20, 2024
b94685f
Renamed RAYMARCH_VOLUMETRIC_SHADOWS
shadielhajj Aug 20, 2024
1a2a6f2
Renamed volume to medium
shadielhajj Aug 20, 2024
67b3369
Updated doc.
shadielhajj Aug 20, 2024
5aa064f
Fixed single-sample raymarching.
shadielhajj Aug 22, 2024
e473c07
Moved attenuation to /light
shadielhajj Aug 22, 2024
6fa92e6
Missing decimals for WebGL.
shadielhajj Aug 23, 2024
60c64b8
Added RAYMARCH_VOLUME guard.
shadielhajj Aug 23, 2024
0992d62
Renamed private functions.
shadielhajj Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lighting/light/attenuation.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
contributors: Shadi El Hajj
description: Light attenuation equation
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef LIGHT_ATTENUATION_CONSTANT
#define LIGHT_ATTENUATION_CONSTANT 0.0
#endif

#ifndef LIGHT_ATTENUATION_LINEAR
#define LIGHT_ATTENUATION_LINEAR 0.0
#endif

#ifndef LIGHT_ATTENUATION_EXPONENTIAL
#define LIGHT_ATTENUATION_EXPONENTIAL 1.0
#endif

#ifndef LIGHT_ATTENUATION_EXPONENT
#define LIGHT_ATTENUATION_EXPONENT 2.0
#endif

#ifndef FNC_LIGHT_ATTENUATION
#define FNC_LIGHT_ATTENUATION

float attenuation(float dist) {
return 1.0 / (
LIGHT_ATTENUATION_CONSTANT +
LIGHT_ATTENUATION_LINEAR * dist +
LIGHT_ATTENUATION_EXPONENTIAL * pow(dist, LIGHT_ATTENUATION_EXPONENT)
);
}

#endif
34 changes: 34 additions & 0 deletions lighting/light/attenuation.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
contributors: Shadi El Hajj
description: Light attenuation equation
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef LIGHT_ATTENUATION_CONSTANT
#define LIGHT_ATTENUATION_CONSTANT 0.0
#endif

#ifndef LIGHT_ATTENUATION_LINEAR
#define LIGHT_ATTENUATION_LINEAR 0.0
#endif

#ifndef LIGHT_ATTENUATION_EXPONENTIAL
#define LIGHT_ATTENUATION_EXPONENTIAL 1.0
#endif

#ifndef LIGHT_ATTENUATION_EXPONENT
#define LIGHT_ATTENUATION_EXPONENT 2.0
#endif

#ifndef FNC_LIGHT_ATTENUATION
#define FNC_LIGHT_ATTENUATION

float attenuation(float dist) {
return 1.0 / (
LIGHT_ATTENUATION_CONSTANT +
LIGHT_ATTENUATION_LINEAR * dist +
LIGHT_ATTENUATION_EXPONENTIAL * pow(dist, LIGHT_ATTENUATION_EXPONENT)
);
}

#endif
61 changes: 61 additions & 0 deletions lighting/material/add.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "../material.glsl"

/*
contributors: Shadi El Hajj
description: Add materials a and b, property by property, store result in r
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef MATERIAL_ADD
#define MATERIAL_ADD

void add(Material a, Material b, Material r) {
r.albedo = a.albedo + b.albedo;
r.emissive = a.emissive + b.emissive;
r.position = a.position + b.position;
r.normal = a.normal + b.normal;

#if defined(SCENE_BACK_SURFACE)
r.normal_back = a.normal_back + b.normal_back;
#endif

r.ior = a.ior + b.ior;
r.f0 = a.f0 + b.f0;
r.roughness = a.roughness + b.roughness;
r.metallic = a.metallic + b.metallic;
r.ambientOcclusion = a.ambientOcclusion + b.ambientOcclusion;

#if defined(SHADING_MODEL_CLEAR_COAT)
r.clearCoat = a.clearCoat + b.clearCoat;
r.clearCoatRoughness = a.clearCoatRoughness + b.clearCoatRoughness;
#if defined(MATERIAL_HAS_CLEAR_COAT_NORMAL)
r.clearCoatNormal = a.clearCoatNormal + b.clearCoatNormal;
#endif
#endif

#if defined(SHADING_MODEL_IRIDESCENCE)
r.thickness = a.thickness + b.thickness;
#endif

#if defined(SHADING_MODEL_SUBSURFACE)
r.subsurfaceColor = a.subsurfaceColor + b.subsurfaceColor;
r.subsurfacePower = a.subsurfacePower + b.subsurfacePower;
r.subsurfaceThickness = a.subsurfaceThickness + b.subsurfaceThickness;
#endif

#if defined(SHADING_MODEL_CLOTH)
r.sheenColor = a.sheenColor + b.sheenColor;
#endif

#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
r.specularColor = a.specularColor + b.specularColor;
r.glossiness = a.glossiness + b.glossiness;
#endif

// I don't think anybody needs this
// r.V = a.V + b.V;
// r.R = a.R + b.R;
// r.NoV = a.NoV + b.NoV;
}

#endif
61 changes: 61 additions & 0 deletions lighting/material/add.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "../material.hlsl"

/*
contributors: Shadi El Hajj
description: Add materials a and b, property by property, store result in r
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef MATERIAL_ADD
#define MATERIAL_ADD

void add(Material a, Material b, Material r) {
r.albedo = a.albedo + b.albedo;
r.emissive = a.emissive + b.emissive;
r.position = a.position + b.position;
r.normal = a.normal + b.normal;

#if defined(SCENE_BACK_SURFACE)
r.normal_back = a.normal_back + b.normal_back;
#endif

r.ior = a.ior + b.ior;
r.f0 = a.f0 + b.f0;
r.roughness = a.roughness + b.roughness;
r.metallic = a.metallic + b.metallic;
r.ambientOcclusion = a.ambientOcclusion + b.ambientOcclusion;

#if defined(SHADING_MODEL_CLEAR_COAT)
r.clearCoat = a.clearCoat + b.clearCoat;
r.clearCoatRoughness = a.clearCoatRoughness + b.clearCoatRoughness;
#if defined(MATERIAL_HAS_CLEAR_COAT_NORMAL)
r.clearCoatNormal = a.clearCoatNormal + b.clearCoatNormal;
#endif
#endif

#if defined(SHADING_MODEL_IRIDESCENCE)
r.thickness = a.thickness + b.thickness;
#endif

#if defined(SHADING_MODEL_SUBSURFACE)
r.subsurfaceColor = a.subsurfaceColor + b.subsurfaceColor;
r.subsurfacePower = a.subsurfacePower + b.subsurfacePower;
r.subsurfaceThickness = a.subsurfaceThickness + b.subsurfaceThickness;
#endif

#if defined(SHADING_MODEL_CLOTH)
r.sheenColor = a.sheenColor + b.sheenColor;
#endif

#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
r.specularColor = a.specularColor + b.specularColor;
r.glossiness = a.glossiness + b.glossiness;
#endif

// I don't think anybody needs this
// r.V = a.V + b.V;
// r.R = a.R + b.R;
// r.NoV = a.NoV + b.NoV;
}

#endif
53 changes: 53 additions & 0 deletions lighting/material/multiply.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../material.glsl"

/*
contributors: Shadi El Hajj
description: Mutiply material properties by a constant, store result in r
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef MATERIAL_MULTIPLY
#define MATERIAL_MULTIPLY

void multiply(Material mat, float f, Material r) {
r.albedo = mat.albedo * f;
r.emissive = mat.emissive * f;
r.position = mat.position * f;
r.normal = mat.normal * f;
#if defined(SCENE_BACK_SURFACE)
r.normal_back = mat.normal_back * f;
#endif
r.ior = mat.ior * f;
r.f0 = mat.f0 * f;
r.roughness = mat.roughness * f;
r.metallic = mat.metallic * f;
r.ambientOcclusion = mat.ambientOcclusion * f;
#if defined(SHADING_MODEL_CLEAR_COAT)
r.clearCoat = mat.clearCoat * f;
r.clearCoatRoughness = mat.clearCoatRoughness * f;
#if defined(MATERIAL_HAS_CLEAR_COAT_NORMAL)
r.clearCoatNormal = mat.clearCoatNormal * f;
#endif
#endif
#if defined(SHADING_MODEL_IRIDESCENCE)
r.thickness = mat.thickness * f;
#endif
#if defined(SHADING_MODEL_SUBSURFACE)
r.subsurfaceColor = mat.subsurfaceColor * f;
r.subsurfacePower = mat.subsurfacePower * f;
r.subsurfaceThickness = mat.subsurfaceThickness * f;
#endif
#if defined(SHADING_MODEL_CLOTH)
r.sheenColor = mat.sheenColor * f;
#endif
#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
r.specularColor = mat.specularColor * f;
r.glossiness = mat.glossiness * f;
#endif
// I don't think anybody needs this
// r.V = mat.V * f;
// r.R = mat.R * f;
// r.NoV = mat.NoV * f;
}

#endif
53 changes: 53 additions & 0 deletions lighting/material/multiply.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../material.hlsl"

/*
contributors: Shadi El Hajj
description: Mutiply material properties by a constant, store result in r
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef MATERIAL_MULTIPLY
#define MATERIAL_MULTIPLY

void multiply(Material mat, float f, Material r) {
r.albedo = mat.albedo * f;
r.emissive = mat.emissive * f;
r.position = mat.position * f;
r.normal = mat.normal * f;
#if defined(SCENE_BACK_SURFACE)
r.normal_back = mat.normal_back * f;
#endif
r.ior = mat.ior * f;
r.f0 = mat.f0 * f;
r.roughness = mat.roughness * f;
r.metallic = mat.metallic * f;
r.ambientOcclusion = mat.ambientOcclusion * f;
#if defined(SHADING_MODEL_CLEAR_COAT)
r.clearCoat = mat.clearCoat * f;
r.clearCoatRoughness = mat.clearCoatRoughness * f;
#if defined(MATERIAL_HAS_CLEAR_COAT_NORMAL)
r.clearCoatNormal = mat.clearCoatNormal * f;
#endif
#endif
#if defined(SHADING_MODEL_IRIDESCENCE)
r.thickness = mat.thickness * f;
#endif
#if defined(SHADING_MODEL_SUBSURFACE)
r.subsurfaceColor = mat.subsurfaceColor * f;
r.subsurfacePower = mat.subsurfacePower * f;
r.subsurfaceThickness = mat.subsurfaceThickness * f;
#endif
#if defined(SHADING_MODEL_CLOTH)
r.sheenColor = mat.sheenColor * f;
#endif
#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)
r.specularColor = mat.specularColor * f;
r.glossiness = mat.glossiness * f;
#endif
// I don't think anybody needs this
// r.V = mat.V * f;
// r.R = mat.R * f;
// r.NoV = mat.NoV * f;
}

#endif
16 changes: 16 additions & 0 deletions lighting/medium.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
contributors: Shadi El Hajj
description: Medium Structure
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef STR_MEDIUM
#define STR_MEDIUM

struct Medium {
vec3 scattering;
vec3 absorption;
float sdf;
};

#endif
16 changes: 16 additions & 0 deletions lighting/medium.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
contributors: Shadi El Hajj
description: Medium Structure
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef STR_MEDIUM
#define STR_MEDIUM

struct Medium {
float3 scattering;
float3 absorption;
float sdf;
};

#endif
41 changes: 41 additions & 0 deletions lighting/medium/new.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "../medium.glsl"

/*
contributors: Shadi El Hajj
description: |
Medium Constructor.
use:
- void mediumNew(out <medium> _mat)
- <medium> mediumNew()
license: MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj
*/

#ifndef FNC_MEDIUM_NEW
#define FNC_MEDIUM_NEW

void mediumNew(out Medium _mat) {
_mat.scattering = vec3(1.0, 1.0, 1.0);
_mat.absorption = vec3(1.0, 1.0, 1.0);
_mat.sdf = RAYMARCH_MAX_DIST;

}

Medium mediumNew() {
Medium mat;
mediumNew(mat);
return mat;
}

Medium mediumNew(vec3 scattering, vec3 absorption, float sdf) {
Medium mat = mediumNew();
mat.scattering = scattering;
mat.absorption = absorption;
mat.sdf = sdf;
return mat;
}

Medium mediumNew(vec3 scattering, float sdf) {
return mediumNew(scattering, vec3(0.0, 0.0, 0.0), sdf);
}

#endif
Loading