Skip to content

Commit da98e83

Browse files
committed
conditional vertex inputs
1 parent 16eb5d0 commit da98e83

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

assets/shaders/pmfx_utility.pmfx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct vs_input_multi
6868
}
6969
};
7070

71-
struct vs_input_instance_multi
71+
struct vs_instance_input_multi
7272
{
7373
if:(INSTANCED)
7474
{
@@ -79,11 +79,6 @@ struct vs_input_instance_multi
7979
float4 user_data : TEXCOORD10;
8080
float4 user_data2 : TEXCOORD11;
8181
}
82-
83-
if:(!INSTANCED)
84-
{
85-
float4 pad : TEXCOORD6;
86-
}
8782
};
8883

8984
struct ps_output
@@ -118,7 +113,7 @@ declare_texture_samplers
118113

119114
// Vertex Shaders -----------------------------------------------------------------------------------------------------------
120115

121-
vs_output vs_multi( vs_input_multi input, vs_instance_multi instance_input )
116+
vs_output vs_multi( vs_input_multi input, vs_instance_input_multi instance_input )
122117
{
123118
vs_output output;
124119

tools/build_scripts/build_shaders.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,29 @@ def replace_conditional_blocks(source):
878878
return source
879879

880880

881+
def us(v):
882+
if v == -1:
883+
return 65535
884+
return v
885+
886+
887+
def strip_empty_vs_inputs(vs_input, vs_main):
888+
conditioned = vs_input.replace("\n", "").replace(";", "").replace(";", "").replace("}", "").replace("{", "")
889+
tokens = conditioned.split(" ")
890+
for t in tokens:
891+
if t == "":
892+
tokens.remove(t)
893+
if len(tokens) == 2:
894+
# input is empty so remove from vs_main args
895+
vs_input = ""
896+
name = tokens[1]
897+
pos = vs_main.find(name)
898+
prev_delim = max(us(vs_main[:pos].rfind(",")), us(vs_main[:pos].rfind("(")))
899+
next_delim = pos + min(us(vs_main[pos:].find(",")), us(vs_main[pos:].find(")")))
900+
vs_main = vs_main.replace(vs_main[prev_delim:next_delim], " ")
901+
return vs_input, vs_main
902+
903+
881904
def create_vsc_psc(filename, shader_file_text, vs_name, ps_name, technique_name, permutation):
882905
mf = open(macros_file)
883906
macros_text = mf.read()
@@ -936,8 +959,12 @@ def create_vsc_psc(filename, shader_file_text, vs_name, ps_name, technique_name,
936959
vs_input_source = find_struct(shader_file_text, "struct " + vs_vertex_input_struct_name)
937960

938961
# evaluate conditional inputs
939-
instance_input_source = evaluate_conditional_blocks(instance_input_source, permutation)
940962
vs_input_source = evaluate_conditional_blocks(vs_input_source, permutation)
963+
instance_input_source = evaluate_conditional_blocks(instance_input_source, permutation)
964+
965+
# remove empty inputs
966+
vs_input_source, vs_main = strip_empty_vs_inputs(vs_input_source, vs_main)
967+
instance_input_source, vs_main = strip_empty_vs_inputs(instance_input_source, vs_main)
941968

942969
vs_output_source = find_struct(shader_file_text, "struct " + vs_output_struct_name)
943970
ps_output_source = find_struct(shader_file_text, "struct " + ps_output_struct_name)

0 commit comments

Comments
 (0)