procedural-3d-engine/data/shaders/glsl/pbrtexture/irradiancecube.frag
Ben Clayton ca884587a4 Move shaders into glsl and hlsl directories
Move `data/shaders` to `data/shaders/glsl`
Move `data/hlsl` to `data/shaders/hlsl`

Fix up shader paths in the cpp files to point to the new glsl location.

`data/shaders/hlsl/compile.py` still overwrites the glsl .spv files (for
now).

Issue: #723
2020-06-01 12:22:28 +01:00

37 lines
1 KiB
GLSL

// Generates an irradiance cube from an environment map using convolution
#version 450
layout (location = 0) in vec3 inPos;
layout (location = 0) out vec4 outColor;
layout (binding = 0) uniform samplerCube samplerEnv;
layout(push_constant) uniform PushConsts {
layout (offset = 64) float deltaPhi;
layout (offset = 68) float deltaTheta;
} consts;
#define PI 3.1415926535897932384626433832795
void main()
{
vec3 N = normalize(inPos);
vec3 up = vec3(0.0, 1.0, 0.0);
vec3 right = normalize(cross(up, N));
up = cross(N, right);
const float TWO_PI = PI * 2.0;
const float HALF_PI = PI * 0.5;
vec3 color = vec3(0.0);
uint sampleCount = 0u;
for (float phi = 0.0; phi < TWO_PI; phi += consts.deltaPhi) {
for (float theta = 0.0; theta < HALF_PI; theta += consts.deltaTheta) {
vec3 tempVec = cos(phi) * right + sin(phi) * up;
vec3 sampleVector = cos(theta) * N + sin(theta) * tempVec;
color += texture(samplerEnv, sampleVector).rgb * cos(theta) * sin(theta);
sampleCount++;
}
}
outColor = vec4(PI * color / float(sampleCount), 1.0);
}