]> git.tdb.fi Git - libs/gl.git/commitdiff
Put the PI constant in builtins
authorMikko Rasa <tdb@tdb.fi>
Thu, 6 May 2021 10:15:40 +0000 (13:15 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 6 May 2021 10:32:46 +0000 (13:32 +0300)
It's needed in several places so this is easier than defining it
separately everywhere.

builtin_data/_builtin.glsl
builtin_data/_pbr_prefilter.glsl
builtin_data/_sky.glsl
builtin_data/_sky_backdrop.glsl
builtin_data/_sky_distant.glsl
shaderlib/cooktorrance.glsl

index c8336d9a18e12f05dc3a468023fecd7747e0d7fb..1bdfde13306cb347c061dd29d85a7dbb0acb9f77 100644 (file)
@@ -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);
index 1fcdd7169ac6b9e42aa84d962bf409e5a17d6bfe..e0616c251226b359672dbd9d109909b209cac55b 100644 (file)
@@ -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;
index 45ca330dd80afd89f7845f07d353fc8f5fe2d4e5..3493b5a48e92711bcf9a0ceaa7d53871bb753b35 100644 (file)
@@ -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;
index 8d9f4ab91915f435518a4459196ad6665a0e2caf..420f0ed5ff1ce268a7a2a2480d0b87e558047a1b 100644 (file)
@@ -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;
 }
index 0680b98602d812565cdd86b439bdc4e763c54089..e6d4800b07bf118a81be0a12876a0405019ff329 100644 (file)
@@ -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);
index 71f8ec76c8df64046cd3a2a70e46742b5f23aa87..4b0c4dc814ca5b16e903d7003f1371b96b3c6503 100644 (file)
@@ -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()
 {