From a86c7071722051107cc99f2472761f8807c2b48c Mon Sep 17 00:00:00 2001 From: saschawillems Date: Wed, 19 Apr 2017 20:29:39 +0200 Subject: [PATCH] Added shaders for PBR IBL irradiance cube map generation --- data/shaders/pbribl/irradiancecube.frag | 37 ++++++++++++++++++++ data/shaders/pbribl/irradiancecube.frag.spv | Bin 0 -> 2856 bytes pbribl/pbribl.cpp | 4 ++- pbribl/pbribl.vcxproj | 5 +++ pbribl/pbribl.vcxproj.filters | 15 ++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 data/shaders/pbribl/irradiancecube.frag create mode 100644 data/shaders/pbribl/irradiancecube.frag.spv diff --git a/data/shaders/pbribl/irradiancecube.frag b/data/shaders/pbribl/irradiancecube.frag new file mode 100644 index 00000000..3232db48 --- /dev/null +++ b/data/shaders/pbribl/irradiancecube.frag @@ -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); +} diff --git a/data/shaders/pbribl/irradiancecube.frag.spv b/data/shaders/pbribl/irradiancecube.frag.spv new file mode 100644 index 0000000000000000000000000000000000000000..e5d9dea3ea337e0ee815028ca2d8a14cda97974b GIT binary patch literal 2856 zcmZ9NTXU2}5QZn&YycBYkduhwZh{I1;|UN&$YR70iD3~0&k~cBM3UV#`vq_D&MSY9 z*WURX_#c#7WtGqK?R4DoOLg_zZ})Wf^vrB3!_#|G8scwn`YH9l{b?9GrLiV>77 zOS8RVZT8IB*Nu28RmwnPCeofXf>yRxHrhJIko(9aaq<)ZRmhss?<}gq4#rpU?ZdZ> z=yUx>yV>cLc7=K=?R5LTr@`AB_tuNjHY#!>=g5POKBm`!+rT_+sjmG z{b##JzpJ?~@ifvvg0sHd2gm|*u~*N;oYsvR2Vmvv#CX!;!=O=g4LL%*XR58ghP@Xp zr)WQcwx0HdY>#Db2HUk0h+o)~rS)*`G+x*3M~snI2Y)Qva>^m{J%_F#e%5~;Z4PHh)k z8QO>IwY>{+F_%s7qlv}FIqsHs!Cw80`4gs!cCB~7x^d>(zTH9F_d96&e#7?6yn|ua z!1e#xGXu8yeZLW}eJR@)=|_GX@!pLyG3_UjA>>NQ8Q=fykr&&q_b%2S0Lz7a5bPeu z$!5Moi1~a|#_Eq+hrv=t8BL)*EA?Y$a{~P$;-~*5w0^a{cwb&d%<&s1dpifX@jvJM7s1xh=Zw6!a#3pz z?4G0V1~~fG7qu>fy)RMgeXv{uiCpvG!CcPd-O{Zx7k4_E(wn_u6=U za^7?AymwW7nfSZt6~y0auYG9UITw)?Rs@ADcWXPh + + + + + diff --git a/pbribl/pbribl.vcxproj.filters b/pbribl/pbribl.vcxproj.filters index aa086bea..63424337 100644 --- a/pbribl/pbribl.vcxproj.filters +++ b/pbribl/pbribl.vcxproj.filters @@ -55,5 +55,20 @@ Shaders + + Shaders + + + Shaders + + + Shaders + + + Shaders + + + Shaders + \ No newline at end of file