Skip to content

Commit

Permalink
Merge pull request #206 from shadielhajj/refactor/volume
Browse files Browse the repository at this point in the history
Overhaul of volume Raymarching
  • Loading branch information
patriciogonzalezvivo authored Aug 23, 2024
2 parents e3bc0b8 + 0992d62 commit 6ac82b8
Show file tree
Hide file tree
Showing 34 changed files with 788 additions and 496 deletions.
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

0 comments on commit 6ac82b8

Please sign in to comment.