Clean up a little bit of API code. Fix an issue with missing operator. Port random semi complex shader.
This commit is contained in:
@@ -514,6 +514,8 @@ binary :: (parse_state : *Parse_State, left : *AST_Node) -> *AST_Node {
|
|||||||
case .TOKEN_PLUS; #through;
|
case .TOKEN_PLUS; #through;
|
||||||
case .TOKEN_PLUSEQUALS; #through;
|
case .TOKEN_PLUSEQUALS; #through;
|
||||||
case .TOKEN_MINUSEQUALS; #through;
|
case .TOKEN_MINUSEQUALS; #through;
|
||||||
|
case .TOKEN_TIMESEQUALS; #through;
|
||||||
|
case .TOKEN_DIVEQUALS; #through;
|
||||||
case .TOKEN_MINUS; #through;
|
case .TOKEN_MINUS; #through;
|
||||||
case .TOKEN_STAR; #through;
|
case .TOKEN_STAR; #through;
|
||||||
case .TOKEN_SLASH; #through;
|
case .TOKEN_SLASH; #through;
|
||||||
|
|||||||
@@ -1448,13 +1448,13 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
|
|||||||
case .TOKEN_MINUS; #through;
|
case .TOKEN_MINUS; #through;
|
||||||
case .TOKEN_STAR; #through;
|
case .TOKEN_STAR; #through;
|
||||||
case .TOKEN_SLASH; {
|
case .TOKEN_SLASH; {
|
||||||
if !types_compatible(checker, lhs_var, rhs_var, true) {
|
if !types_compatible(checker, lhs_var, rhs_var) {
|
||||||
type_mismatch(checker, node, node.children[1], lhs_var, rhs_var);
|
type_mismatch(checker, node, node.children[1], lhs_var, rhs_var);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .TOKEN_ASSIGN; {
|
case .TOKEN_ASSIGN; {
|
||||||
if !types_compatible(checker, lhs_var, rhs_var, true) {
|
if !types_compatible(checker, lhs_var, rhs_var) {
|
||||||
type_mismatch(checker, node.parent, node.children[1], lhs_var, rhs_var);
|
type_mismatch(checker, node.parent, node.children[1], lhs_var, rhs_var);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1611,7 +1611,6 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
|
|||||||
case .Struct; {
|
case .Struct; {
|
||||||
lhs_node := lhs_var.source_node;
|
lhs_node := lhs_var.source_node;
|
||||||
rhs_node := rhs_var.source_node;
|
rhs_node := rhs_var.source_node;
|
||||||
|
|
||||||
if rhs_var.type != .Struct && !param_matching {
|
if rhs_var.type != .Struct && !param_matching {
|
||||||
if lhs_var.typename == {
|
if lhs_var.typename == {
|
||||||
case "float2"; #through;
|
case "float2"; #through;
|
||||||
@@ -1626,7 +1625,6 @@ types_compatible :: (checker : *Semantic_Checker, lhs : Type_Variable_Handle, rh
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lhs_struct := find_symbol(checker, lhs_var.typename, xx 1);
|
lhs_struct := find_symbol(checker, lhs_var.typename, xx 1);
|
||||||
rhs_struct := find_symbol(checker, rhs_var.typename, xx 1);
|
rhs_struct := find_symbol(checker, rhs_var.typename, xx 1);
|
||||||
|
|
||||||
|
|||||||
38
module.jai
38
module.jai
@@ -400,22 +400,7 @@ type_variable_to_field :: (checker : *Semantic_Checker, variable : *Type_Variabl
|
|||||||
return type_variable_to_field(checker.result_file.type_variables, checker.result_file.scope_stack, variable);
|
return type_variable_to_field(checker.result_file.type_variables, checker.result_file.scope_stack, variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Result {
|
generate_output_data :: (result : *Compile_Result) {
|
||||||
result : Compile_Result;
|
|
||||||
|
|
||||||
for path : paths {
|
|
||||||
add_file(*result, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
lex(*result);
|
|
||||||
parse(*result);
|
|
||||||
check(*result);
|
|
||||||
codegen(*result);
|
|
||||||
|
|
||||||
if result.had_error {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
for *file : result.files {
|
for *file : result.files {
|
||||||
if file.vertex_entry_point.node {
|
if file.vertex_entry_point.node {
|
||||||
file.vertex_entry_point.name = file.vertex_entry_point.node.name;
|
file.vertex_entry_point.name = file.vertex_entry_point.node.name;
|
||||||
@@ -498,6 +483,27 @@ compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Resul
|
|||||||
file.pixel_entry_point.return_value = field;
|
file.pixel_entry_point.return_value = field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
compile_file :: (compiler : *Shader_Compiler, paths : []string) -> Compile_Result {
|
||||||
|
result : Compile_Result;
|
||||||
|
|
||||||
|
for path : paths {
|
||||||
|
add_file(*result, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
lex(*result);
|
||||||
|
parse(*result);
|
||||||
|
check(*result);
|
||||||
|
codegen(*result);
|
||||||
|
|
||||||
|
if result.had_error {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_output_data(*result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
93
test/codegen/night_time.golden
Normal file
93
test/codegen/night_time.golden
Normal 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
78
test/night_time.ink
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user