From 9208e0ff263a287e456e082a4a8b8fd0bbd41f9e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 6 May 2021 13:15:40 +0300 Subject: [PATCH] Put the PI constant in builtins It's needed in several places so this is easier than defining it separately everywhere. --- builtin_data/_builtin.glsl | 2 ++ builtin_data/_pbr_prefilter.glsl | 2 -- builtin_data/_sky.glsl | 7 +++---- builtin_data/_sky_backdrop.glsl | 2 +- builtin_data/_sky_distant.glsl | 2 +- shaderlib/cooktorrance.glsl | 2 -- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/builtin_data/_builtin.glsl b/builtin_data/_builtin.glsl index c8336d9a..1bdfde13 100644 --- a/builtin_data/_builtin.glsl +++ b/builtin_data/_builtin.glsl @@ -40,6 +40,8 @@ typedef image(dimensions=2[], shadow, sampled) float sampler2DArrayShadow; typedef image(dimensions=cube, shadow, sampled) float samplerCubeShadow; typedef image(dimensions=cube[], shadow, sampled) float samplerCubeArrayShadow; +const float PI = 3.1415926535; + // BEGIN BUILTIN FUNCTIONS float radians(float degrees); vec2 radians(vec2 degrees); diff --git a/builtin_data/_pbr_prefilter.glsl b/builtin_data/_pbr_prefilter.glsl index 1fcdd716..e0616c25 100644 --- a/builtin_data/_pbr_prefilter.glsl +++ b/builtin_data/_pbr_prefilter.glsl @@ -6,8 +6,6 @@ uniform PrecalcParams uniform samplerCube environment_map; -const float PI = 3.1415926535; - vec2 hammersley(int i, int count) { float y = bitfieldReverse(uint(i))*2.3283064e-10; diff --git a/builtin_data/_sky.glsl b/builtin_data/_sky.glsl index 45ca330d..3493b5a4 100644 --- a/builtin_data/_sky.glsl +++ b/builtin_data/_sky.glsl @@ -32,7 +32,6 @@ struct OpticalPathInfo vec3 luminance; }; -const float pi = 3.1415926535; const float mie_asymmetry = 0.8; uniform sampler2D transmittance_lookup; @@ -44,7 +43,7 @@ vec3 rayleigh_density(vec3 base, float height) float rayleigh_phase(float cos_theta) { - return 3.0*(1.0+cos_theta*cos_theta)/(16.0*pi); + return 3.0*(1.0+cos_theta*cos_theta)/(16.0*PI); } vec3 mie_density(vec3 base, float height) @@ -57,7 +56,7 @@ float mie_phase(float cos_theta) float g = mie_asymmetry; float num = (1.0-g*g)*(1.0+cos_theta*cos_theta); float denom = (2.0+g*g)*pow(1.0+g*g-2.0*g*cos_theta, 1.5); - return 3.0/(8.0*pi)*num/denom; + return 3.0/(8.0*PI)*num/denom; } vec3 ozone_density(vec3 base, float height) @@ -127,7 +126,7 @@ OpticalPathInfo raymarch_path(float start_height, vec3 look_dir) vec3 in_transmittance = texture(transmittance_lookup, vec2(sqrt(height/atmosphere_thickness), light_z)).rgb; vec3 in_luminance = (ev.rayleigh_scatter*p_rayleigh+ev.mie_scatter*p_mie)*step_size; if(i==n_steps && ground_t>0.0) - in_luminance += ground_albedo*light_z/pi; + in_luminance += ground_albedo*light_z/PI; path_luminance += transmittance*in_transmittance*in_luminance; path_extinction += total_extinction(ev)*step_size; diff --git a/builtin_data/_sky_backdrop.glsl b/builtin_data/_sky_backdrop.glsl index 8d9f4ab9..420f0ed5 100644 --- a/builtin_data/_sky_backdrop.glsl +++ b/builtin_data/_sky_backdrop.glsl @@ -18,5 +18,5 @@ void main() { vec3 nview = normalize(view_dir.xyz); float azimuth = atan(nview.y, nview.x); - frag_color = texture(distant, vec2(azimuth/(2*pi), nview.z*0.5+0.5))*light_color; + frag_color = texture(distant, vec2(azimuth/(2*PI), nview.z*0.5+0.5))*light_color; } diff --git a/builtin_data/_sky_distant.glsl b/builtin_data/_sky_distant.glsl index 0680b986..e6d4800b 100644 --- a/builtin_data/_sky_distant.glsl +++ b/builtin_data/_sky_distant.glsl @@ -5,7 +5,7 @@ import _sky; layout(location=0) out vec3 frag_color; void main() { - float azimuth = texcoord.x*2.0*pi; + float azimuth = texcoord.x*2.0*PI; float z = texcoord.y*2.0-1.0; float r = sqrt(1.0-z*z); vec3 look_dir = vec3(cos(azimuth)*r, sin(azimuth)*r, z); diff --git a/shaderlib/cooktorrance.glsl b/shaderlib/cooktorrance.glsl index 71f8ec76..4b0c4dc8 100644 --- a/shaderlib/cooktorrance.glsl +++ b/shaderlib/cooktorrance.glsl @@ -30,8 +30,6 @@ layout(constant_id=auto) const bool use_emission = false; layout(constant_id=auto) const bool use_emission_map = false; layout(constant_id=auto) const bool use_image_based_lighting = false; -const float PI = 3.1415926535; - #pragma MSP stage(fragment) virtual vec4 get_base_color() { -- 2.45.2