From 1b6faada6fa10df085ba7c429e617431c188a43b Mon Sep 17 00:00:00 2001 From: Shinmera Date: Mon, 11 Dec 2023 11:13:00 +0100 Subject: [PATCH] Add emission output to pbr --- data/standard-render-pbr.glsl | 6 +++++- package.lisp | 1 + renderer/pbr.lisp | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/data/standard-render-pbr.glsl b/data/standard-render-pbr.glsl index fcbf5559c..6ad952189 100644 --- a/data/standard-render-pbr.glsl +++ b/data/standard-render-pbr.glsl @@ -3,14 +3,16 @@ #include "pbr-common.glsl" PbrMaterial material; +layout (location = 1) out vec3 f_emission; uniform int material_id; uniform sampler2D albedo_tex; uniform sampler2D metal_rough_occlusion_tex; uniform sampler2D normal_tex; +uniform sampler2D emission_tex; uniform sampler2D brdf_lut; uniform samplerCube irradiance_map; uniform samplerCube environment_map; -vec3 view_dir, F0; +vec3 view_dir, F0, emission; vec4 albedo; float metalness, roughness, occlusion; @@ -21,6 +23,7 @@ void standard_init(){ maybe_call_next_method(); material = materials[material_id]; normal = normal_map(normal_tex, world_position-camera_position, uv, normal); + emission = texture(emission_tex, uv).xyz * material.emission_factor; view_dir = normalize(camera_position - world_position); albedo = texture(albedo_tex, uv); albedo.xyz = pow(albedo.xyz,vec3(gamma)); @@ -82,6 +85,7 @@ vec4 standard_shade(in StandardLight light){ } void standard_finish(){ + f_emission = emission; color.w = albedo.w; if(color.w < material.alpha_cutoff) discard; diff --git a/package.lisp b/package.lisp index aabc6a532..1c2b8b003 100644 --- a/package.lisp +++ b/package.lisp @@ -491,6 +491,7 @@ #:emission-texture #:normal-texture #:pbr-render-pass + #:emission #:environment-light #:irradiance-map #:environment-map) diff --git a/renderer/pbr.lisp b/renderer/pbr.lisp index 6e8a3c3f1..88331ad87 100644 --- a/renderer/pbr.lisp +++ b/renderer/pbr.lisp @@ -85,7 +85,8 @@ (setf (alpha-cutoff target) (alpha-cutoff material))) (define-shader-pass pbr-render-pass (standard-shadows-pass light-cache-render-pass) - ((environment :initform NIL :accessor environment)) + ((environment :initform NIL :accessor environment) + (emission :port-type output :texspec (:internal-format :rgb16f) :attachment :color-attachment2 :reader emission)) (:shader-file (trial "standard-render-pbr.glsl"))) (defmethod render-with ((pass pbr-render-pass) (material pbr-material) program)