paint: merge gc remove
This commit is contained in:
@@ -28,55 +28,53 @@ char *parser_material_texture_store(ui_node_t *node, bind_tex_t *tex, char *tex_
|
||||
}
|
||||
char *tex_store = parser_material_store_var_name(node);
|
||||
if (parser_material_sample_keep_aspect) {
|
||||
node_shader_add_constant(parser_material_kong, string("%s_size: float2", tex_name), string("_size(%s)", tex_name));
|
||||
parser_material_write(parser_material_kong, string("var %s_size: float2 = constants.%s_size;", tex_store, tex_name));
|
||||
parser_material_write(parser_material_kong, string("var %s_ax: float = %s_size.x / %s_size.y;", tex_store, tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string("var %s_ay: float = %s_size.y / %s_size.x;", tex_store, tex_store, tex_store));
|
||||
node_shader_add_constant(parser_material_kong, string_tmp("%s_size: float2", tex_name), string_tmp("_size(%s)", tex_name));
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s_size: float2 = constants.%s_size;", tex_store, tex_name));
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s_ax: float = %s_size.x / %s_size.y;", tex_store, tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s_ay: float = %s_size.y / %s_size.x;", tex_store, tex_store, tex_store));
|
||||
parser_material_write(
|
||||
parser_material_kong,
|
||||
string("var %s_uv: float2 = ((%s.xy / float(%s) - float2(0.5, 0.5)) * float2(max(%s_ay, 1.0), max(%s_ax, 1.0))) + float2(0.5, 0.5);", tex_store,
|
||||
string_tmp("var %s_uv: float2 = ((%s.xy / float(%s) - float2(0.5, 0.5)) * float2(max(%s_ay, 1.0), max(%s_ax, 1.0))) + float2(0.5, 0.5);", tex_store,
|
||||
uv_name, parser_material_sample_uv_scale, tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string("if (%s_uv.x < 0.0 || %s_uv.y < 0.0 || %s_uv.x > 1.0 || %s_uv.y > 1.0) { discard; }", tex_store,
|
||||
parser_material_write(parser_material_kong, string_tmp("if (%s_uv.x < 0.0 || %s_uv.y < 0.0 || %s_uv.x > 1.0 || %s_uv.y > 1.0) { discard; }", tex_store,
|
||||
tex_store, tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string("%s_uv = %s_uv * float(%s);", tex_store, tex_store, parser_material_sample_uv_scale));
|
||||
uv_name = string("%s_uv", tex_store);
|
||||
parser_material_write(parser_material_kong, string_tmp("%s_uv = %s_uv * float(%s);", tex_store, tex_store, parser_material_sample_uv_scale));
|
||||
uv_name = string_tmp("%s_uv", tex_store);
|
||||
}
|
||||
if (parser_material_triplanar) {
|
||||
if (!string_equals(uv_name, parser_material_tex_coord)) {
|
||||
parser_material_write(parser_material_kong, string("var %s1: float3 = %s;", uv_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string("var %s2: float3 = %s;", uv_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s1: float3 = %s;", uv_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s2: float3 = %s;", uv_name, uv_name));
|
||||
}
|
||||
parser_material_write(parser_material_kong, string("var %s: float4 = float4(0.0, 0.0, 0.0, 0.0);", tex_store));
|
||||
parser_material_write(parser_material_kong, string("if (tex_coord_blend.x > 0.0) {%s += sample(%s, sampler_linear, %s.xy) * tex_coord_blend.x; }",
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s: float4 = float4(0.0, 0.0, 0.0, 0.0);", tex_store));
|
||||
parser_material_write(parser_material_kong, string_tmp("if (tex_coord_blend.x > 0.0) {%s += sample(%s, sampler_linear, %s.xy) * tex_coord_blend.x; }",
|
||||
tex_store, tex_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string("if (tex_coord_blend.y > 0.0) {%s += sample(%s, sampler_linear, %s1.xy) * tex_coord_blend.y; }",
|
||||
parser_material_write(parser_material_kong, string_tmp("if (tex_coord_blend.y > 0.0) {%s += sample(%s, sampler_linear, %s1.xy) * tex_coord_blend.y; }",
|
||||
tex_store, tex_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string("if (tex_coord_blend.z > 0.0) {%s += sample(%s, sampler_linear, %s2.xy) * tex_coord_blend.z; }",
|
||||
parser_material_write(parser_material_kong, string_tmp("if (tex_coord_blend.z > 0.0) {%s += sample(%s, sampler_linear, %s2.xy) * tex_coord_blend.z; }",
|
||||
tex_store, tex_name, uv_name));
|
||||
}
|
||||
else {
|
||||
if (parser_material_is_frag) {
|
||||
any_map_set(parser_material_texture_map, tex_store, string("sample(%s, sampler_linear, %s.xy)", tex_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string("var %s: float4 = sample(%s, sampler_linear, %s.xy);", tex_store, tex_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s: float4 = sample(%s, sampler_linear, %s.xy);", tex_store, tex_name, uv_name));
|
||||
}
|
||||
else {
|
||||
any_map_set(parser_material_texture_map, tex_store, string("sample_lod(%s, sampler_linear, %s.xy, 0.0)", tex_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string("var %s: float4 = sample_lod(%s, sampler_linear, %s.xy, 0.0);", tex_store, tex_name, uv_name));
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s: float4 = sample_lod(%s, sampler_linear, %s.xy, 0.0);", tex_store, tex_name, uv_name));
|
||||
}
|
||||
if (!ends_with(tex->file, ".jpg")) { // Pre-mult alpha
|
||||
parser_material_write(parser_material_kong, string("%s.rgb = %s.rgb * %s.a;", tex_store, tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string_tmp("%s.rgb = %s.rgb * %s.a;", tex_store, tex_store, tex_store));
|
||||
}
|
||||
}
|
||||
if (parser_material_transform_color_space) {
|
||||
// Base color socket auto-converts from sRGB to linear
|
||||
if (color_space == COLOR_SPACE_LINEAR && parser_material_parsing_basecolor) { // Linear to sRGB
|
||||
parser_material_write(parser_material_kong, string("%s.rgb = pow3(%s.rgb, float3(2.2, 2.2, 2.2));", tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string_tmp("%s.rgb = pow3(%s.rgb, float3(2.2, 2.2, 2.2));", tex_store, tex_store));
|
||||
}
|
||||
else if (color_space == COLOR_SPACE_SRGB && !parser_material_parsing_basecolor) { // sRGB to linear
|
||||
parser_material_write(parser_material_kong, string("%s.rgb = pow3(%s.rgb, float3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));", tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string_tmp("%s.rgb = pow3(%s.rgb, float3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));", tex_store, tex_store));
|
||||
}
|
||||
else if (color_space == COLOR_SPACE_DIRECTX_NORMAL_MAP) { // DirectX normal map to OpenGL normal map
|
||||
parser_material_write(parser_material_kong, string("%s.y = 1.0 - %s.y;", tex_store, tex_store));
|
||||
parser_material_write(parser_material_kong, string_tmp("%s.y = 1.0 - %s.y;", tex_store, tex_store));
|
||||
}
|
||||
}
|
||||
return tex_store;
|
||||
@@ -86,19 +84,19 @@ char *image_texture_node_vector(ui_node_t *node, ui_node_socket_t *socket) {
|
||||
// Already fetched
|
||||
if (string_array_index_of(parser_material_parsed, parser_material_res_var_name(node, node->outputs->buffer[1])) >= 0) { // TODO: node.outputs[0]
|
||||
char *varname = parser_material_store_var_name(node);
|
||||
return string("%s.rgb", varname);
|
||||
return string_tmp("%s.rgb", varname);
|
||||
}
|
||||
char *tex_name = parser_material_node_name(node, NULL);
|
||||
bind_tex_t *tex = parser_material_make_texture(node, tex_name);
|
||||
if (tex != NULL) {
|
||||
i32 color_space = node->buttons->buffer[1]->default_value->buffer[0];
|
||||
char *texstore = parser_material_texture_store(node, tex, tex_name, color_space);
|
||||
return string("%s.rgb", texstore);
|
||||
return string_tmp("%s.rgb", texstore);
|
||||
}
|
||||
else {
|
||||
char *tex_store = parser_material_store_var_name(node); // Pink color for missing texture
|
||||
parser_material_write(parser_material_kong, string("var %s: float4 = float4(1.0, 0.0, 1.0, 1.0);", tex_store));
|
||||
return string("%s.rgb", tex_store);
|
||||
parser_material_write(parser_material_kong, string_tmp("var %s: float4 = float4(1.0, 0.0, 1.0, 1.0);", tex_store));
|
||||
return string_tmp("%s.rgb", tex_store);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,23 +104,23 @@ char *image_texture_node_value(ui_node_t *node, ui_node_socket_t *socket) {
|
||||
// Already fetched
|
||||
if (string_array_index_of(parser_material_parsed, parser_material_res_var_name(node, node->outputs->buffer[0])) >= 0) { // TODO: node.outputs[1]
|
||||
char *varname = parser_material_store_var_name(node);
|
||||
return string("%s.a", varname);
|
||||
return string_tmp("%s.a", varname);
|
||||
}
|
||||
char *tex_name = parser_material_node_name(node, NULL);
|
||||
bind_tex_t *tex = parser_material_make_texture(node, tex_name);
|
||||
if (tex != NULL) {
|
||||
i32 color_space = node->buttons->buffer[1]->default_value->buffer[0];
|
||||
char *texstore = parser_material_texture_store(node, tex, tex_name, color_space);
|
||||
return string("%s.a", texstore);
|
||||
return string_tmp("%s.a", texstore);
|
||||
}
|
||||
return "0.0";
|
||||
}
|
||||
|
||||
void image_texture_node_init() {
|
||||
|
||||
char *image_texture_color_space_data = string("%s\n%s\n%s\n%s", _tr("Auto"), _tr("Linear"), _tr("sRGB"), _tr("DirectX Normal Map"));
|
||||
char *image_texture_color_space_data = string_tmp("%s\n%s\n%s\n%s", _tr("Auto"), _tr("Linear"), _tr("sRGB"), _tr("DirectX Normal Map"));
|
||||
ui_node_t *image_texture_node_def =
|
||||
GC_ALLOC_INIT(ui_node_t, {.id = 0,
|
||||
ALLOC_INIT(ui_node_t, {.id = 0,
|
||||
.name = _tr("Image Texture"),
|
||||
.type = "TEX_IMAGE",
|
||||
.x = 0,
|
||||
@@ -130,7 +128,7 @@ void image_texture_node_init() {
|
||||
.color = 0xff4982a0,
|
||||
.inputs = any_array_create_from_raw(
|
||||
(void *[]){
|
||||
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
||||
ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
||||
.node_id = 0,
|
||||
.name = _tr("Vector"),
|
||||
.type = "VECTOR",
|
||||
@@ -144,7 +142,7 @@ void image_texture_node_init() {
|
||||
1),
|
||||
.outputs = any_array_create_from_raw(
|
||||
(void *[]){
|
||||
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
||||
ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
||||
.node_id = 0,
|
||||
.name = _tr("Color"),
|
||||
.type = "RGBA",
|
||||
@@ -154,7 +152,7 @@ void image_texture_node_init() {
|
||||
.max = 1.0,
|
||||
.precision = 100,
|
||||
.display = 0}),
|
||||
GC_ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
||||
ALLOC_INIT(ui_node_socket_t, {.id = 0,
|
||||
.node_id = 0,
|
||||
.name = _tr("Alpha"),
|
||||
.type = "VALUE",
|
||||
@@ -168,7 +166,7 @@ void image_texture_node_init() {
|
||||
2),
|
||||
.buttons = any_array_create_from_raw(
|
||||
(void *[]){
|
||||
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("File"),
|
||||
ALLOC_INIT(ui_node_button_t, {.name = _tr("File"),
|
||||
.type = "ENUM",
|
||||
.output = -1,
|
||||
.default_value = f32_array_create_x(0),
|
||||
@@ -177,7 +175,7 @@ void image_texture_node_init() {
|
||||
.max = 1.0,
|
||||
.precision = 100,
|
||||
.height = 0}),
|
||||
GC_ALLOC_INIT(ui_node_button_t, {.name = _tr("Color Space"),
|
||||
ALLOC_INIT(ui_node_button_t, {.name = _tr("Color Space"),
|
||||
.type = "ENUM",
|
||||
.output = -1,
|
||||
.default_value = f32_array_create_x(0),
|
||||
|
||||
Reference in New Issue
Block a user