Skip to content

Commit

Permalink
merian-shader: add MERIAN_SHADERS to #define guards
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Aug 13, 2024
1 parent 3a99a07 commit f732082
Show file tree
Hide file tree
Showing 36 changed files with 80 additions and 76 deletions.
6 changes: 3 additions & 3 deletions include/merian-shaders/bit_twiddling.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _BIT_TWIDDLING_H_
#define _BIT_TWIDDLING_H_
#ifndef _MERIAN_SHADERS_BIT_TWIDDLING_H_
#define _MERIAN_SHADERS_BIT_TWIDDLING_H_

uint next_power_of_two(uint v) {
v--;
Expand All @@ -13,4 +13,4 @@ uint next_power_of_two(uint v) {
return v;
}

#endif // _BIT_TWIDDLING_H_
#endif // _MERIAN_SHADERS_BIT_TWIDDLING_H_
4 changes: 2 additions & 2 deletions include/merian-shaders/bsdf_diffuse.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "merian-shaders/sampling.glsl"
#include "merian-shaders/frames.glsl"

#ifndef _BSDF_DIFFUSE_H_
#define _BSDF_DIFFUSE_H_
#ifndef _MERIAN_SHADERS_BSDF_DIFFUSE_H_
#define _MERIAN_SHADERS_BSDF_DIFFUSE_H_

// n must be normalized
#define bsdf_diffuse_sample(n, random) (make_frame(n) * sample_cos(random))
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/bsdf_microfacet.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* microfacet model by jonathan:
*/

#ifndef _BSDF_MICROFACET_H_
#define _BSDF_MICROFACET_H_
#ifndef _MERIAN_SHADERS_BSDF_MICROFACET_H_
#define _MERIAN_SHADERS_BSDF_MICROFACET_H_

//-----------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/camera.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "merian-shaders/common.glsl"

#ifndef _CAMERA_H_
#define _CAMERA_H_
#ifndef _MERIAN_SHADERS_CAMERA_H_
#define _MERIAN_SHADERS_CAMERA_H_

// importance sample the blackman harris pixel filter with 1.5px radius support
vec2 pixel_offset_blackman_harris(const vec2 rand) {
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/color/colors_dng.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _COLORS_DNG_H_
#define _COLORS_DNG_H_
#ifndef _MERIAN_SHADERS_COLORS_DNG_H_
#define _MERIAN_SHADERS_COLORS_DNG_H_

/*
Adapted from VKDT, licensed under:
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/color/colors_dtucs.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _COLORS_DTUCS_H_
#define _COLORS_DTUCS_H_
#ifndef _MERIAN_SHADERS_COLORS_DTUCS_H_
#define _MERIAN_SHADERS_COLORS_DTUCS_H_

/* The following is darktable Uniform Color Space 2022
* © Aurélien Pierre
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/color/colors_munsell.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "merian-shaders/common.glsl"

#ifndef _COLORS_MUNSELL_H_
#define _COLORS_MUNSELL_H_
#ifndef _MERIAN_SHADERS_COLORS_MUNSELL_H_
#define _MERIAN_SHADERS_COLORS_MUNSELL_H_

/*
Adapted from VKDT, licensed under:
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/color/colors_rec2020.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _COLORS_REC2020_H_
#define _COLORS_REC2020_H_
#ifndef _MERIAN_SHADERS_COLORS_REC2020_H_
#define _MERIAN_SHADERS_COLORS_REC2020_H_


vec3 rec2020_to_xyY(vec3 rec2020) {
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/color/colors_srgb.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _COLORS_SRGB_H_
#define _COLORS_SRGB_H_
#ifndef _MERIAN_SHADERS_COLORS_SRGB_H_
#define _MERIAN_SHADERS_COLORS_SRGB_H_

// Converts the curve from sRGB to linear. Primary chromaticities are not transformed (output is close to rec709).
vec3 srgb_to_rgb(vec3 srgb) {
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/color/colors_xyz.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _COLORS_XYZ_H_
#define _COLORS_XYZ_H_
#ifndef _MERIAN_SHADERS_COLORS_XYZ_H_
#define _MERIAN_SHADERS_COLORS_XYZ_H_

float XYZ_luminance(const vec3 rgb) {
return dot(rgb, vec3(0.2126729, 0.7151522, 0.0721750));
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/color/colors_yuv.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _COLORS_YUV_H_
#define _COLORS_YUV_H_
#ifndef _MERIAN_SHADERS_COLORS_YUV_H_
#define _MERIAN_SHADERS_COLORS_YUV_H_

#define yuv_luminance(rgb) dot(rgb, vec3(0.299, 0.587, 0.114))

Expand Down
6 changes: 3 additions & 3 deletions include/merian-shaders/common.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _COMMON_H_
#define _COMMON_H_
#ifndef _MERIAN_SHADERS_COMMON_H_
#define _MERIAN_SHADERS_COMMON_H_

#define M_PI 3.14159265358979323846
#define TWO_PI 6.283185307179586
Expand All @@ -9,4 +9,4 @@
// returns 1/x if x > 0 else 1.
#define SAFE_RECIPROCAL(x) (x > 0. ? 1. / x : 1.0)

#endif // _COMMON_H_
#endif // _MERIAN_SHADERS_COMMON_H_
4 changes: 2 additions & 2 deletions include/merian-shaders/cubemap.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _CUBEMAP_H_
#define _CUBEMAP_H_
#ifndef _MERIAN_SHADERS_CUBEMAP_H_
#define _MERIAN_SHADERS_CUBEMAP_H_

// 0: pos x, 1: neg x, 2: pos y, 3: neg: y, 4: pos z, 5: neg z
uint cubemap_side(const vec3 w) {
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/frames.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _FRAMES_H_
#define _FRAMES_H_
#ifndef _MERIAN_SHADERS_FRAMES_H_
#define _MERIAN_SHADERS_FRAMES_H_

// Returns a matrix of axis (x, y, z) which all being perpendicular to each other
mat3x3 make_frame(vec3 z) {
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/gbuffer.glsl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "merian-shaders/types.glsl.h"

#ifndef _GBUFFER_H_
#define _GBUFFER_H_
#ifndef _MERIAN_SHADERS_GBUFFER_H_
#define _MERIAN_SHADERS_GBUFFER_H_

#ifdef __cplusplus
namespace merian_nodes {
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/grid.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "merian-shaders/cubemap.glsl"

#ifndef _GRID_H_
#define _GRID_H_
#ifndef _MERIAN_SHADERS_GRID_H_
#define _MERIAN_SHADERS_GRID_H_

// Determines the grid cell of pos and returns the lower vertex indices.
// The vertex pos then is index * cell_width.
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/hash.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _HASH_H_
#define _HASH_H_
#ifndef _MERIAN_SHADERS_HASH_H_
#define _MERIAN_SHADERS_HASH_H_

// Jarzynski et al. From Hash Functions for GPU Rendering
// Fastest to highest quality
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/interpolate.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _INTERPOLATE_H_
#define _INTERPOLATE_H_
#ifndef _MERIAN_SHADERS_INTERPOLATE_H_
#define _MERIAN_SHADERS_INTERPOLATE_H_

// like smoothstep but without Hermite smoothing
float linearstep(const float edge0, const float edge1, const float x) {
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/intersect.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _INTERSECT_H_
#define _INTERSECT_H_
#ifndef _MERIAN_SHADERS_INTERSECT_H_
#define _MERIAN_SHADERS_INTERSECT_H_

// Returns t such that ray_origin + t * ray_dir = intersection
#define intersect_ray_plane(plane_origin, plane_normal, ray_origin, ray_dir) (dot(plane_normal, plane_origin - ray_origin) / dot(plane_normal, ray_dir))
Expand Down
6 changes: 3 additions & 3 deletions include/merian-shaders/linalg.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _LINALG_H_
#define _LINALG_H_
#ifndef _MERIAN_SHADERS_LINALG_H_
#define _MERIAN_SHADERS_LINALG_H_


// Returns the Moore-Penrose inverse also known as the pseudoinverse A+ = (A^TA)^-1 * A^T.
Expand Down Expand Up @@ -31,4 +31,4 @@ void pseudoinverse(const vec3 du, const vec3 dv, out vec3 du_dx, out vec3 dv_dx)
pseudoinverse(du, dv, cross(du, dv), du_dx, dv_dx);
}

#endif // _LINALG_H_
#endif // _MERIAN_SHADERS_LINALG_H_
6 changes: 3 additions & 3 deletions include/merian-shaders/morton.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _MORTON_H_
#define _MORTON_H_
#ifndef _MERIAN_SHADERS_MORTON_H_
#define _MERIAN_SHADERS_MORTON_H_

#include "merian-shaders/bit_twiddling.glsl"

Expand Down Expand Up @@ -31,4 +31,4 @@ uint morton_encode2d(const uvec2 p, in uint width, in uint height) {
}


#endif // _MORTON_H_
#endif // _MERIAN_SHADERS_MORTON_H_
4 changes: 2 additions & 2 deletions include/merian-shaders/normal_encode.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _NORMAL_ENCODE_H_
#define _NORMAL_ENCODE_H_
#ifndef _MERIAN_SHADERS_NORMAL_ENCODE_H_
#define _MERIAN_SHADERS_NORMAL_ENCODE_H_

vec2 sign_no0(const vec2 v)
{
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/phase_draine.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _PHASE_DRAINE_H_
#define _PHASE_DRAINE_H_
#ifndef _MERIAN_SHADERS_PHASE_DRAINE_H_
#define _MERIAN_SHADERS_PHASE_DRAINE_H_

/*
* SPDX-FileCopyrightText: Copyright (c) <2023> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/phase_isotropic.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "merian-shaders/sampling.glsl"
#include "merian-shaders/frames.glsl"

#ifndef _PHASE_ISOTROPIC_H_
#define _PHASE_ISOTROPIC_H_
#ifndef _MERIAN_SHADERS_PHASE_ISOTROPIC_H_
#define _MERIAN_SHADERS_PHASE_ISOTROPIC_H_

#define phase_isotropic_sample(random) sample_sphere(random)

Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/phase_rayleigh.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _PHASE_RAYLEIGH_H_
#define _PHASE_RAYLEIGH_H_
#ifndef _MERIAN_SHADERS_PHASE_RAYLEIGH_H_
#define _MERIAN_SHADERS_PHASE_RAYLEIGH_H_

float phase_rayleigh(const float cos_theta) {
return 3 * (1 + cos_theta * cos_theta) / 4;
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/random.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _RANDOM_H_
#define _RANDOM_H_
#ifndef _MERIAN_SHADERS_RANDOM_H_
#define _MERIAN_SHADERS_RANDOM_H_

// Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs"
// Returns random float in [0, 1) and updates state.
Expand Down
6 changes: 3 additions & 3 deletions include/merian-shaders/ray_differential.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _RAYDIFFERENTIAL_H_
#define _RAYDIFFERENTIAL_H_
#ifndef _MERIAN_SHADERS_RAYDIFFERENTIAL_H_
#define _MERIAN_SHADERS_RAYDIFFERENTIAL_H_

struct RayDifferential {
// current differential of origin
Expand Down Expand Up @@ -29,4 +29,4 @@ void ray_diff_propagate(inout RayDifferential rd,
}


#endif // _RAYDIFFERENT_H_
#endif // _MERIAN_SHADERS_RAYDIFFERENTIAL_H_
4 changes: 2 additions & 2 deletions include/merian-shaders/raytrace.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _RAYTRACE_H_
#define _RAYTRACE_H_
#ifndef _MERIAN_SHADERS_RAYTRACE_H_
#define _MERIAN_SHADERS_RAYTRACE_H_

#define _rq_get_t(ray_query, commited) rayQueryGetIntersectionTEXT(ray_query, commited)
#define _rq_instance_id(ray_query, commited) rayQueryGetIntersectionInstanceIdEXT(ray_query, commited)
Expand Down
4 changes: 4 additions & 0 deletions include/merian-shaders/reprojection.glsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef _MERIAN_SHADERS_REPROJECTION
#define _MERIAN_SHADERS_REPROJECTION

// Computes a weight for the quality of the reprojection.
// Reprojections with normals further away than normal_reject_cos = cos(alpha)
Expand Down Expand Up @@ -40,3 +42,5 @@ bool reprojection_intersect_border(inout vec2 prev_pos, const vec2 mv, const vec
}
return false;
}

#endif
4 changes: 2 additions & 2 deletions include/merian-shaders/sampler.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _SAMPLER_H_
#define _SAMPLER_H_
#ifndef _MERIAN_SHADERS_SAMPLER_H_
#define _MERIAN_SHADERS_SAMPLER_H_

// Adapted for Vulkan from https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
// (MIT License)
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/sampling.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "merian-shaders/common.glsl"
#include "merian-shaders/random.glsl"

#ifndef _SAMPLING_H_
#define _SAMPLING_H_
#ifndef _MERIAN_SHADERS_SAMPLING_H_
#define _MERIAN_SHADERS_SAMPLING_H_

// sample sphere, p = 1 / 4pi
vec3 sample_sphere(const vec2 random) {
Expand Down
6 changes: 3 additions & 3 deletions include/merian-shaders/textures.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef _TEXTURES_H_
#define _TEXTURES_H_
#ifndef _MERIAN_SHADERS_TEXTURES_H_
#define _MERIAN_SHADERS_TEXTURES_H_

// adapted from gl_warp.c
#define MERIAN_TEXTUREEFFECT_QUAKE_WARPCALC(st, time) (2 * ((st) + 0.125 * sin(vec2(3 * (st).yx + 0.5 * (time)))))

#define MERIAN_TEXTUREEFFECT_WAVES(st, time) (-vec2(.1, 0) * cos((st).x * 5 + (time) * 2) * pow(max(sin((st).x * 5 + (time) * 2), 0), 5) \
-vec2(.07, 0) * cos(-(st).x * 5 + -(st).y * 3 + (time) * 3) * pow(max(sin(-(st).x * 5 + -(st).y * 3 + (time) * 3), 0), 5))

#endif // _TEXTURES_H_
#endif // _MERIAN_SHADERS_TEXTURES_H_
4 changes: 2 additions & 2 deletions include/merian-shaders/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "merian-shaders/color/colors_srgb.glsl"
#include "merian-shaders/common.glsl"

#ifndef _TONEMAP_H_
#define _TONEMAP_H_
#ifndef _MERIAN_SHADERS_TONEMAP_H_
#define _MERIAN_SHADERS_TONEMAP_H_

vec3 tonemap_clamp(const vec3 rgb) {
return clamp(rgb, vec3(0), vec3(1));
Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/transmittance.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _TRANSMITTANCE_H_
#define _TRANSMITTANCE_H_
#ifndef _MERIAN_SHADERS_TRANSMITTANCE_H_
#define _MERIAN_SHADERS_TRANSMITTANCE_H_

// Beer-Lambert law / Beer's law

Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/types.glsl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _TYPES_H_
#define _TYPES_H_
#ifndef _MERIAN_SHADERS_TYPES_H_
#define _MERIAN_SHADERS_TYPES_H_

#ifdef __cplusplus

Expand Down
4 changes: 2 additions & 2 deletions include/merian-shaders/von_mises_fisher.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "merian-shaders/common.glsl"
#include "merian-shaders/frames.glsl"

#ifndef _VON_MISES_FISHER_H_
#define _VON_MISES_FISHER_H_
#ifndef _MERIAN_SHADERS_VON_MISES_FISHER_H_
#define _MERIAN_SHADERS_VON_MISES_FISHER_H_

// Based on Wenzel Jakob, Numerically stable sampling of the von Mises Fisher distribution on S2 (and other tricks)

Expand Down

0 comments on commit f732082

Please sign in to comment.