mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Adds fragment shader PBR resolve
It allows to have PBR for devices without properly detected compute shaders.
This commit is contained in:
parent
62fcb7e042
commit
faeca3c5eb
5 changed files with 55 additions and 8 deletions
10
binaries/data/mods/mod/shaders/effects/resolve_pbr.xml
Normal file
10
binaries/data/mods/mod/shaders/effects/resolve_pbr.xml
Normal 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>
|
||||
12
binaries/data/mods/mod/shaders/glsl/common/tone_mapper.h
Normal file
12
binaries/data/mods/mod/shaders/glsl/common/tone_mapper.h
Normal 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
|
||||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
23
binaries/data/mods/mod/shaders/glsl/resolve_pbr.fs
Normal file
23
binaries/data/mods/mod/shaders/glsl/resolve_pbr.fs
Normal 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));
|
||||
}
|
||||
9
binaries/data/mods/mod/shaders/glsl/resolve_pbr.xml
Normal file
9
binaries/data/mods/mod/shaders/glsl/resolve_pbr.xml
Normal 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>
|
||||
Loading…
Reference in a new issue