Skip to content

Commit f1e3c2c

Browse files
committed
moving over to permutations
1 parent b8f10ea commit f1e3c2c

File tree

6 files changed

+359
-96
lines changed

6 files changed

+359
-96
lines changed

.clang-format

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ UseTab: Never
2424
NamespaceIndentation: All
2525
PointerAlignment: Left
2626
AlignConsecutiveDeclarations: 'true'
27-
AlignConsecutiveAssignments: 'true'
27+
AlignConsecutiveAssignments: 'false'
2828
IndentCaseLabels: 'true'
29-
29+
ReflowComments: 'false'
3030
...

assets/shaders/forward_render.pmfx

+74-28
Original file line numberDiff line numberDiff line change
@@ -235,30 +235,66 @@ vs_output vs_main_multi( vs_input_multi input, vs_instance_input instance_input
235235
vs_output output;
236236

237237
float4x4 wvp = mul( world_matrix, vp_matrix );
238+
float4x4 wm = world_matrix;
238239

239-
output.position = mul( input.position, wvp );
240-
output.world_pos = mul( input.position, world_matrix );
240+
if:(INSTANCED)
241+
{
242+
float4x4 instance_world_mat;
243+
unpack_vb_instance_mat(
244+
instance_world_mat,
245+
instance_input.world_matrix_0,
246+
instance_input.world_matrix_1,
247+
instance_input.world_matrix_2,
248+
instance_input.world_matrix_3
249+
);
250+
251+
wvp = mul( instance_world_mat, vp_matrix );
252+
wm = instance_world_mat;
253+
254+
output.colour = instance_input.user_data2;
255+
}
241256

242-
float3x3 world_rot_mat = to_3x3(world_matrix);
243-
world_rot_mat[0] = normalize(world_rot_mat[0]);
244-
world_rot_mat[1] = normalize(world_rot_mat[1]);
245-
world_rot_mat[2] = normalize(world_rot_mat[2]);
257+
if:(SKINNED)
258+
{
259+
float4 sp = skin_pos(input.position, input.blend_weights, input.blend_indices);
260+
261+
output.tangent = input.tangent.xyz;
262+
output.bitangent = input.bitangent.xyz;
263+
output.normal = input.normal.xyz;
264+
265+
skin_tbn(output.tangent, output.bitangent, output.normal, input.blend_weights, input.blend_indices);
266+
267+
output.position = mul( sp, vp_matrix );
268+
output.world_pos = sp;
269+
}
270+
271+
if:(!SKINNED)
272+
{
273+
output.position = mul( input.position, wvp );
274+
output.world_pos = mul( input.position, wm );
275+
276+
float3x3 wrm = to_3x3(wm);
277+
wrm[0] = normalize(wrm[0]);
278+
wrm[1] = normalize(wrm[1]);
279+
wrm[2] = normalize(wrm[2]);
280+
281+
output.normal = mul( input.normal.xyz, wrm );
282+
output.tangent = mul( input.tangent.xyz, wrm );
283+
output.bitangent = mul( input.bitangent.xyz, wrm );
284+
285+
output.texcoord = float4(input.texcoord.x, 1.0 - input.texcoord.y,
286+
input.texcoord.z, 1.0 - input.texcoord.w );
287+
}
246288

247-
float3x3 rotation_matrix = world_rot_mat;
248-
249-
output.normal = mul( input.normal.xyz, rotation_matrix );
250-
output.tangent = mul( input.tangent.xyz, rotation_matrix );
251-
output.bitangent = mul( input.bitangent.xyz, rotation_matrix );
252-
253-
output.texcoord = float4(input.texcoord.x, 1.0f - input.texcoord.y,
254-
input.texcoord.z, 1.0f - input.texcoord.w );
255-
256289
if:(UV_SCALE)
257290
{
258291
output.texcoord *= float4(m_uv_scale.x, m_uv_scale.y, m_uv_scale.x, m_uv_scale.y);
259292
}
260293

261-
output.colour = m_albedo;
294+
if:(!INSTANCED)
295+
{
296+
output.colour = m_albedo;
297+
}
262298

263299
return output;
264300
}
@@ -612,21 +648,31 @@ pmfx:
612648
"permutations":
613649
{
614650
"SKINNED": [31, [0,1]],
615-
"INSTANCED": [30, [0,1]]
616-
}
617-
},
618-
619-
"forward_lit_uv_scale":
620-
{
621-
"inherit" : "forward_lit",
622-
"constants":
623-
{
624-
"uv_scale": { "type": "float2", "widget": "slider", "min": 0, "max": 100, "default": 1.0 }
651+
"INSTANCED": [30, [0,1]],
652+
"UV_SCALE": [1, [0,1]],
653+
"SSS": [2, [0,1]],
654+
"SDF_SHADOW": [3, [0,1]]
625655
},
626656

627-
"defines": ["UV_SCALE"]
657+
"constants":
658+
{
659+
"permutation(SSS)":
660+
{
661+
"sss_scale": { "type": "float", "widget": "slider", "min": 0, "max": 500, "default": 1.0 }
662+
},
663+
664+
"permutation(SDF_SHADOW)":
665+
{
666+
"surface_offset": { "type": "float", "widget": "slider", "min": 0, "max": 1, "default": 1.0 }
667+
},
668+
669+
"permutation(UV_SCALE)":
670+
{
671+
"uv_scale": { "type": "float2", "widget": "slider", "min": 0, "max": 100, "default": 1.0 }
672+
}
673+
}
628674
},
629-
675+
630676
"forward_lit_sdf_shadow":
631677
{
632678
"inherit": "forward_lit",

assets/shaders/pmfx_utility.pmfx

-47
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,6 @@ struct vs_instance_input
5353
float4 user_data2 : TEXCOORD11;
5454
};
5555

