Adds fragment shader PBR resolve

It allows to have PBR for devices without properly detected compute
shaders.
This commit is contained in:
Vladislav Belov 2026-06-11 19:33:57 +02:00
parent 62fcb7e042
commit faeca3c5eb
No known key found for this signature in database
GPG key ID: 353545E45DB9CCB3
5 changed files with 55 additions and 8 deletions

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<effect>
<technique>
<require shaders="glsl"/>
<require shaders="spirv"/>
<pass shader="resolve_pbr">
<depth test="FALSE" mask="false"/>
</pass>
</technique>
</effect>

View file

@ -0,0 +1,12 @@
#ifndef INCLUDED_COMMON_TONE_MAPPING
#define INCLUDED_COMMON_TONE_MAPPING
vec3 applyTonemapper(vec3 color)
{
float whitePoint = 10.0;
// Extendend Reinhard:
// https://www-old.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
return color * (vec3(1.0) + color / (whitePoint * whitePoint)) / (vec3(1.0) + color);
}
#endif // INCLUDED_COMMON_TONE_MAPPING

View file

@ -1,6 +1,7 @@
#version 430
#include "common/compute.h"
#include "common/tone_mapper.h"
BEGIN_DRAW_TEXTURES
TEXTURE_2D(0, inTex)
@ -14,14 +15,6 @@ END_DRAW_UNIFORMS
STORAGE_2D(0, rgba8, outTex);
vec3 applyTonemapper(vec3 color)
{
float whitePoint = 10.0;
// Extendend Reinhard:
// https://www-old.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
return color * (vec3(1.0) + color / (whitePoint * whitePoint)) / (vec3(1.0) + color);
}
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main()
{

View file

@ -0,0 +1,23 @@
#version 120
#include "common/fragment.h"
#include "common/stage.h"
#include "common/tone_mapper.h"
BEGIN_DRAW_TEXTURES
TEXTURE_2D(0, inTex)
END_DRAW_TEXTURES
BEGIN_DRAW_UNIFORMS
// Premultiplied exposure, already contains 2^exposure.
UNIFORM(float, exposure)
END_DRAW_UNIFORMS
VERTEX_OUTPUT(0, vec2, v_tex);
void main()
{
vec3 hdrColor = SAMPLE_2D(GET_DRAW_TEXTURE_2D(inTex), v_tex).rgb;
vec3 sdrColor = applyTonemapper(hdrColor * exposure);
OUTPUT_FRAGMENT_SINGLE_COLOR(vec4(sdrColor, 1.0));
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<program type="glsl">
<vertex file="glsl/simple.vs">
<stream name="pos" attribute="a_vertex"/>
<stream name="uv0" attribute="a_uv0"/>
</vertex>
<fragment file="glsl/resolve_pbr.fs"/>
</program>