Permalink
Browse files

HDR stuff

  • Loading branch information...
Shinmera committed Jan 29, 2019
1 parent 3b00477 commit fea8eb84869b82f55c2f4769738dcbf6b82144b0
Showing with 70 additions and 0 deletions.
  1. +69 −0 hdr.lisp
  2. +1 −0 trial.asd
@@ -0,0 +1,69 @@
#|
This file is a part of trial
(c) 2019 Shirakumo http://tymoon.eu (shinmera@tymoon.eu)
Author: Nicolas Hafner <shinmera@tymoon.eu>
|#

(in-package #:org.shirakumo.fraf.trial)

(define-shader-pass hdr-output-pass ()
((color :port-type output :texspec (:internal-format :rgba16f))))

(define-shader-pass tone-mapping-pass (post-effect-pass)
((previous-pass :port-type input :texspec (:internal-format :rgba16f))
(color :port-type output :attachment :color-attachment0)))

(define-class-shader (tone-mapping-pass :fragment-shader)
"uniform sampler2D previous_pass;
in vec2 tex_coord;
out vec4 color;
uniform float gamma = 2.2;
uniform float exposure = 0.5;
void main(){
vec3 hdr = texture(previous_pass, tex_coord).rgb;
vec3 mapped = vec3(1.0) - exp((-hdr) * exposure);
mapped = pow(mapped, vec3(1.0 / gamma));
color = vec4(mapped, 1.0);
}")

(define-shader-pass high-color-pass ()
((high-pass :port-type output :texspec (:internal-format :rgba16f)
:attachment :color-attachment1)))

(define-class-shader (high-color-pass :fragment-shader -100)
"out vec4 color;
layout (location = 1) out vec4 high_pass;
void main(){
float brightness = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
if(brightness > 0.5)
high_pass = vec4(color.rgb, 1.0);
else
high_pass = vec4(0.0, 0.0, 0.0, 1.0);
}")

(define-shader-pass bloom-pass (tone-mapping-pass)
((previous-pass :port-type input :texspec (:internal-format :rgba16f))
(high-pass :port-type input))
(:inhibit-shaders (tone-mapping-pass :fragment-shader)))

;; KLUDGE: We can't change the previous_pass texture value so there's no way for us
;; to influence the value that the tone-mapping-pass would read in order to
;; factor in the bloom. This we replicate its behaviour here. Not great.
;; use-relations in GLSL-toolkit would allow us to fix this.
(define-class-shader (bloom-pass :fragment-shader)
"uniform sampler2D previous_pass;
uniform sampler2D high_pass;
in vec2 tex_coord;
out vec4 color;
uniform float gamma = 2.2;
uniform float exposure = 0.5;
void main(){
vec3 hdr = texture(previous_pass, tex_coord).rgb;
hdr += texture(high_pass, tex_coord).rgb;
vec3 mapped = vec3(1.0) - exp((-hdr) * exposure);
mapped = pow(mapped, vec3(1.0 / gamma));
color = vec4(mapped, 1.0);
}")
@@ -44,6 +44,7 @@
(:file "geometry-clipmap" :depends-on ("package" "geometry-shapes" "shader-subject"))
(:file "geometry-shapes" :depends-on ("package" "geometry" "asset-pool" ("assets" "mesh")))
(:file "helpers" :depends-on ("package" "entity" "transforms" "shader-subject" "shader-pass" "asset" "resources"))
(:file "hdr" :depends-on ("package" "shader-pass"))
(:file "input" :depends-on ("package" "event-loop" "retention"))
(:file "layer-set" :depends-on ("package"))
(:file "loader" :depends-on ("package" "scene" "resource"))

0 comments on commit fea8eb8

Please sign in to comment.