I am building a 3d renderer in C++ using Vulkan.hpp. I have implemented deferred shading…
- User
I am building a 3d renderer in C++ using Vulkan.hpp. I have implemented deferred shading with PBR shading and IBL lighting. To generate the specular part of the IBL I am using a prefilter pass on the environmental cubemap to generate the roughness levels, which are then saved to the cubemap mip levels. Right now this is being done as part of a fragment shader that is rendered as part of generating the IBL textures. In order to improve the flexibility to rerun this as the environmental lighting changes (e.g. a day/night cycle), I am wondering whether this could be converted to a compute shader that can be run in parallel, reducing the impact on the render cycle time. Is this possible and does it make sense to try to do this?
Here is the fragment shader code for reference:
#version 450 layout(location = 0) out vec4 FragColor; layout(location = 1) in vec4 WorldPos;
layout(binding = 2) uniform samplerCube environmentMap; layout(set = 0, binding = 3) uniform Roughness_Data { float roughness; } roughness;
const float PI = 3.14159265359; // ---------------------------------------------------------------------------- float DistributionGGX(vec3 N, vec3 H, float roughness) { float a = roughnessroughness; float a2 = aa; float NdotH = max(dot(N, H), 0.0); float NdotH2 = NdotH*NdotH;
codefloat nom = a2; float denom = (NdotH2 * (a2 - 1.0) + 1.0); denom = PI * denom * denom; return nom / denom;} // ---------------------------------------------------------------------------- // http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html // efficient VanDerCorpus calculation. float RadicalInverse_VdC(uint bits) { bits = (bits << 16u) | (bits >> 16u); bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); return float(bits) * 2.3283064365386963e-10; // / 0x100000000 } // ---------------------------------------------------------------------------- vec2 Hammersley(uint i, uint N) { return vec2(float(i)/float(N), RadicalInverse_VdC(i)); } // ---------------------------------------------------------------------------- vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness) { float a = roughness*roughness;
code - Assistant