56-
struct vs_input_multi
57-
{
58-
float4 position : POSITION;
59-
float4 normal : TEXCOORD0;
60-
float4 texcoord : TEXCOORD1;
61-
float4 tangent : TEXCOORD2;
62-
float4 bitangent : TEXCOORD3;
63-
64-
if:(SKINNED)
65-
{
66-
float4 blend_indices : TEXCOORD4;
67-
float4 blend_weights : TEXCOORD5;
68-
}
69-
};
70-
71-
struct vs_instance_input_multi
72-
{
73-
if:(INSTANCED)
74-
{
75-
float4 world_matrix_0 : TEXCOORD6;
76-
float4 world_matrix_1 : TEXCOORD7;
77-
float4 world_matrix_2 : TEXCOORD8;
78-
float4 world_matrix_3 : TEXCOORD9;
79-
float4 user_data : TEXCOORD10;
80-
float4 user_data2 : TEXCOORD11;
81-
}
82-
};
83-
8456
struct ps_output
8557
{
8658
float4 colour : SV_Target;
@@ -113,13 +85,6 @@ declare_texture_samplers
11385

11486
// Vertex Shaders -----------------------------------------------------------------------------------------------------------
11587

116-
vs_output vs_multi( vs_input_multi input, vs_instance_input_multi instance_input )
117-
{
118-
vs_output output;
119-
120-
return output;
121-
}
122-
12388
vs_output vs_main_skinned( vs_input_skinned input )
12489
{
12590
vs_output output;
@@ -680,18 +645,6 @@ pmfx:
680645
"RED": [0, [0,1]],
681646
"GREEN": [1, [0,1]]
682647
}
683-
},
684-
685-
"permutation_vs_input_test":
686-
{
687-
"vs" : "vs_multi",
688-
"ps" : "ps_diffuse",
689-
690-
"permutations":
691-
{
692-
"SKINNED": [0, [0,1]],
693-
"INSTANCED": [1, [0,1]]
694-
}
695648
}
696649
}
697650

0 commit comments

Comments
 (0)