Added shaders for PBR IBL irradiance cube map generation
This commit is contained in:
parent
4653676522
commit
a86c707172
5 changed files with 60 additions and 1 deletions
37
data/shaders/pbribl/irradiancecube.frag
Normal file
37
data/shaders/pbribl/irradiancecube.frag
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// 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);
|
||||
}
|
||||
BIN
data/shaders/pbribl/irradiancecube.frag.spv
Normal file
BIN
data/shaders/pbribl/irradiancecube.frag.spv
Normal file
Binary file not shown.
|
|
@ -800,7 +800,9 @@ public:
|
|||
// Pipeline layout
|
||||
struct PushBlock {
|
||||
glm::mat4 mvp;
|
||||
float sampleDelta = 0.05f;
|
||||
// Sampling deltas
|
||||
float deltaPhi = (2.0f * M_PI) / 180.0f;
|
||||
float deltaTheta = (0.5f * M_PI) / 64.0f;
|
||||
} pushBlock;
|
||||
|
||||
VkPipelineLayout pipelinelayout;
|
||||
|
|
|
|||
|
|
@ -90,8 +90,13 @@
|
|||
<ClInclude Include="..\base\vulkantools.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\data\shaders\pbribl\genbrdflut.frag" />
|
||||
<None Include="..\data\shaders\pbribl\genbrdflut.vert" />
|
||||
<None Include="..\data\shaders\pbribl\irradiancecube.frag" />
|
||||
<None Include="..\data\shaders\pbribl\pbribl.frag" />
|
||||
<None Include="..\data\shaders\pbribl\pbribl.vert" />
|
||||
<None Include="..\data\shaders\pbribl\prefilterenvmap.frag" />
|
||||
<None Include="..\data\shaders\pbribl\filtercube.vert" />
|
||||
<None Include="..\data\shaders\pbribl\skybox.frag" />
|
||||
<None Include="..\data\shaders\pbribl\skybox.vert" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -55,5 +55,20 @@
|
|||
<None Include="..\data\shaders\pbribl\skybox.vert">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\data\shaders\pbribl\prefilterenvmap.frag">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\data\shaders\pbribl\genbrdflut.frag">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\data\shaders\pbribl\genbrdflut.vert">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\data\shaders\pbribl\filtercube.vert">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="..\data\shaders\pbribl\irradiancecube.frag">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Add table
Add a link
Reference in a new issue