OpenTTD Source 20261112-master-gbcbec5e63f
hlsl_shader.h File Reference

HLSL shader programs. More...

Go to the source code of this file.

Macros

#define _hlsl_cbuffer   R"STR( cbuffer UniformConstantBuffer : register(b0) { float4 sprite; float2 screen; float zoom; bool rgb; bool crash; };)STR"
 Defines a constant buffer for HLSL shaders that contains the sprite position, screen size, zoom level, and flags for RGB and crash mode.
#define _frag_shader_remap_func_hlsl   R"STR( float max3(float3 v) { return max(max(v.x, v.y), v.z); } float3 adj_brightness(float3 colour, float3 brightness) { float3 adj = colour * (brightness > 0.0 ? brightness / 0.5 : 1.0); float3 ob_vec = clamp(adj - 1.0, 0.0, 1.0); float ob = (ob_vec.r + ob_vec.g + ob_vec.b) / 2.0; return clamp(adj + ob * (1.0 - adj), 0.0, 1.0); })STR"
 Pixel shader function for remap brightness modulation.

Variables

static const char _vertex_shader_sprite_hlsl []
 HLSL vertex shader that positions a sprite on screen.
static const char _frag_shader_direct_hlsl []
 HLSL pixel shader that reads the fragment colour from a 32bpp texture.
static const char _frag_shader_palette_hlsl []
 HLSL pixel shader that reads the fragment colour from a 32bpp texture.
static const char _frag_shader_rgb_mask_blend_hlsl []
 HLSL pixel shader that performs a palette lookup to read the colour from an 8bpp texture.
static const char _frag_shader_sprite_blend_hlsl []
 HLSL pixel shader that performs a palette lookup to read the colour from a sprite texture.

Detailed Description

HLSL shader programs.

Definition in file hlsl_shader.h.

Macro Definition Documentation

◆ _frag_shader_remap_func_hlsl

#define _frag_shader_remap_func_hlsl   R"STR( float max3(float3 v) { return max(max(v.x, v.y), v.z); } float3 adj_brightness(float3 colour, float3 brightness) { float3 adj = colour * (brightness > 0.0 ? brightness / 0.5 : 1.0); float3 ob_vec = clamp(adj - 1.0, 0.0, 1.0); float ob = (ob_vec.r + ob_vec.g + ob_vec.b) / 2.0; return clamp(adj + ob * (1.0 - adj), 0.0, 1.0); })STR"

Pixel shader function for remap brightness modulation.

Definition at line 95 of file hlsl_shader.h.

◆ _hlsl_cbuffer

#define _hlsl_cbuffer   R"STR( cbuffer UniformConstantBuffer : register(b0) { float4 sprite; float2 screen; float zoom; bool rgb; bool crash; };)STR"

Defines a constant buffer for HLSL shaders that contains the sprite position, screen size, zoom level, and flags for RGB and crash mode.

Definition at line 13 of file hlsl_shader.h.

Variable Documentation

◆ _frag_shader_direct_hlsl

const char _frag_shader_direct_hlsl[]
static
Initial value:
=
R"STR(
uniform Texture2D colour_tex : register(t0);
uniform SamplerState texture_sampler : register(s0);
struct vs_out
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
};
float4 ps_main(vs_out input) : SV_TARGET
{
return colour_tex.Sample(texture_sampler, input.texcoord);
};
)STR"

HLSL pixel shader that reads the fragment colour from a 32bpp texture.

Definition at line 57 of file hlsl_shader.h.

Referenced by VideoDriver_Win32D3D11::InitD3D().

◆ _frag_shader_palette_hlsl

const char _frag_shader_palette_hlsl[]
static
Initial value:
=
R"STR(
uniform Texture2D colour_tex : register(t0);
uniform Texture1D palette : register(t1);
uniform SamplerState texture_sampler : register(s0);
struct vs_out
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
};
float4 ps_main(vs_out input) : SV_TARGET
{
float idx = colour_tex.Sample(texture_sampler, input.texcoord).x;
return palette.Sample(texture_sampler, idx);
};
)STR"

HLSL pixel shader that reads the fragment colour from a 32bpp texture.

Definition at line 75 of file hlsl_shader.h.

Referenced by VideoDriver_Win32D3D11::InitD3D().

◆ _frag_shader_rgb_mask_blend_hlsl

const char _frag_shader_rgb_mask_blend_hlsl[]
static
Initial value:
=
R"STR(
uniform Texture2D colour_tex : register(t0);
uniform Texture1D palette : register(t1);
uniform Texture2D remap_tex : register(t2);
uniform SamplerState texture_sampler : register(s0);
struct vs_out
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
};
float4 ps_main(vs_out input) : SV_TARGET
{
float idx = remap_tex.SampleLevel(texture_sampler, input.texcoord, zoom).r;
float4 remap_col = palette.Sample(texture_sampler, idx);
float4 rgb_col = colour_tex.SampleLevel(texture_sampler, input.texcoord, zoom);
float4 output;
output.a = rgb ? rgb_col.a : remap_col.a;
output.rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;
return output;
};
)STR"
#define _hlsl_cbuffer
Defines a constant buffer for HLSL shaders that contains the sprite position, screen size,...
Definition hlsl_shader.h:13
#define _frag_shader_remap_func_hlsl
Pixel shader function for remap brightness modulation.
Definition hlsl_shader.h:95

HLSL pixel shader that performs a palette lookup to read the colour from an 8bpp texture.

Definition at line 112 of file hlsl_shader.h.

Referenced by VideoDriver_Win32D3D11::InitD3D().

◆ _frag_shader_sprite_blend_hlsl

const char _frag_shader_sprite_blend_hlsl[]
static

HLSL pixel shader that performs a palette lookup to read the colour from a sprite texture.

Definition at line 142 of file hlsl_shader.h.

Referenced by VideoDriver_Win32D3D11::InitD3D().

◆ _vertex_shader_sprite_hlsl

const char _vertex_shader_sprite_hlsl[]
static
Initial value:
=
R"STR(
struct vs_out
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
};
static const float4 vert_array[] = {
// x y u v
float4( 1.0, -1.0, 1.0, 1.0),
float4(-1.0, -1.0, 0.0, 1.0),
float4( 1.0, 1.0, 1.0, 0.0),
float4(-1.0, 1.0, 0.0, 0.0)
};
vs_out vs_main(uint id: SV_VertexID)
{
float2 size = sprite.zw / screen.xy;
float2 offset = ((2.0 * sprite.xy + sprite.zw) / screen.xy - 1.0) * float2(1.0, -1.0);
vs_out output;
output.texcoord = vert_array[id].zw;
output.position = float4(vert_array[id].xy * size + offset, 0.0, 1.0);
return output;
};
)STR"

HLSL vertex shader that positions a sprite on screen.

Definition at line 26 of file hlsl_shader.h.

Referenced by VideoDriver_Win32D3D11::InitD3D().