paint: merge sculpt
This commit is contained in:
@@ -92,7 +92,9 @@ string_array_t *make_paint_color_attachments() {
|
||||
}
|
||||
|
||||
node_shader_context_t *make_paint_run(material_t *data, material_context_t *matcon) {
|
||||
if (g_context->layer->texpaint_sculpt != NULL) {
|
||||
bool picking_tool = g_context->tool == TOOL_TYPE_COLORID || g_context->tool == TOOL_TYPE_PICKER || g_context->tool == TOOL_TYPE_MATERIAL ||
|
||||
g_context->tool == TOOL_TYPE_CURSOR;
|
||||
if (g_context->layer->texpaint_sculpt != NULL && !picking_tool) {
|
||||
return sculpt_make_sculpt_run(data, matcon);
|
||||
}
|
||||
|
||||
@@ -594,44 +596,7 @@ node_shader_context_t *make_paint_run(material_t *data, material_context_t *matc
|
||||
parser_material_triplanar = false;
|
||||
parser_material_sample_keep_aspect = false;
|
||||
|
||||
{
|
||||
slot_layer_t_array_t *sculpt_layers = any_array_create_from_raw((void *[]){}, 0);
|
||||
i32_array_t *sculpt_indices = i32_array_create(0);
|
||||
for (i32 i = 0; i < g_project->_->layers->length; ++i) {
|
||||
slot_layer_t *l = g_project->_->layers->buffer[i];
|
||||
if (l->texpaint_sculpt != NULL && slot_layer_is_visible(l)) {
|
||||
any_array_push(sculpt_layers, l);
|
||||
i32_array_push(sculpt_indices, i);
|
||||
}
|
||||
}
|
||||
i32 scount = sculpt_layers->length;
|
||||
if (scount > 0) {
|
||||
i32 idx0 = sculpt_indices->buffer[0];
|
||||
node_shader_add_constant(kong, string("texpaint_sculpt_size%d: float2", idx0), string("_size(_texpaint_sculpt%d)", idx0));
|
||||
for (i32 i = 0; i < scount; ++i) {
|
||||
i32 idx = sculpt_indices->buffer[i];
|
||||
node_shader_add_texture(kong, string("texpaint_sculpt%d", idx), string("_texpaint_sculpt%d", idx));
|
||||
}
|
||||
if (scount > 1) {
|
||||
node_shader_add_texture(kong, "texpaint_sculpt_base", "_texpaint_sculpt_base");
|
||||
}
|
||||
|
||||
node_shader_write_attrib_vert(kong, string("var sculpt_uv_paint: uint2 = uint2(uint(float(vertex_id()) %% constants.texpaint_sculpt_size%d.x), "
|
||||
"uint(float(vertex_id()) / constants.texpaint_sculpt_size%d.y));",
|
||||
idx0, idx0));
|
||||
|
||||
node_shader_write_attrib_vert(kong, string("var sculpt_pos_paint: float4 = texpaint_sculpt%d[sculpt_uv_paint];", idx0));
|
||||
for (i32 i = 1; i < scount; ++i) {
|
||||
i32 idx = sculpt_indices->buffer[i];
|
||||
node_shader_write_attrib_vert(
|
||||
kong, string("sculpt_pos_paint = sculpt_pos_paint + texpaint_sculpt%d[sculpt_uv_paint] - texpaint_sculpt_base[sculpt_uv_paint];", idx));
|
||||
}
|
||||
node_shader_write_attrib_vert(kong, "output.ndc = constants.WVP * float4(sculpt_pos_paint.xyz, 1.0);");
|
||||
if (kong->frag_wposition) {
|
||||
node_shader_write_attrib_vert(kong, "output.wposition = (constants.W * float4(sculpt_pos_paint.xyz, 1.0)).xyz;");
|
||||
}
|
||||
}
|
||||
}
|
||||
sculpt_make_paint_run(kong);
|
||||
|
||||
con_paint->data->shader_from_source = true;
|
||||
gpu_create_shaders_from_kong(node_shader_get(kong), &con_paint->data->vertex_shader, &con_paint->data->fragment_shader,
|
||||
|
||||
@@ -1,6 +1,85 @@
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
static material_data_t *particle_bullet_material = NULL;
|
||||
|
||||
static node_shader_context_t *make_particle_bullet_run() {
|
||||
material_t *mat = GC_ALLOC_INIT(material_t, {.name = "particle_bullet", .canvas = NULL});
|
||||
shader_context_t *props = GC_ALLOC_INIT(shader_context_t, {
|
||||
.name = "mesh",
|
||||
.depth_write = true,
|
||||
.compare_mode = "less",
|
||||
.cull_mode = "clockwise",
|
||||
.vertex_elements = any_array_create_from_raw(
|
||||
(void *[]){
|
||||
GC_ALLOC_INIT(vertex_element_t, {.name = "pos", .data = "short4norm"}),
|
||||
GC_ALLOC_INIT(vertex_element_t, {.name = "nor", .data = "short2norm"}),
|
||||
GC_ALLOC_INIT(vertex_element_t, {.name = "tex", .data = "short2norm"}),
|
||||
},
|
||||
3),
|
||||
.color_attachments = any_array_create_from_raw((void *[]){"RGBA64", "RGBA64", "RGBA64"}, 3),
|
||||
.depth_attachment = "D32",
|
||||
});
|
||||
node_shader_context_t *con = node_shader_context_create(mat, props);
|
||||
node_shader_t *kong = node_shader_context_make_kong(con);
|
||||
|
||||
kong->frag_n = true;
|
||||
kong->frag_out = "float4[3]";
|
||||
|
||||
node_shader_add_constant(kong, "WVP: float4x4", "_world_view_proj_matrix");
|
||||
node_shader_write_vert(kong, "output.pos = constants.WVP * float4(input.pos.xyz, 1.0);");
|
||||
|
||||
node_shader_add_out(kong, "tex_coord: float2");
|
||||
node_shader_write_vert(kong, "output.tex_coord = input.tex;");
|
||||
|
||||
node_shader_add_function(kong, str_octahedron_wrap);
|
||||
node_shader_add_function(kong, str_pack_float_int16);
|
||||
|
||||
node_shader_write_frag(kong, "var basecol: float3 = float3(0.8, 0.8, 0.8);");
|
||||
node_shader_write_frag(kong, "var roughness: float = 0.5;");
|
||||
node_shader_write_frag(kong, "var metallic: float = 0.0;");
|
||||
node_shader_write_frag(kong, "var occlusion: float = 1.0;");
|
||||
node_shader_write_frag(kong, "n = n / (abs(n.x) + abs(n.y) + abs(n.z));");
|
||||
node_shader_write_frag(kong, "if (n.z < 0.0) { n.xy = octahedron_wrap(n.xy); }");
|
||||
node_shader_write_frag(kong, "output[0] = float4(n.xy, roughness, pack_f32_i16(metallic, uint(0)));");
|
||||
node_shader_write_frag(kong, "output[1] = float4(basecol, occlusion);");
|
||||
node_shader_write_frag(kong, "output[2] = float4(0.0, 0.0, input.tex_coord.xy);");
|
||||
|
||||
parser_material_finalize(con);
|
||||
con->data->shader_from_source = true;
|
||||
gpu_create_shaders_from_kong(node_shader_get(kong), &con->data->vertex_shader, &con->data->fragment_shader, &con->data->_->vertex_shader_size,
|
||||
&con->data->_->fragment_shader_size);
|
||||
return con;
|
||||
}
|
||||
|
||||
material_data_t *make_particle_get_bullet_material() {
|
||||
if (particle_bullet_material != NULL) {
|
||||
return particle_bullet_material;
|
||||
}
|
||||
|
||||
node_shader_context_t *con = make_particle_bullet_run();
|
||||
shader_context_load(con->data);
|
||||
|
||||
shader_data_t *sd = GC_ALLOC_INIT(shader_data_t, {
|
||||
.name = "particle_bullet",
|
||||
.contexts = any_array_create_from_raw((void *[]){con->data}, 1),
|
||||
});
|
||||
material_context_t *mcon = GC_ALLOC_INIT(material_context_t, {
|
||||
.name = "mesh",
|
||||
.bind_constants = any_array_create_from_raw((void *[]){}, 0),
|
||||
.bind_textures = any_array_create_from_raw((void *[]){}, 0),
|
||||
});
|
||||
material_context_load(mcon);
|
||||
particle_bullet_material = GC_ALLOC_INIT(material_data_t, {
|
||||
.name = "particle_bullet",
|
||||
.shader = "",
|
||||
.contexts = any_array_create_from_raw((void *[]){mcon}, 1),
|
||||
._ = GC_ALLOC_INIT(material_data_runtime_t, {.uid = 0.0, .shader = sd}),
|
||||
});
|
||||
gc_root(particle_bullet_material);
|
||||
return particle_bullet_material;
|
||||
}
|
||||
|
||||
void make_particle_mask(node_shader_t *kong) {
|
||||
node_shader_add_out(kong, "wpos: float4");
|
||||
node_shader_add_constant(kong, "W: float4x4", "_world_matrix");
|
||||
|
||||
+717
-149
File diff suppressed because it is too large
Load Diff
@@ -164,7 +164,9 @@ void render_path_paint_commands_particle(i32 tid, char *texpaint, bool is_mask)
|
||||
void render_path_paint_commands_paint(bool dilation) {
|
||||
i32 tid = g_context->layer->id;
|
||||
|
||||
if (g_context->layer->texpaint_sculpt != NULL) {
|
||||
bool picking_tool = g_context->tool == TOOL_TYPE_COLORID || g_context->tool == TOOL_TYPE_PICKER || g_context->tool == TOOL_TYPE_MATERIAL ||
|
||||
g_context->tool == TOOL_TYPE_CURSOR;
|
||||
if (g_context->layer->texpaint_sculpt != NULL && !picking_tool) {
|
||||
render_path_sculpt_commands();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user