kong test
This commit is contained in:
@@ -39,7 +39,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_add_out(kong, "tex_coord: float2");
|
||||
kong.frag_wvpposition = true;
|
||||
node_shader_add_constant(kong, "VP: float4x4", "_view_proj_matrix");
|
||||
kong.vert_wposition = true;
|
||||
kong.frag_wposition = true;
|
||||
|
||||
let texture_count: i32 = 0;
|
||||
let displace_strength: f32 = make_material_get_displace_strength();
|
||||
@@ -48,10 +48,10 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_write_vert(kong, "var height: float = 0.0;");
|
||||
let num_layers: i32 = 1;
|
||||
let displace_3: string = displace_strength + ", " + displace_strength + ", " + displace_strength;
|
||||
node_shader_write_vert(kong, "\wposition += wnormal * float3(height, height, height) * float3(" + displace_3 + ");");
|
||||
node_shader_write_vert(kong, "\output.wposition += wnormal * float3(height, height, height) * float3(" + displace_3 + ");");
|
||||
}
|
||||
|
||||
node_shader_write_vert(kong, "output.pos = constants.VP * float4(\wposition.xyz, 1.0);");
|
||||
node_shader_write_vert(kong, "output.pos = constants.VP * float4(\output.wposition.xyz, 1.0);");
|
||||
let brush_scale: f32 = context_raw.brush_scale;
|
||||
node_shader_add_constant(kong, "tex_scale: float", "_tex_unpack");
|
||||
node_shader_write_vert(kong, "output.tex_coord = input.tex * " + brush_scale + " * constants.tex_scale;");
|
||||
@@ -135,7 +135,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_write_frag(kong, "var f0: float3 = lerp3(float3(0.04, 0.04, 0.04), basecol, metallic);");
|
||||
kong.frag_vvec = true;
|
||||
node_shader_write_frag(kong, "var dotnv: float = max(0.0, dot(n, vvec));");
|
||||
node_shader_write_frag(kong, "var env_brdf: float2 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)].xy;");
|
||||
// node_shader_write_frag(kong, "var env_brdf: float2 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)].xy;");
|
||||
node_shader_write_frag(kong, "var env_brdf: float4 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)];");
|
||||
node_shader_add_constant(kong, "envmap_num_mipmaps: int", "_envmap_num_mipmaps");
|
||||
node_shader_add_constant(kong, "envmap_data: float4", "_envmap_data"); // angle, sin(angle), cos(angle), strength
|
||||
node_shader_write_frag(kong, "var wreflect: float3 = reflect(-vvec, n);");
|
||||
|
||||
@@ -36,7 +36,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_add_out(kong, "tex_coord: float2");
|
||||
kong.frag_wvpposition = true;
|
||||
node_shader_add_constant(kong, "VP: float4x4", "_view_proj_matrix");
|
||||
kong.vert_wposition = true;
|
||||
kong.frag_wposition = true;
|
||||
|
||||
let texture_count: i32 = 0;
|
||||
let displace_strength: f32 = make_material_get_displace_strength();
|
||||
@@ -69,10 +69,10 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
}
|
||||
}
|
||||
}
|
||||
node_shader_write_vert(kong, "wposition += wnormal * float3(height, height, height) * float3(" + displace_strength + ", " + displace_strength + ", " + displace_strength + ");");
|
||||
node_shader_write_vert(kong, "output.wposition += wnormal * float3(height, height, height) * float3(" + displace_strength + ", " + displace_strength + ", " + displace_strength + ");");
|
||||
}
|
||||
|
||||
node_shader_write_vert(kong, "output.pos = constants.VP * float4(wposition.xyz, 1.0);");
|
||||
node_shader_write_vert(kong, "output.pos = constants.VP * float4(output.wposition.xyz, 1.0);");
|
||||
node_shader_write_vert(kong, "output.tex_coord = input.tex;");
|
||||
|
||||
kong.frag_out = "float4[3]";
|
||||
@@ -147,7 +147,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
}
|
||||
|
||||
if (context_raw.viewport_mode == viewport_mode_t.LIT && context_raw.render_mode == render_mode_t.FORWARD) {
|
||||
texture_count += 4;
|
||||
texture_count += 2;
|
||||
node_shader_add_texture(kong, "senvmap_brdf", "$brdf.k");
|
||||
node_shader_add_texture(kong, "senvmap_radiance", "_envmap_radiance");
|
||||
}
|
||||
@@ -271,12 +271,12 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
// Whiteout blend
|
||||
node_shader_write_frag(kong, "{");
|
||||
node_shader_write_frag(kong, "var n1: float3 = ntex * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);");
|
||||
node_shader_write_frag(kong, "var n2: float3 = clamp3(float3(0.5, 0.5, 1.0), texpaint_nor_sample.rgb, texpaint_opac) * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);");
|
||||
node_shader_write_frag(kong, "var n2: float3 = lerp3(float3(0.5, 0.5, 1.0), texpaint_nor_sample.rgb, texpaint_opac) * float3(2.0, 2.0, 2.0) - float3(1.0, 1.0, 1.0);");
|
||||
node_shader_write_frag(kong, "ntex = normalize(float3(n1.xy + n2.xy, n1.z * n2.z)) * float3(0.5, 0.5, 0.5) + float3(0.5, 0.5, 0.5);");
|
||||
node_shader_write_frag(kong, "}");
|
||||
}
|
||||
else {
|
||||
node_shader_write_frag(kong, "ntex = clamp3(ntex, texpaint_nor_sample.rgb, texpaint_opac);");
|
||||
node_shader_write_frag(kong, "ntex = lerp3(ntex, texpaint_nor_sample.rgb, texpaint_opac);");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,13 +286,13 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_write_frag(kong, "texpaint_pack_sample = sample_lod(texpaint_pack" + l.id + ", shared_sampler, input.tex_coord, 0.0);");
|
||||
|
||||
if (l.paint_occ) {
|
||||
node_shader_write_frag(kong, "occlusion = clamp(occlusion, texpaint_pack_sample.r, texpaint_opac);");
|
||||
node_shader_write_frag(kong, "occlusion = lerp(occlusion, texpaint_pack_sample.r, texpaint_opac);");
|
||||
}
|
||||
if (l.paint_rough) {
|
||||
node_shader_write_frag(kong, "roughness = clamp(roughness, texpaint_pack_sample.g, texpaint_opac);");
|
||||
node_shader_write_frag(kong, "roughness = lerp(roughness, texpaint_pack_sample.g, texpaint_opac);");
|
||||
}
|
||||
if (l.paint_met) {
|
||||
node_shader_write_frag(kong, "metallic = clamp(metallic, texpaint_pack_sample.b, texpaint_opac);");
|
||||
node_shader_write_frag(kong, "metallic = lerp(metallic, texpaint_pack_sample.b, texpaint_opac);");
|
||||
}
|
||||
if (l.paint_height && make_material_height_used) {
|
||||
let assign: string = l.paint_height_blend ? "+=" : "=";
|
||||
@@ -366,11 +366,12 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
}
|
||||
else if (context_raw.render_mode == render_mode_t.FORWARD && context_raw.viewport_mode != viewport_mode_t.PATH_TRACE) {
|
||||
kong.frag_wposition = true;
|
||||
node_shader_write_frag(kong, "var albedo: float3 = clamp3(basecol, float3(0.0, 0.0, 0.0), metallic);");
|
||||
node_shader_write_frag(kong, "var f0: float3 = clamp3(float3(0.04, 0.04, 0.04), basecol, metallic);");
|
||||
node_shader_write_frag(kong, "var albedo: float3 = lerp3(basecol, float3(0.0, 0.0, 0.0), metallic);");
|
||||
node_shader_write_frag(kong, "var f0: float3 = lerp3(float3(0.04, 0.04, 0.04), basecol, metallic);");
|
||||
kong.frag_vvec = true;
|
||||
node_shader_write_frag(kong, "var dotnv: float = max(0.0, dot(n, vvec));");
|
||||
node_shader_write_frag(kong, "var env_brdf: float2 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)].xy;");
|
||||
// node_shader_write_frag(kong, "var env_brdf: float2 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)].xy;");
|
||||
node_shader_write_frag(kong, "var env_brdf: float4 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)];");
|
||||
node_shader_add_constant(kong, "envmap_num_mipmaps: int", "_envmap_num_mipmaps");
|
||||
node_shader_add_constant(kong, "envmap_data: float4", "_envmap_data"); // angle, sin(angle), cos(angle), strength
|
||||
node_shader_write_frag(kong, "var wreflect: float3 = reflect(-vvec, n);");
|
||||
@@ -393,7 +394,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
}
|
||||
else { // Deferred, Pathtraced
|
||||
if (make_material_emis_used) {
|
||||
node_shader_write_frag(kong, "if (int(matid * 255.0) % 3 == 1) { basecol *= 10.0 };"); // Boost for bloom
|
||||
node_shader_write_frag(kong, "if (int(matid * 255.0) % 3 == 1) { basecol *= 10.0; }"); // Boost for bloom
|
||||
}
|
||||
node_shader_write_frag(kong, "output[1].rgba = float4(basecol, occlusion);");
|
||||
}
|
||||
@@ -477,7 +478,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
}
|
||||
|
||||
if (context_raw.viewport_mode != viewport_mode_t.LIT && context_raw.viewport_mode != viewport_mode_t.PATH_TRACE) {
|
||||
node_shader_write_frag(kong, "output[1].rgb = pow3(output[1].rgb, float3(2.2, 2.2, 2.2));");
|
||||
node_shader_write_frag(kong, "output[1].rgb = pow3(output[1].rgb, float3(2.2, 2.2, 2.2));"); ////
|
||||
}
|
||||
|
||||
node_shader_write_frag(kong, "n /= (abs(n.x) + abs(n.y) + abs(n.z));");
|
||||
@@ -490,7 +491,13 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
|
||||
parser_material_finalize(con_mesh);
|
||||
con_mesh.data.shader_from_source = true;
|
||||
gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_mesh.data.vertex_shader), ADDRESS(con_mesh.data.fragment_shader));
|
||||
|
||||
let test: string = node_shader_get(kong);
|
||||
|
||||
// iron_file_save_bytes("c:/users/lubos/desktop/test.kong", sys_string_to_buffer(test), 0);
|
||||
|
||||
gpu_create_shaders_from_kong(test, ADDRESS(con_mesh.data.vertex_shader), ADDRESS(con_mesh.data.fragment_shader));
|
||||
|
||||
return con_mesh;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ function make_node_preview_run(data: material_t, matcon: material_context_t, nod
|
||||
let kong: node_shader_t = node_shader_context_make_kong(con_mesh);
|
||||
|
||||
node_shader_write_attrib_vert(kong, "output.pos = float4(input.pos.xy * 3.0, 0.0, 1.0);"); // Pos unpack
|
||||
node_shader_write_attrib_vert(kong, "const madd: float2 = float2(0.5, 0.5);");
|
||||
node_shader_write_attrib_vert(kong, "var madd: float2 = float2(0.5, 0.5);");
|
||||
node_shader_add_out(kong, "tex_coord: float2");
|
||||
node_shader_write_attrib_vert(kong, "output.tex_coord = output.pos.xy * madd + madd;");
|
||||
node_shader_write_attrib_vert(kong, "output.tex_coord.y = 1.0 - output.tex_coord.y;");
|
||||
@@ -76,7 +76,12 @@ function make_node_preview_run(data: material_t, matcon: material_context_t, nod
|
||||
parser_material_finalize(con_mesh);
|
||||
|
||||
con_mesh.data.shader_from_source = true;
|
||||
gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_mesh.data.vertex_shader), ADDRESS(con_mesh.data.fragment_shader));
|
||||
|
||||
let test: string = node_shader_get(kong);
|
||||
|
||||
// iron_file_save_bytes("c:/users/lubos/desktop/test.kong", sys_string_to_buffer(test), 0);
|
||||
|
||||
gpu_create_shaders_from_kong(test, ADDRESS(con_mesh.data.vertex_shader), ADDRESS(con_mesh.data.fragment_shader));
|
||||
|
||||
return con_mesh;
|
||||
}
|
||||
|
||||
@@ -494,7 +494,12 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
|
||||
parser_material_triplanar = false;
|
||||
parser_material_sample_keep_aspect = false;
|
||||
con_paint.data.shader_from_source = true;
|
||||
gpu_create_shaders_from_kong(node_shader_get(kong), ADDRESS(con_paint.data.vertex_shader), ADDRESS(con_paint.data.fragment_shader));
|
||||
|
||||
let test: string = node_shader_get(kong);
|
||||
|
||||
// iron_file_save_bytes("c:/users/lubos/desktop/test.kong", sys_string_to_buffer(test), 0);
|
||||
|
||||
gpu_create_shaders_from_kong(test, ADDRESS(con_paint.data.vertex_shader), ADDRESS(con_paint.data.fragment_shader));
|
||||
|
||||
return con_paint;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_add_out(kong, "tex_coord: float2");
|
||||
kong.frag_wvpposition = true;
|
||||
node_shader_add_constant(kong, "VP: float4x4", "_view_proj_matrix");
|
||||
kong.vert_wposition = true;
|
||||
kong.frag_wposition = true;
|
||||
|
||||
let texture_count: i32 = 0;
|
||||
|
||||
@@ -111,7 +111,7 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
}
|
||||
|
||||
if (context_raw.viewport_mode == viewport_mode_t.LIT && context_raw.render_mode == render_mode_t.FORWARD) {
|
||||
texture_count += 4;
|
||||
texture_count += 2;
|
||||
node_shader_add_texture(kong, "senvmap_brdf", "$brdf.k");
|
||||
node_shader_add_texture(kong, "senvmap_radiance", "_envmap_radiance");
|
||||
}
|
||||
@@ -263,7 +263,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte
|
||||
node_shader_write_frag(kong, "var f0: float3 = lerp3(float3(0.04, 0.04, 0.04), basecol, metallic);");
|
||||
kong.frag_vvec = true;
|
||||
node_shader_write_frag(kong, "var dotnv: float = max(0.0, dot(n, vvec));");
|
||||
node_shader_write_frag(kong, "var env_brdf: float2 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)].xy;");
|
||||
// node_shader_write_frag(kong, "var env_brdf: float2 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)].xy;");
|
||||
node_shader_write_frag(kong, "var env_brdf: float4 = senvmap_brdf[int2(float2(roughness, 1.0 - dotnv) * 256.0)];");
|
||||
node_shader_add_constant(kong, "envmap_num_mipmaps: int", "_envmap_num_mipmaps");
|
||||
node_shader_add_constant(kong, "envmap_data: float4", "_envmap_data"); // angle, sin(angle), cos(angle), strength
|
||||
node_shader_write_frag(kong, "var wreflect: float3 = reflect(-vvec, n);");
|
||||
|
||||
@@ -33,7 +33,7 @@ function make_sculpt_run(data: material_t, matcon: material_context_t): node_sha
|
||||
let decal: bool = context_is_decal();
|
||||
|
||||
node_shader_add_out(kong, "tex_coord: float2");
|
||||
node_shader_write_vert(kong, "const madd: float2 = float2(0.5, 0.5);");
|
||||
node_shader_write_vert(kong, "var madd: float2 = float2(0.5, 0.5);");
|
||||
node_shader_write_vert(kong, "output.tex_coord = input.pos.xy * madd + madd;");
|
||||
node_shader_write_vert(kong, "output.tex_coord.y = 1.0 - output.tex_coord.y;");
|
||||
node_shader_write_vert(kong, "output.pos = float4(input.pos.xy, 0.0, 1.0);");
|
||||
|
||||
@@ -467,7 +467,9 @@ function context_init() {
|
||||
}
|
||||
|
||||
function context_use_deferred(): bool {
|
||||
return context_raw.render_mode != render_mode_t.FORWARD && (context_raw.viewport_mode == viewport_mode_t.LIT || context_raw.viewport_mode == viewport_mode_t.PATH_TRACE) && context_raw.tool != workspace_tool_t.COLORID;
|
||||
return context_raw.render_mode != render_mode_t.FORWARD &&
|
||||
(context_raw.viewport_mode == viewport_mode_t.LIT || context_raw.viewport_mode == viewport_mode_t.PATH_TRACE) &&
|
||||
context_raw.tool != workspace_tool_t.COLORID;
|
||||
}
|
||||
|
||||
function context_select_material(i: i32) {
|
||||
|
||||
@@ -22,14 +22,13 @@ function main() {
|
||||
scene_set_active("Scene");
|
||||
uniforms_ext_init();
|
||||
render_path_base_init();
|
||||
render_path_deferred_init(); // Allocate gbuffer
|
||||
|
||||
if (context_raw.render_mode == render_mode_t.FORWARD) {
|
||||
render_path_deferred_init(); // Allocate gbuffer
|
||||
render_path_forward_init();
|
||||
render_path_commands = render_path_forward_commands;
|
||||
}
|
||||
else {
|
||||
render_path_deferred_init();
|
||||
render_path_commands = render_path_deferred_commands;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ type node_shader_t = {
|
||||
frag_write_normal?: i32;
|
||||
|
||||
// References
|
||||
vert_wposition?: bool;
|
||||
vert_n?: bool;
|
||||
frag_bposition?: bool;
|
||||
frag_wposition?: bool;
|
||||
@@ -204,13 +203,15 @@ function node_shader_get(raw: node_shader_t): string {
|
||||
s += "const " + a + "_sampler: sampler;\n\n";
|
||||
}
|
||||
|
||||
s += "#[set(everything)]\n";
|
||||
s += "const constants: {\n";
|
||||
for (let i: i32 = 0; i < raw.constants.length; ++i) {
|
||||
let a: string = raw.constants[i];
|
||||
s += "\t" + a + ";\n";
|
||||
if (raw.constants.length > 0) {
|
||||
s += "#[set(everything)]\n";
|
||||
s += "const constants: {\n";
|
||||
for (let i: i32 = 0; i < raw.constants.length; ++i) {
|
||||
let a: string = raw.constants[i];
|
||||
s += "\t" + a + ";\n";
|
||||
}
|
||||
s += "};\n\n";
|
||||
}
|
||||
s += "};\n\n";
|
||||
|
||||
for (let i: i32 = 0; i < raw.shared_samplers.length; ++i) {
|
||||
let a: string = raw.shared_samplers[i];
|
||||
@@ -235,6 +236,7 @@ function node_shader_get(raw: node_shader_t): string {
|
||||
s += raw.vert_normal;
|
||||
s += raw.vert;
|
||||
s += raw.vert_end;
|
||||
s += "output.pos.z = (output.pos.z + output.pos.w) * 0.5;\n";
|
||||
s += "\n\treturn output;\n";
|
||||
s += "}\n\n";
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ function parser_material_finalize(con: node_shader_context_t) {
|
||||
kong.frag_n = true;
|
||||
}
|
||||
if (kong.frag_vvec) {
|
||||
kong.vert_wposition = true;
|
||||
kong.frag_wposition = true;
|
||||
}
|
||||
|
||||
if (kong.frag_bposition) {
|
||||
@@ -192,14 +192,16 @@ function parser_material_finalize(con: node_shader_context_t) {
|
||||
tex_coord.y * tex_coord_blend.x + tex_coord1.y * tex_coord_blend.y);");
|
||||
}
|
||||
else if (kong.frag_ndcpos) {
|
||||
node_shader_add_out(kong, "bposition: float3");
|
||||
node_shader_write_vert(kong, "output.bposition = (ndc.xyz / ndc.w);");
|
||||
node_shader_add_out(kong, "_bposition: float3");
|
||||
node_shader_write_vert(kong, "output._bposition = (ndc.xyz / ndc.w);");
|
||||
node_shader_write_attrib_frag(kong, "var bposition: float3 = input._bposition;");
|
||||
}
|
||||
else {
|
||||
node_shader_add_out(kong, "bposition: float3");
|
||||
node_shader_add_out(kong, "_bposition: float3");
|
||||
node_shader_add_constant(kong, "dim: float3", "_dim");
|
||||
node_shader_add_constant(kong, "hdim: float3", "_half_dim");
|
||||
node_shader_write_attrib_vert(kong, "output.bposition = (input.pos.xyz + constants.hdim) / constants.dim;");
|
||||
node_shader_write_attrib_vert(kong, "output._bposition = (input.pos.xyz + constants.hdim) / constants.dim;");
|
||||
node_shader_write_attrib_frag(kong, "var bposition: float3 = input._bposition;");
|
||||
}
|
||||
}
|
||||
if (kong.frag_wposition) {
|
||||
@@ -207,10 +209,6 @@ function parser_material_finalize(con: node_shader_context_t) {
|
||||
node_shader_add_out(kong, "wposition: float3");
|
||||
node_shader_write_attrib_vert(kong, "output.wposition = float4(constants.W * float4(input.pos.xyz, 1.0)).xyz;");
|
||||
}
|
||||
else if (kong.vert_wposition) {
|
||||
node_shader_add_constant(kong, "W: float4x4", "_world_matrix");
|
||||
node_shader_write_attrib_vert(kong, "var wposition: float3 = float4(constants.W * float4(input.pos.xyz, 1.0)).xyz;");
|
||||
}
|
||||
if (kong.frag_vposition) {
|
||||
node_shader_add_constant(kong, "WV: float4x4", "_world_view_matrix");
|
||||
node_shader_add_out(kong, "vposition: float3");
|
||||
@@ -232,13 +230,14 @@ function parser_material_finalize(con: node_shader_context_t) {
|
||||
if (kong.frag_vvec_cam) {
|
||||
node_shader_add_constant(kong, "WV: float4x4", "_world_view_matrix");
|
||||
node_shader_add_out(kong, "eye_dir_cam: float3");
|
||||
node_shader_write_attrib_vert(kong, "output.eye_dir_cam = float4(constants.WV * float4(input.pos.xyz, 1.0)).xyz; eye_dir_cam.z *= -1.0;");
|
||||
node_shader_write_attrib_vert(kong, "output.eye_dir_cam = float4(constants.WV * float4(input.pos.xyz, 1.0)).xyz;");
|
||||
node_shader_write_attrib_vert(kong, "output.eye_dir_cam.z *= -1.0;");
|
||||
node_shader_write_attrib_frag(kong, "var vvec_cam: float3 = normalize(input.eye_dir_cam);");
|
||||
}
|
||||
if (kong.frag_vvec) {
|
||||
node_shader_add_constant(kong, "eye: float3", "_camera_pos");
|
||||
node_shader_add_out(kong, "eye_dir: float3");
|
||||
node_shader_write_attrib_vert(kong, "output.eye_dir = constants.eye - wposition;");
|
||||
node_shader_write_attrib_vert(kong, "output.eye_dir = constants.eye - output.wposition;");
|
||||
node_shader_write_attrib_frag(kong, "var vvec: float3 = normalize(input.eye_dir);");
|
||||
}
|
||||
if (kong.frag_n) {
|
||||
@@ -260,11 +259,11 @@ function parser_material_finalize(con: node_shader_context_t) {
|
||||
}
|
||||
if (kong.frag_wvpposition) {
|
||||
node_shader_add_out(kong, "wvpposition: float4");
|
||||
node_shader_write_end_vert(kong, "output.wvpposition = input.pos;");
|
||||
node_shader_write_end_vert(kong, "output.wvpposition = output.pos;");
|
||||
}
|
||||
if (node_shader_context_is_elem(con, "col")) {
|
||||
node_shader_add_out(kong, "vcolor: float3");
|
||||
node_shader_write_attrib_vert(kong, "output.vcolor = col.rgb;");
|
||||
node_shader_write_attrib_vert(kong, "output.vcolor = input.col.rgb;");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +496,7 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
|
||||
if (socket == node.outputs[0]) { // Color
|
||||
if (parser_material_kong.context.allow_vcols) {
|
||||
node_shader_context_add_elem(parser_material_kong.context, "col", "short4norm"); // Vcols only for now
|
||||
return "vcolor";
|
||||
return "input.vcolor";
|
||||
}
|
||||
else {
|
||||
return("float3(0.0, 0.0, 0.0)");
|
||||
@@ -505,13 +504,13 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
|
||||
}
|
||||
else { // Vector
|
||||
node_shader_context_add_elem(parser_material_kong.context, "tex", "short2norm"); // UVMaps only for now
|
||||
return "float3(tex_coord.x, tex_coord.y, 0.0)";
|
||||
return "float3(input.tex_coord.x, input.tex_coord.y, 0.0)";
|
||||
}
|
||||
}
|
||||
else if (node.type == "VERTEX_COLOR") {
|
||||
if (parser_material_kong.context.allow_vcols) {
|
||||
node_shader_context_add_elem(parser_material_kong.context, "col", "short4norm");
|
||||
return "vcolor";
|
||||
return "input.vcolor";
|
||||
}
|
||||
else {
|
||||
return("float3(0.0, 0.0, 0.0)");
|
||||
@@ -930,7 +929,7 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
|
||||
}
|
||||
else if (socket == node.outputs[2]) { // Tangent
|
||||
parser_material_kong.frag_wtangent = true;
|
||||
return "wtangent";
|
||||
return "input.wtangent";
|
||||
}
|
||||
else if (socket == node.outputs[3]) { // True Normal
|
||||
parser_material_kong.frag_n = true;
|
||||
@@ -942,13 +941,13 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
|
||||
}
|
||||
else if (socket == node.outputs[5]) { // Parametric
|
||||
parser_material_kong.frag_mposition = true;
|
||||
return "mposition";
|
||||
return "input.mposition";
|
||||
}
|
||||
}
|
||||
else if (node.type == "OBJECT_INFO") {
|
||||
if (socket == node.outputs[0]) { // Location
|
||||
parser_material_kong.frag_wposition = true;
|
||||
return "wposition";
|
||||
return "input.wposition";
|
||||
}
|
||||
else if (socket == node.outputs[1]) { // Color
|
||||
return "float3(0.0, 0.0, 0.0)";
|
||||
@@ -972,7 +971,7 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
|
||||
else if (node.type == "TEX_COORD") {
|
||||
if (socket == node.outputs[0]) { // Generated - bounds
|
||||
parser_material_kong.frag_bposition = true;
|
||||
return "input.bposition";
|
||||
return "bposition";
|
||||
}
|
||||
else if (socket == node.outputs[1]) { // Normal
|
||||
parser_material_kong.frag_n = true;
|
||||
@@ -980,7 +979,7 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
|
||||
}
|
||||
else if (socket == node.outputs[2]) {// UV
|
||||
node_shader_context_add_elem(parser_material_kong.context, "tex", "short2norm");
|
||||
return "float3(tex_coord.x, tex_coord.y, 0.0)";
|
||||
return "float3(input.tex_coord.x, input.tex_coord.y, 0.0)";
|
||||
}
|
||||
else if (socket == node.outputs[3]) { // Object
|
||||
parser_material_kong.frag_mposition = true;
|
||||
@@ -1000,7 +999,7 @@ function parser_material_parse_vector(node: ui_node_t, socket: ui_node_socket_t)
|
||||
}
|
||||
else if (node.type == "UVMAP") {
|
||||
node_shader_context_add_elem(parser_material_kong.context, "tex", "short2norm");
|
||||
return "float3(tex_coord.x, tex_coord.y, 0.0)";
|
||||
return "float3(input.tex_coord.x, input.tex_coord.y, 0.0)";
|
||||
}
|
||||
else if (node.type == "BUMP") {
|
||||
let strength: string = parser_material_parse_value_input(node.inputs[0]);
|
||||
@@ -1258,18 +1257,18 @@ function parser_material_parse_value(node: ui_node_t, socket: ui_node_socket_t):
|
||||
node_shader_add_texture(parser_material_kong, "texuvmap", "_texuvmap");
|
||||
// let use_pixel_size: bool = node.buttons[0].default_value == "true";
|
||||
// let pixel_size: f32 = parse_value_input(node.inputs[0]);
|
||||
return "sample_lod(texuvmap, texuvmap_sampler, tex_coord, 0.0).r";
|
||||
return "sample_lod(texuvmap, texuvmap_sampler, input.tex_coord, 0.0).r";
|
||||
}
|
||||
else if (node.type == "CAMERA") {
|
||||
if (socket == node.outputs[1]) { // View Z Depth
|
||||
node_shader_add_constant(parser_material_kong, "camera_proj: float2", "_camera_plane_proj");
|
||||
parser_material_kong.frag_wvpposition = true;
|
||||
return "(constants.camera_proj.y / ((wvpposition.z / wvpposition.w) - constants.camera_proj.x))";
|
||||
return "(constants.camera_proj.y / ((input.wvpposition.z / input.wvpposition.w) - constants.camera_proj.x))";
|
||||
}
|
||||
else { // View Distance
|
||||
node_shader_add_constant(parser_material_kong, "eye: float3", "_camera_pos");
|
||||
parser_material_kong.frag_wposition = true;
|
||||
return "distance(constants.eye, wposition)";
|
||||
return "distance(constants.eye, input.wposition)";
|
||||
}
|
||||
}
|
||||
else if (node.type == "LAYER") {
|
||||
@@ -1658,8 +1657,8 @@ function parser_material_parse_value(node: ui_node_t, socket: ui_node_socket_t):
|
||||
let str: string = sys_buffer_to_string(script);
|
||||
let link: string = parser_material_node_name(node);
|
||||
map_set(parser_material_script_links, link, str);
|
||||
node_shader_add_constant(parser_material_kong, "float " + link, "_" + link);
|
||||
return link;
|
||||
node_shader_add_constant(parser_material_kong, "" + link + ": float", "_" + link);
|
||||
return "constants." + link;
|
||||
}
|
||||
else if (node.type == "SHADER_GPU") {
|
||||
let shader: buffer_t = node.buttons[0].default_value;
|
||||
@@ -1928,8 +1927,8 @@ function parser_material_texture_store(node: ui_node_t, tex: bind_tex_t, tex_nam
|
||||
}
|
||||
|
||||
function parser_material_vec1(v: f32): string {
|
||||
// return "float(" + v + ")";
|
||||
return v + "";
|
||||
return "float(" + v + ")";
|
||||
// return v + "";
|
||||
}
|
||||
|
||||
function parser_material_vec3(v: f32_array_t): string {
|
||||
|
||||
@@ -192,23 +192,25 @@ let str_tex_brick: string = "\
|
||||
fun tex_brick_noise(n: int): float { \
|
||||
var nn: int; \
|
||||
n = (n >> 13) ^ n; \
|
||||
nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; \
|
||||
return 0.5f * float(nn) / 1073741824.0; \
|
||||
/*nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;*/ \
|
||||
nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 2147483647; \
|
||||
return 0.5 * float(nn) / 1073741824.0; \
|
||||
} \
|
||||
fun tex_brick(p: float3, c1: float3, c2: float3, c3: float3): float3 { \
|
||||
var brick_size: float3 = float3(0.9, 0.49, 0.49); \
|
||||
var mortar_size: float3 = float3(0.05, 0.1, 0.1); \
|
||||
p /= brick_size / 2; \
|
||||
p /= brick_size / 2.0; \
|
||||
if (frac(p.y * 0.5) > 0.5) { p.x += 0.5; } \
|
||||
var col: float = floor(p.x / (brick_size.x + (mortar_size.x * 2.0))); \
|
||||
var row: float = p.y; \
|
||||
p = frac3(p); \
|
||||
var b: float3 = step3(p, 1.0 - mortar_size); \
|
||||
var tint: float = min(max(tex_brick_noise((int(col) << 16) + (int(row) & 0xFFFF)), 0.0), 1.0); \
|
||||
/*var tint: float = min(max(tex_brick_noise((int(col) << 16) + (int(row) & 0xffff)), 0.0), 1.0);*/ \
|
||||
var tint: float = min(max(tex_brick_noise((int(col) << 16) + (int(row) & 65535)), 0.0), 1.0); \
|
||||
return lerp3(c3, lerp3(c1, c2, tint), b.x * b.y * b.z); \
|
||||
} \
|
||||
fun tex_brick_f(p: float3): float { \
|
||||
p /= float3(0.9, 0.49, 0.49) / 2; \
|
||||
p /= float3(0.9, 0.49, 0.49) / 2.0; \
|
||||
if (frac(p.y * 0.5) > 0.5) { p.x += 0.5; } \
|
||||
p = frac3(p); \
|
||||
var b: float3 = step3(p, float3(0.95, 0.9, 0.9)); \
|
||||
@@ -318,7 +320,7 @@ fun create_basis(normal: float3, out tangent: float3, out binormal: float3) { \
|
||||
";
|
||||
|
||||
let str_sh_irradiance: string = "\
|
||||
fun sh_irradiance(float3 nor): float3 { \
|
||||
fun sh_irradiance(nor: float3): float3 { \
|
||||
var c1: float = 0.429043; \
|
||||
var c2: float = 0.511664; \
|
||||
var c3: float = 0.743125; \
|
||||
|
||||
Reference in New Issue
Block a user