Clean up a little bit of API code. Fix an issue with missing operator. Port random semi complex shader.

This commit is contained in:
2025-08-21 22:22:00 +02:00
parent 01ffe9c73d
commit 45f67e16a8
5 changed files with 197 additions and 20 deletions

View File

@@ -0,0 +1,93 @@
float4 apply_night(float4 color);
float4 apply_twilight(float4 color);
float4 apply_morning(float4 color);
float4 apply_dawn(float4 color);
cbuffer __PROPERTIES : register(b0)
{
float __PROPERTIES__hour_of_day;
}
Texture2D __PROPERTIES__input_tex : register(t0);
SamplerState __PROPERTIES__tex_sampler : register(s0);
struct VS_Input
{
float3 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct VS_Output
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
VS_Output vs_main(VS_Input input)
{
VS_Output output;
output.pos = float4(input.pos, 1.0f);
output.uv = input.uv;
return output;
}
float4 apply_night(float4 color)
{
float4 result = color;
(result -= float4(0.3f, 0.2f, 0.0f, 0.0f));
(result *= 0.8f);
return result;
}
float4 apply_twilight(float4 color)
{
float4 result = color;
(result += float4(0.2f, -0.1f, 0.1f, 0.0f));
(result *= 0.9f);
return result;
}
float4 apply_morning(float4 color)
{
return (color * 1.3f);
}
float4 apply_dawn(float4 color)
{
return color;
}
float4 ps_main(VS_Output input)
{
float4 sampled_color = __PROPERTIES__input_tex.Sample(__PROPERTIES__tex_sampler, input.uv);
float t = 0.0f;
float4 a = float4(0, 0, 0, 0);
float4 b = float4(0, 0, 0, 0);
if (__PROPERTIES__hour_of_day > 16)
{
t = ((__PROPERTIES__hour_of_day - 16) / 6);
a = apply_twilight(sampled_color);
b = apply_night(sampled_color);
}
else if (__PROPERTIES__hour_of_day > 12)
{
t = ((__PROPERTIES__hour_of_day - 12) / 6);
a = sampled_color;
b = apply_twilight(sampled_color);
}
else if (__PROPERTIES__hour_of_day > 6)
{
t = ((__PROPERTIES__hour_of_day - 6) / 6);
a = apply_morning(sampled_color);
b = sampled_color;
}
else if (__PROPERTIES__hour_of_day >= 0)
{
t = (__PROPERTIES__hour_of_day / 6);
a = apply_night(sampled_color);
b = apply_morning(sampled_color);
}
return lerp(a, b, t);
}

78
test/night_time.ink Normal file
View File

@@ -0,0 +1,78 @@
p :: properties {
input_tex : Texture2D;
tex_sampler : Sampler;
hour_of_day : float;
}
VS_Input :: struct {
pos : float3 @position;
uv : float2 @uv;
}
VS_Output :: struct {
pos : float4 @outposition;
uv : float2 @uv;
}
vertex main :: (input : VS_Input) -> VS_Output {
output : VS_Output;
output.pos = float4(input.pos, 1.0);
output.uv = input.uv;
return output;
}
apply_night :: (color : float4) -> float4 {
result := color;
result -= float4(0.3, 0.2, 0.0, 0.0);
result *= 0.8;
return result;
}
apply_twilight :: (color : float4) -> float4 {
result := color;
result += float4(0.2, -0.1, 0.1, 0.0);
result *= 0.9;
return result;
}
apply_morning :: (color : float4) -> float4 {
return color * 1.3;
}
apply_dawn :: (color : float4) -> float4 {
return color;
}
pixel main :: (input : VS_Output) -> float4 @outposition {
sampled_color : float4 = sample(p.input_tex, p.tex_sampler, input.uv);
t := 0.0;
a := float4(0, 0, 0, 0);
b := float4(0, 0, 0, 0);
if p.hour_of_day > 16 {
t = (p.hour_of_day - 16) / 6;
a = apply_twilight(sampled_color);
b = apply_night(sampled_color);
} else if p.hour_of_day > 12 {
t = (p.hour_of_day - 12) / 6;
a = sampled_color;
b = apply_twilight(sampled_color);
} else if p.hour_of_day > 6 {
t = (p.hour_of_day - 6) / 6;
a = apply_morning(sampled_color);
b = sampled_color;
} else if p.hour_of_day >= 0 {
t = p.hour_of_day / 6;
a = apply_night(sampled_color);
b = apply_morning(sampled_color);
}
return lerp(a, b, t);
}