X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=shaderlib%2Fenvironment.glsl;fp=shaderlib%2Fenvironment.glsl;h=b5f0cdfb7f572d7c7ab581a54a7c1a1ff83eabcd;hp=0000000000000000000000000000000000000000;hb=857c2db0fb3112b750b618625649d12e13d9ae1a;hpb=03937c4f58465cb0fe7492feb17f19e81eee6abb diff --git a/shaderlib/environment.glsl b/shaderlib/environment.glsl new file mode 100644 index 00000000..b5f0cdfb --- /dev/null +++ b/shaderlib/environment.glsl @@ -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; +} +