]> git.tdb.fi Git - libs/gl.git/commitdiff
Move environment map handling to its own shader file
authorMikko Rasa <tdb@tdb.fi>
Sat, 19 Mar 2022 07:57:38 +0000 (09:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 19 Mar 2022 07:57:38 +0000 (09:57 +0200)
shaderlib/common.glsl
shaderlib/cooktorrance.glsl
shaderlib/environment.glsl [new file with mode: 0644]

index 6bac9c3720e478fe3beb5a186da3b53800e902f2..300726dc541c0f7d4cfcdfdcdba9094f4662f242 100644 (file)
@@ -1,14 +1,7 @@
 import msp_interface;
 import shadow;
 
-layout(set=0) uniform EnvMap
-{
-       mat3 env_world_matrix;
-};
-
 layout(set=1) uniform sampler2D normal_map;
-layout(set=0) uniform samplerCube environment_map;
-layout(set=0) uniform samplerCube irradiance_map;
 
 layout(constant_id=auto) const bool use_instancing = false;
 layout(constant_id=auto) const bool use_normal_map = false;
@@ -102,23 +95,6 @@ virtual IncomingLight get_incoming_light(int index, vec3 world_pos)
        return IncomingLight(rel_pos/d, light_sources[index].color*attenuation);
 }
 
-virtual vec3 get_environment_sample(vec3 direction, float roughness)
-{
-       float lod = (2-roughness)*roughness*(textureQueryLevels(environment_map)-1);
-       return textureLod(environment_map, env_world_matrix*direction, lod).rgb;
-}
-
-virtual vec3 get_reflection(vec3 normal, vec3 look)
-{
-       vec3 reflect_dir = reflect(look, normal);
-       return get_environment_sample(reflect_dir, 0.0);
-}
-
-virtual vec3 get_irradiance_sample(vec3 normal)
-{
-       return texture(irradiance_map, env_world_matrix*normal).rgb;
-}
-
 vec3 apply_fog(vec3 color)
 {
        float fog_value = exp(fog_coord*fog_density);
index fe6179b783ba27fc50fdb164e5e6ba30f3536832..e942b49ebab2bb5cb9e5553b004e5e112b36fe5e 100644 (file)
@@ -1,5 +1,6 @@
 import msp_interface;
 import common;
+import environment;
 import shadow;
 
 struct PbrMaterialParameters
diff --git a/shaderlib/environment.glsl b/shaderlib/environment.glsl
new file mode 100644 (file)
index 0000000..b5f0cdf
--- /dev/null
@@ -0,0 +1,26 @@
+layout(set=0) uniform EnvMap
+{
+       mat3 env_world_matrix;
+};
+
+layout(set=0) uniform samplerCube environment_map;
+layout(set=0) uniform samplerCube irradiance_map;
+
+#pragma MSP stage(fragment)
+virtual vec3 get_environment_sample(vec3 direction, float roughness)
+{
+       float lod = (2-roughness)*roughness*(textureQueryLevels(environment_map)-1);
+       return textureLod(environment_map, env_world_matrix*direction, lod).rgb;
+}
+
+virtual vec3 get_reflection(vec3 normal, vec3 look)
+{
+       vec3 reflect_dir = reflect(look, normal);
+       return get_environment_sample(reflect_dir, 0.0);
+}
+
+virtual vec3 get_irradiance_sample(vec3 normal)
+{
+       return texture(irradiance_map, env_world_matrix*normal).rgb;
+}
+