Permalink
Browse files

Added 18-ibl example.

  • Loading branch information...
dariomanesku committed Feb 14, 2014
1 parent 7259e94 commit 9bb2440d868623c7399dea270d9778594f59b1da
Showing with 1,066 additions and 0 deletions.
  1. +79 −0 examples/18-ibl/fs_ibl_mesh.sc
  2. +23 −0 examples/18-ibl/fs_ibl_skybox.sc
  3. +900 −0 examples/18-ibl/ibl.cpp
  4. +17 −0 examples/18-ibl/makefile
  5. +7 −0 examples/18-ibl/varying.def.sc
  6. +20 −0 examples/18-ibl/vs_ibl_mesh.sc
  7. +19 −0 examples/18-ibl/vs_ibl_skybox.sc
  8. BIN examples/runtime/shaders/dx11/fs_ibl_mesh.bin
  9. BIN examples/runtime/shaders/dx11/fs_ibl_skybox.bin
  10. BIN examples/runtime/shaders/dx11/vs_ibl_mesh.bin
  11. BIN examples/runtime/shaders/dx11/vs_ibl_skybox.bin
  12. BIN examples/runtime/shaders/dx9/fs_ibl_mesh.bin
  13. BIN examples/runtime/shaders/dx9/fs_ibl_skybox.bin
  14. BIN examples/runtime/shaders/dx9/vs_ibl_mesh.bin
  15. BIN examples/runtime/shaders/dx9/vs_ibl_skybox.bin
  16. BIN examples/runtime/shaders/gles/fs_ibl_mesh.bin
  17. BIN examples/runtime/shaders/gles/fs_ibl_skybox.bin
  18. BIN examples/runtime/shaders/gles/vs_ibl_mesh.bin
  19. BIN examples/runtime/shaders/gles/vs_ibl_skybox.bin
  20. BIN examples/runtime/shaders/glsl/fs_ibl_mesh.bin
  21. BIN examples/runtime/shaders/glsl/fs_ibl_skybox.bin
  22. BIN examples/runtime/shaders/glsl/vs_ibl_mesh.bin
  23. BIN examples/runtime/shaders/glsl/vs_ibl_skybox.bin
  24. BIN examples/runtime/textures/ennis_irr.dds
  25. BIN examples/runtime/textures/ennis_lod.dds
  26. BIN examples/runtime/textures/grace_irr.dds
  27. BIN examples/runtime/textures/grace_lod.dds
  28. BIN examples/runtime/textures/pisa_irr.dds
  29. BIN examples/runtime/textures/pisa_lod.dds
  30. BIN examples/runtime/textures/uffizi_irr.dds
  31. BIN examples/runtime/textures/uffizi_lod.dds
  32. BIN examples/runtime/textures/wells_irr.dds
  33. BIN examples/runtime/textures/wells_lod.dds
  34. +1 −0 premake/premake4.lua
@@ -0,0 +1,79 @@
+$input v_view, v_normal
+
+/*
+ * Copyright 2014 Dario Manesku. All rights reserved.
+ * License: http://www.opensource.org/licenses/BSD-2-Clause
+ */
+
+#include "../common/common.sh"
+
+uniform float u_time;
+uniform vec4 u_params;
+uniform mat4 u_mtx;
+uniform vec4 u_flags;
+uniform vec3 u_camPos;
+uniform vec3 u_rgbDiff;
+uniform vec3 u_rgbSpec;
+
+SAMPLERCUBE(u_texCube, 4);
+SAMPLERCUBE(u_texCubeIrr, 5);
+
+#define u_glossiness u_params.x
+#define u_exposure u_params.y
+#define u_diffspec u_params.z
+
+#define u_doDiffuse u_flags.x
+#define u_doSpecular u_flags.y
+#define u_doDiffuseIbl u_flags.z
+#define u_doSpecularIbl u_flags.w
+
+vec3 fresnel(vec3 _cspec, float _dot)
+{
+ return _cspec + (1.0 - _cspec) * pow(1.0 - _dot, 5);
+}
+
+void main()
+{
+ vec3 light = vec3(0.0f, 0.0f, -1.0f);
+ vec3 clight = vec3(1.0f, 1.0f, 1.0f);
+
+ vec3 v = v_view;
+ vec3 n = normalize(v_normal);
+ vec3 l = normalize(light);
+ vec3 h = normalize(v + l);
+
+ float ndotl = clamp(dot(n, l), 0.0, 1.0); //diff
+ float ndoth = clamp(dot(n, h), 0.0, 1.0); //spec
+ float vdoth = clamp(dot(v, h), 0.0, 1.0); //spec fresnel
+ float ndotv = clamp(dot(n, v), 0.0, 1.0); //env spec fresnel
+
+ vec3 r = 2.0*ndotv*n - v; // reflect(v, n);
+
+ vec3 cubeR = normalize(mul(u_mtx, vec4(r, 0.0)).xyz);
+ vec3 cubeN = normalize(mul(u_mtx, vec4(n, 0.0)).xyz);
+
+ float mipLevel = min((1.0 - u_glossiness)*11.0 + 1.0, 8.0);
+ vec3 cenv = textureCubeLod(u_texCube, cubeR, mipLevel).xyz;
+
+ vec3 kd = u_rgbDiff;
+ vec3 ks = u_rgbSpec;
+
+ vec3 cs = ks * u_diffspec;
+ vec3 cd = kd * (1.0 - cs);
+
+ vec3 diff = cd;
+ float pwr = exp2(u_glossiness * 11.0 + 1.0);
+ vec3 spec = cs * pow(ndoth, pwr) * ( (pwr + 8.0)/8.0) * fresnel(cs, vdoth);
+
+ vec3 ambspec = fresnel(cs, ndotv) * cenv;
+ vec3 ambdiff = cd * textureCube(u_texCubeIrr, cubeN).xyz;
+
+ vec3 lc = ( diff * u_doDiffuse + spec * u_doSpecular ) * ndotl * clight;
+ vec3 ec = (ambdiff * u_doDiffuseIbl + ambspec * u_doSpecularIbl);
+
+ vec3 color = lc + ec;
+ color = color * exp2(u_exposure);
+
+ gl_FragColor.xyz = toFilmic(color);
+ gl_FragColor.w = 1.0;
+}
@@ -0,0 +1,23 @@
+$input v_dir
+
+/*
+ * Copyright 2014 Dario Manesku. All rights reserved.
+ * License: http://www.opensource.org/licenses/BSD-2-Clause
+ */
+
+#include "../common/common.sh"
+
+SAMPLERCUBE(u_texCube, 4);
+
+uniform vec4 u_params;
+#define u_exposure u_params.y
+
+void main()
+{
+ vec3 dir = normalize(v_dir);
+
+ vec4 color = textureCubeLod(u_texCube, dir, 0.0);
+ color *= exp2(u_exposure);
+
+ gl_FragColor = toFilmic(color);
+}
Oops, something went wrong.

0 comments on commit 9bb2440

Please sign in to comment.