mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-26 17:31:31 +11:00
Merge pull request #237 from MajorPainTheCactus/hdr_5_5
V5.5 Sony PVM 4K HDR Shader
This commit is contained in:
commit
87e63c8000
|
@ -35,16 +35,6 @@ alias0 = ""
|
||||||
float_framebuffer0 = "false"
|
float_framebuffer0 = "false"
|
||||||
srgb_framebuffer0 = "false"
|
srgb_framebuffer0 = "false"
|
||||||
|
|
||||||
/*
|
|
||||||
CRT Bright levels
|
|
||||||
hcrt_brightness = "0.300000"
|
|
||||||
hcrt_colour_system = "0.000000"
|
|
||||||
hcrt_white_temperature = "2800.000000"
|
|
||||||
hcrt_expand_gamut = "1.000000"
|
|
||||||
hcrt_contrast = "0.800000"
|
|
||||||
hcrt_gamma = "-0.200000"
|
|
||||||
*/
|
|
||||||
|
|
||||||
hcrt_brightness = "0.150000"
|
hcrt_brightness = "0.150000"
|
||||||
hcrt_colour_system = "0.000000"
|
hcrt_colour_system = "0.000000"
|
||||||
hcrt_white_temperature = "2800.000000"
|
hcrt_white_temperature = "2800.000000"
|
||||||
|
|
|
@ -33,8 +33,8 @@ layout(push_constant) uniform Push
|
||||||
float hcrt_paper_white_nits;
|
float hcrt_paper_white_nits;
|
||||||
float hcrt_lcd_resolution;
|
float hcrt_lcd_resolution;
|
||||||
float hcrt_lcd_subpixel;
|
float hcrt_lcd_subpixel;
|
||||||
float hcrt_brightness;
|
float hcrt_colour_system;
|
||||||
float hcrt_contrast;
|
float hcrt_colour_space;
|
||||||
float hcrt_expand_gamut;
|
float hcrt_expand_gamut;
|
||||||
float hcrt_red_vertical_convergence;
|
float hcrt_red_vertical_convergence;
|
||||||
float hcrt_green_vertical_convergence;
|
float hcrt_green_vertical_convergence;
|
||||||
|
@ -76,9 +76,10 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
vec4 OutputSize;
|
vec4 OutputSize;
|
||||||
uint FrameCount;
|
uint FrameCount;
|
||||||
|
|
||||||
float hcrt_colour_system;
|
|
||||||
float hcrt_colour_space;
|
|
||||||
float hcrt_white_temperature;
|
float hcrt_white_temperature;
|
||||||
|
float hcrt_brightness;
|
||||||
|
float hcrt_contrast;
|
||||||
|
float hcrt_saturation;
|
||||||
float hcrt_gamma;
|
float hcrt_gamma;
|
||||||
} global;
|
} global;
|
||||||
|
|
||||||
|
@ -96,14 +97,12 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
#pragma parameter hcrt_instructions3 "SCALING: Apect Ratio: Core Provided" 0.0 0.0 0.0001 0.0
|
#pragma parameter hcrt_instructions3 "SCALING: Apect Ratio: Core Provided" 0.0 0.0 0.0001 0.0
|
||||||
#pragma parameter hcrt_space2 " " 0.0 0.0 0.0001 0.0
|
#pragma parameter hcrt_space2 " " 0.0 0.0 0.0001 0.0
|
||||||
#pragma parameter hcrt_user_settings "USER SETTINGS:" 0.0 0.0 0.0001 0.0
|
#pragma parameter hcrt_user_settings "USER SETTINGS:" 0.0 0.0 0.0001 0.0
|
||||||
#pragma parameter hcrt_hdr " SDR | HDR" 1.0 0.0 1.0 1.0
|
#pragma parameter hcrt_hdr " HDR | SDR" 0.0 0.0 1.0 1.0
|
||||||
#pragma parameter hcrt_max_nits " Display's Peak Luminance" 700.0 0.0 10000.0 10.0
|
#pragma parameter hcrt_max_nits " HDR: Display's Peak Luminance" 700.0 0.0 10000.0 10.0
|
||||||
#pragma parameter hcrt_paper_white_nits " Display's Paper White Luminance" 700.0 0.0 10000.0 10.0
|
#pragma parameter hcrt_paper_white_nits " HDR: Display's Paper White Luminance" 700.0 0.0 10000.0 10.0
|
||||||
|
#pragma parameter hcrt_colour_space " SDR: Display's Colour Space: sRGB | DCI-P3" 0.0 0.0 1.0 1.0
|
||||||
#pragma parameter hcrt_lcd_resolution " Display's Resolution: 4K | 8K" 0.0 0.0 1.0 1.0
|
#pragma parameter hcrt_lcd_resolution " Display's Resolution: 4K | 8K" 0.0 0.0 1.0 1.0
|
||||||
#pragma parameter hcrt_lcd_subpixel " Display's Subpixel Layout: RGB | BGR" 0.0 0.0 1.0 1.0
|
#pragma parameter hcrt_lcd_subpixel " Display's Subpixel Layout: RGB | BGR" 0.0 0.0 1.0 1.0
|
||||||
#pragma parameter hcrt_brightness " Brightness" 0.0 -1.0 1.0 0.01
|
|
||||||
#pragma parameter hcrt_contrast " Contrast" 0.0 -1.0 1.0 0.01
|
|
||||||
#pragma parameter hcrt_gamma " Gamma" 0.0 -1.0 1.0 0.01
|
|
||||||
#pragma parameter hcrt_red_vertical_convergence " Red Vertical Convergence" 0.00 -10.0 10.0 0.01
|
#pragma parameter hcrt_red_vertical_convergence " Red Vertical Convergence" 0.00 -10.0 10.0 0.01
|
||||||
#pragma parameter hcrt_green_vertical_convergence " Green Vertical Convergence" 0.00 -10.0 10.0 0.01
|
#pragma parameter hcrt_green_vertical_convergence " Green Vertical Convergence" 0.00 -10.0 10.0 0.01
|
||||||
#pragma parameter hcrt_blue_vertical_convergence " Blue Vertical Convergence" 0.00 -10.0 10.0 0.01
|
#pragma parameter hcrt_blue_vertical_convergence " Blue Vertical Convergence" 0.00 -10.0 10.0 0.01
|
||||||
|
@ -116,9 +115,12 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
#pragma parameter hcrt_crt_screen_type " CRT Type: APERTURE GRILLE | SHADOW MASK | SLOT MASK" 0.0 0.0 2.0 1.0
|
#pragma parameter hcrt_crt_screen_type " CRT Type: APERTURE GRILLE | SHADOW MASK | SLOT MASK" 0.0 0.0 2.0 1.0
|
||||||
#pragma parameter hcrt_crt_resolution " CRT Resolution: 600TVL | 800TVL | 1000TVL" 0.0 0.0 2.0 1.0
|
#pragma parameter hcrt_crt_resolution " CRT Resolution: 600TVL | 800TVL | 1000TVL" 0.0 0.0 2.0 1.0
|
||||||
#pragma parameter hcrt_colour_system " CRT Colour System: PAL | NTSC-U | NTSC-J" 1.0 0.0 2.0 1.0
|
#pragma parameter hcrt_colour_system " CRT Colour System: PAL | NTSC-U | NTSC-J" 1.0 0.0 2.0 1.0
|
||||||
#pragma parameter hcrt_colour_space " Colour Space: Rec.601/Rec.709 | sRGB" 0.0 0.0 1.0 1.0
|
|
||||||
#pragma parameter hcrt_white_temperature " White Point: (PAL:D65, NTSC-U:D65, NTSC-J:D93)" 0.0 -5000.0 12000.0 100.0
|
#pragma parameter hcrt_white_temperature " White Point: (PAL:D65, NTSC-U:D65, NTSC-J:D93)" 0.0 -5000.0 12000.0 100.0
|
||||||
#pragma parameter hcrt_expand_gamut " Original/Vivid" 0.0 0.0 1.0 1.0
|
#pragma parameter hcrt_expand_gamut " HDR: Original/Vivid" 0.0 0.0 1.0 1.0
|
||||||
|
#pragma parameter hcrt_brightness " Brightness" 0.0 -1.0 1.0 0.01
|
||||||
|
#pragma parameter hcrt_contrast " Contrast" 0.0 -1.0 1.0 0.01
|
||||||
|
#pragma parameter hcrt_saturation " Saturation" 0.0 -1.0 1.0 0.01
|
||||||
|
#pragma parameter hcrt_gamma " Gamma" 0.0 -1.0 1.0 0.01
|
||||||
|
|
||||||
#pragma parameter hcrt_developer_settings0 " VERTICAL SETTINGS:" 0.0 0.0 0.0001 0.0
|
#pragma parameter hcrt_developer_settings0 " VERTICAL SETTINGS:" 0.0 0.0 0.0001 0.0
|
||||||
#pragma parameter hcrt_red_scanline_min " Red Scanline Min" 0.50 0.0 2.0 0.01
|
#pragma parameter hcrt_red_scanline_min " Red Scanline Min" 0.50 0.0 2.0 0.01
|
||||||
|
@ -144,8 +146,6 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
#define HCRT_PAPER_WHITE_NITS params.hcrt_paper_white_nits
|
#define HCRT_PAPER_WHITE_NITS params.hcrt_paper_white_nits
|
||||||
#define HCRT_LCD_RESOLUTION params.hcrt_lcd_resolution
|
#define HCRT_LCD_RESOLUTION params.hcrt_lcd_resolution
|
||||||
#define HCRT_LCD_SUBPIXEL params.hcrt_lcd_subpixel
|
#define HCRT_LCD_SUBPIXEL params.hcrt_lcd_subpixel
|
||||||
#define HCRT_BRIGHTNESS params.hcrt_brightness
|
|
||||||
#define HCRT_CONTRAST params.hcrt_contrast
|
|
||||||
#define HCRT_EXPAND_GAMUT params.hcrt_expand_gamut
|
#define HCRT_EXPAND_GAMUT params.hcrt_expand_gamut
|
||||||
#define HCRT_RED_VERTICAL_CONVERGENCE params.hcrt_red_vertical_convergence
|
#define HCRT_RED_VERTICAL_CONVERGENCE params.hcrt_red_vertical_convergence
|
||||||
#define HCRT_GREEN_VERTICAL_CONVERGENCE params.hcrt_green_vertical_convergence
|
#define HCRT_GREEN_VERTICAL_CONVERGENCE params.hcrt_green_vertical_convergence
|
||||||
|
@ -156,9 +156,12 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
|
|
||||||
#define HCRT_CRT_SCREEN_TYPE params.hcrt_crt_screen_type
|
#define HCRT_CRT_SCREEN_TYPE params.hcrt_crt_screen_type
|
||||||
#define HCRT_CRT_RESOLUTION params.hcrt_crt_resolution
|
#define HCRT_CRT_RESOLUTION params.hcrt_crt_resolution
|
||||||
#define HCRT_CRT_COLOUR_SPACE global.hcrt_colour_space
|
#define HCRT_CRT_COLOUR_SYSTEM params.hcrt_colour_system
|
||||||
#define HCRT_CRT_COLOUR_SYSTEM global.hcrt_colour_system
|
#define HCRT_OUTPUT_COLOUR_SPACE params.hcrt_colour_space
|
||||||
#define HCRT_WHITE_TEMPERATURE global.hcrt_white_temperature
|
#define HCRT_WHITE_TEMPERATURE global.hcrt_white_temperature
|
||||||
|
#define HCRT_BRIGHTNESS global.hcrt_brightness
|
||||||
|
#define HCRT_CONTRAST global.hcrt_contrast
|
||||||
|
#define HCRT_SATURATION global.hcrt_saturation
|
||||||
#define HCRT_GAMMA global.hcrt_gamma
|
#define HCRT_GAMMA global.hcrt_gamma
|
||||||
|
|
||||||
#define HCRT_RED_SCANLINE_MIN params.hcrt_red_scanline_min
|
#define HCRT_RED_SCANLINE_MIN params.hcrt_red_scanline_min
|
||||||
|
@ -401,20 +404,46 @@ float Bezier(const float t0, const vec4 control_points)
|
||||||
return dot(t, control_points * kCubicBezier);
|
return dot(t, control_points * kCubicBezier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SDR Colour output spaces
|
||||||
|
float sRGBToLinear_1(const float channel)
|
||||||
|
{
|
||||||
|
return (channel > 0.04045f) ? pow((channel + 0.055f) * (1.0f / 1.055f), 2.4f + HCRT_GAMMA) : channel * (1.0f / 12.92f);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 sRGBToLinear(const vec3 colour)
|
||||||
|
{
|
||||||
|
return vec3(sRGBToLinear_1(colour.r), sRGBToLinear_1(colour.g), sRGBToLinear_1(colour.b));
|
||||||
|
}
|
||||||
|
|
||||||
|
float LinearTosRGB_1(const float channel)
|
||||||
|
{
|
||||||
|
return (channel > 0.0031308f) ? (1.055f * pow(channel, 1.0f / 2.4f)) - 0.055f : channel * 12.92f;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 LinearTosRGB(const vec3 colour)
|
||||||
|
{
|
||||||
|
return vec3(LinearTosRGB_1(colour.r), LinearTosRGB_1(colour.g), LinearTosRGB_1(colour.b));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 LinearToDCIP3(const vec3 colour)
|
||||||
|
{
|
||||||
|
return pow(colour, vec3(1.0f / 2.6f));
|
||||||
|
}
|
||||||
|
|
||||||
#include "include\hdr10.h"
|
#include "include\hdr10.h"
|
||||||
#include "include\inverse_tonemap.h"
|
#include "include\inverse_tonemap.h"
|
||||||
#include "include\colour_grade.h"
|
#include "include\colour_grade.h"
|
||||||
#include "include\scanline_generation.h"
|
#include "include\scanline_generation.h"
|
||||||
|
|
||||||
vec3 Hdr10Conditional(const vec3 scanline_colour)
|
vec3 GammaCorrect(const vec3 scanline_colour)
|
||||||
{
|
{
|
||||||
if(HCRT_HDR > 0.0f)
|
if(HCRT_HDR > 0.0f)
|
||||||
{
|
{
|
||||||
return Hdr10(scanline_colour, HCRT_PAPER_WHITE_NITS, HCRT_EXPAND_GAMUT);
|
return HCRT_OUTPUT_COLOUR_SPACE == 0.0f ? LinearTosRGB(scanline_colour) : LinearToDCIP3(scanline_colour);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return scanline_colour;
|
return Hdr10(scanline_colour, HCRT_PAPER_WHITE_NITS, HCRT_EXPAND_GAMUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,8 +496,7 @@ void main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const vec3 hdr10 = Hdr10Conditional(scanline_colour);
|
const vec3 hdr10 = GammaCorrect(scanline_colour);
|
||||||
|
|
||||||
//FragColor = vec4(scanline_colour, 1.0);
|
|
||||||
FragColor = vec4(hdr10, 1.0);
|
FragColor = vec4(hdr10, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,26 +95,6 @@ vec3 LinearTor601r709(const vec3 colour)
|
||||||
return vec3(LinearTor601r709_1(colour.r), LinearTor601r709_1(colour.g), LinearTor601r709_1(colour.b));
|
return vec3(LinearTor601r709_1(colour.r), LinearTor601r709_1(colour.g), LinearTor601r709_1(colour.b));
|
||||||
}
|
}
|
||||||
|
|
||||||
float sRGBToLinear_1(const float channel)
|
|
||||||
{
|
|
||||||
return (channel > 0.04045f) ? pow((channel + 0.055f) * (1.0f / 1.055f), 2.4f + HCRT_GAMMA) : channel * (1.0f / 12.92f);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 sRGBToLinear(const vec3 colour)
|
|
||||||
{
|
|
||||||
return vec3(sRGBToLinear_1(colour.r), sRGBToLinear_1(colour.g), sRGBToLinear_1(colour.b));
|
|
||||||
}
|
|
||||||
|
|
||||||
float LinearTosRGB_1(const float channel)
|
|
||||||
{
|
|
||||||
return (channel > 0.0031308f) ? (1.055f * pow(channel, 1.0f / 2.4f)) - 0.055f : channel * 12.92f;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 LinearTosRGB(const vec3 colour)
|
|
||||||
{
|
|
||||||
return vec3(LinearTosRGB_1(colour.r), LinearTosRGB_1(colour.g), LinearTosRGB_1(colour.b));
|
|
||||||
}
|
|
||||||
|
|
||||||
// XYZ Yxy transforms found in Dogway's Grade.slang shader
|
// XYZ Yxy transforms found in Dogway's Grade.slang shader
|
||||||
|
|
||||||
vec3 XYZtoYxy(const vec3 XYZ)
|
vec3 XYZtoYxy(const vec3 XYZ)
|
||||||
|
@ -165,11 +145,19 @@ float Contrast(const float luminance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec3 Saturation(const vec3 colour)
|
||||||
|
{
|
||||||
|
const float luma = dot(colour, vec3(0.2125, 0.7154, 0.0721));
|
||||||
|
const float saturation = 0.5f + HCRT_SATURATION * 0.5f;
|
||||||
|
|
||||||
|
return clamp(mix(vec3(luma), colour, vec3(saturation) * 2.0f), 0.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
vec3 ColourGrade(const vec3 colour)
|
vec3 ColourGrade(const vec3 colour)
|
||||||
{
|
{
|
||||||
const uint colour_system = uint(HCRT_CRT_COLOUR_SYSTEM);
|
const uint colour_system = uint(HCRT_CRT_COLOUR_SYSTEM);
|
||||||
|
|
||||||
const vec3 linear = HCRT_CRT_COLOUR_SPACE == 0.0f ? r601r709ToLinear(colour) : sRGBToLinear(colour);
|
const vec3 linear = r601r709ToLinear(colour);
|
||||||
|
|
||||||
const vec3 xyz = sRGB_to_XYZ * linear;
|
const vec3 xyz = sRGB_to_XYZ * linear;
|
||||||
const vec3 Yxy = XYZtoYxy(xyz);
|
const vec3 Yxy = XYZtoYxy(xyz);
|
||||||
|
@ -183,7 +171,9 @@ vec3 ColourGrade(const vec3 colour)
|
||||||
const vec3 contrast_xyz = YxytoXYZ(contrast_linear);
|
const vec3 contrast_xyz = YxytoXYZ(contrast_linear);
|
||||||
const vec3 contrast = clamp(XYZ_to_sRGB * contrast_xyz, 0.0f, 1.0f);
|
const vec3 contrast = clamp(XYZ_to_sRGB * contrast_xyz, 0.0f, 1.0f);
|
||||||
|
|
||||||
const vec3 gamut = kPhosphorGamut[colour_system] * contrast;
|
const vec3 saturation = Saturation(contrast);
|
||||||
|
|
||||||
|
const vec3 gamut = kPhosphorGamut[colour_system] * saturation;
|
||||||
|
|
||||||
const vec3 white_point = WhiteBalance(kTemperatures[colour_system] + HCRT_WHITE_TEMPERATURE, gamut);
|
const vec3 white_point = WhiteBalance(kTemperatures[colour_system] + HCRT_WHITE_TEMPERATURE, gamut);
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,11 @@ vec3 InverseTonemapConditional(const vec3 linear)
|
||||||
{
|
{
|
||||||
if(HCRT_HDR > 0.0f)
|
if(HCRT_HDR > 0.0f)
|
||||||
{
|
{
|
||||||
return InverseTonemap(linear, HCRT_MAX_NITS, HCRT_PAPER_WHITE_NITS, kLumaRatio);
|
return linear;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return linear;
|
return InverseTonemap(linear, HCRT_MAX_NITS, HCRT_PAPER_WHITE_NITS, kLumaRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue