paint: add depth_to_normal_pass
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
empty: float4;
|
||||
};
|
||||
|
||||
#[set(everything)]
|
||||
const sampler_linear: sampler;
|
||||
|
||||
#[set(everything)]
|
||||
const height_map: tex2d;
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
fun depth_to_normal_pass_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun depth_to_normal_pass_frag(input: vert_out): float4 {
|
||||
var ts: float = 1.0 / 768.0;
|
||||
var h00: float = sample_lod(height_map, sampler_linear, input.tex + float2(-2.0 * ts, -2.0 * ts), 0.0).r;
|
||||
var h01: float = sample_lod(height_map, sampler_linear, input.tex + float2(-ts, -2.0 * ts), 0.0).r;
|
||||
var h02: float = sample_lod(height_map, sampler_linear, input.tex + float2(0.0, -2.0 * ts), 0.0).r;
|
||||
var h03: float = sample_lod(height_map, sampler_linear, input.tex + float2( ts, -2.0 * ts), 0.0).r;
|
||||
var h04: float = sample_lod(height_map, sampler_linear, input.tex + float2( 2.0 * ts, -2.0 * ts), 0.0).r;
|
||||
var h10: float = sample_lod(height_map, sampler_linear, input.tex + float2(-2.0 * ts, -ts), 0.0).r;
|
||||
var h11: float = sample_lod(height_map, sampler_linear, input.tex + float2(-ts, -ts), 0.0).r;
|
||||
var h12: float = sample_lod(height_map, sampler_linear, input.tex + float2(0.0, -ts), 0.0).r;
|
||||
var h13: float = sample_lod(height_map, sampler_linear, input.tex + float2( ts, -ts), 0.0).r;
|
||||
var h14: float = sample_lod(height_map, sampler_linear, input.tex + float2( 2.0 * ts, -ts), 0.0).r;
|
||||
var h20: float = sample_lod(height_map, sampler_linear, input.tex + float2(-2.0 * ts, 0.0), 0.0).r;
|
||||
var h21: float = sample_lod(height_map, sampler_linear, input.tex + float2(-ts, 0.0), 0.0).r;
|
||||
var h23: float = sample_lod(height_map, sampler_linear, input.tex + float2( ts, 0.0), 0.0).r;
|
||||
var h24: float = sample_lod(height_map, sampler_linear, input.tex + float2( 2.0 * ts, 0.0), 0.0).r;
|
||||
var h30: float = sample_lod(height_map, sampler_linear, input.tex + float2(-2.0 * ts, ts), 0.0).r;
|
||||
var h31: float = sample_lod(height_map, sampler_linear, input.tex + float2(-ts, ts), 0.0).r;
|
||||
var h32: float = sample_lod(height_map, sampler_linear, input.tex + float2(0.0, ts), 0.0).r;
|
||||
var h33: float = sample_lod(height_map, sampler_linear, input.tex + float2( ts, ts), 0.0).r;
|
||||
var h34: float = sample_lod(height_map, sampler_linear, input.tex + float2( 2.0 * ts, ts), 0.0).r;
|
||||
var h40: float = sample_lod(height_map, sampler_linear, input.tex + float2(-2.0 * ts, 2.0 * ts), 0.0).r;
|
||||
var h41: float = sample_lod(height_map, sampler_linear, input.tex + float2(-ts, 2.0 * ts), 0.0).r;
|
||||
var h42: float = sample_lod(height_map, sampler_linear, input.tex + float2(0.0, 2.0 * ts), 0.0).r;
|
||||
var h43: float = sample_lod(height_map, sampler_linear, input.tex + float2( ts, 2.0 * ts), 0.0).r;
|
||||
var h44: float = sample_lod(height_map, sampler_linear, input.tex + float2( 2.0 * ts, 2.0 * ts), 0.0).r;
|
||||
var dx: float = 2.0 * (h00 - h04) + 1.0 * (h01 - h03)
|
||||
+ 3.0 * (h10 - h14) + 2.0 * (h11 - h13)
|
||||
+ 4.0 * (h20 - h24) + 3.0 * (h21 - h23)
|
||||
+ 3.0 * (h30 - h34) + 2.0 * (h31 - h33)
|
||||
+ 2.0 * (h40 - h44) + 1.0 * (h41 - h43);
|
||||
var dy: float = 2.0 * (h40 - h00) + 3.0 * (h41 - h01) + 4.0 * (h42 - h02) + 3.0 * (h43 - h03) + 2.0 * (h44 - h04)
|
||||
+ 1.0 * (h30 - h10) + 2.0 * (h31 - h11) + 3.0 * (h32 - h12) + 2.0 * (h33 - h13) + 1.0 * (h34 - h14);
|
||||
var normal: float3 = normalize(float3(dx, dy, 1.4375));
|
||||
normal = normal * 0.5 + 0.5;
|
||||
return float4(normal.x, normal.y, normal.z, 1.0);
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = depth_to_normal_pass_vert;
|
||||
fragment = depth_to_normal_pass_frag;
|
||||
}
|
||||
@@ -121,6 +121,16 @@ void image_to_pbr_node_all_done(void *_) {
|
||||
render_path_create_render_target(t);
|
||||
occmap_blurred = t;
|
||||
}
|
||||
render_target_t *normmap;
|
||||
{
|
||||
render_target_t *t = render_target_create();
|
||||
t->name = "normmap";
|
||||
t->width = 768;
|
||||
t->height = 768;
|
||||
t->format = "RGBA32";
|
||||
render_path_create_render_target(t);
|
||||
normmap = t;
|
||||
}
|
||||
{
|
||||
render_target_t *t = render_target_create();
|
||||
t->name = "_height_map";
|
||||
@@ -130,6 +140,7 @@ void image_to_pbr_node_all_done(void *_) {
|
||||
t->_image = image_to_pbr_node_result_height;
|
||||
any_map_set(render_path_render_targets, t->name, t);
|
||||
}
|
||||
render_target_t *normal_map_rt;
|
||||
{
|
||||
render_target_t *t = render_target_create();
|
||||
t->name = "_normal_map";
|
||||
@@ -138,12 +149,23 @@ void image_to_pbr_node_all_done(void *_) {
|
||||
t->format = "RGBA32";
|
||||
t->_image = image_to_pbr_node_result_normal;
|
||||
any_map_set(render_path_render_targets, t->name, t);
|
||||
normal_map_rt = t;
|
||||
}
|
||||
|
||||
render_path_load_shader("Scene/depth_to_normal_pass/depth_to_normal_pass");
|
||||
render_path_load_shader("Scene/depth_to_ao_pass/depth_to_ao_pass");
|
||||
render_path_load_shader("Scene/ssao_blur_pass/ssao_blur_pass_x");
|
||||
render_path_load_shader("Scene/ssao_blur_pass/ssao_blur_pass_y");
|
||||
|
||||
render_path_set_target("normmap", NULL, NULL, GPU_CLEAR_NONE, 0, 0.0);
|
||||
render_path_bind_target("_height_map", "height_map");
|
||||
render_path_draw_shader("Scene/depth_to_normal_pass/depth_to_normal_pass");
|
||||
|
||||
gc_unroot(image_to_pbr_node_result_normal);
|
||||
image_to_pbr_node_result_normal = normmap->_image;
|
||||
gc_root(image_to_pbr_node_result_normal);
|
||||
normal_map_rt->_image = normmap->_image;
|
||||
|
||||
render_path_set_target("occmap", NULL, NULL, GPU_CLEAR_NONE, 0, 0.0);
|
||||
render_path_bind_target("_height_map", "height_map");
|
||||
render_path_bind_target("_normal_map", "normal_map");
|
||||
|
||||
+34
-1
@@ -2848,7 +2848,7 @@ scene_t *startup_get_scene(void) {
|
||||
}
|
||||
|
||||
// shader_datas
|
||||
scene->shader_datas = any_array_create(17);
|
||||
scene->shader_datas = any_array_create(18);
|
||||
{
|
||||
shader_data_t *sd = (shader_data_t *)gc_alloc(sizeof(shader_data_t));
|
||||
sd->name = "armdefault_data";
|
||||
@@ -4210,6 +4210,39 @@ scene_t *startup_get_scene(void) {
|
||||
}
|
||||
scene->shader_datas->buffer[16] = sd;
|
||||
}
|
||||
{
|
||||
shader_data_t *sd = (shader_data_t *)gc_alloc(sizeof(shader_data_t));
|
||||
sd->name = "depth_to_normal_pass";
|
||||
sd->contexts = any_array_create(1);
|
||||
{
|
||||
shader_context_t *sc = (shader_context_t *)gc_alloc(sizeof(shader_context_t));
|
||||
sc->name = "depth_to_normal_pass";
|
||||
sc->depth_write = false;
|
||||
sc->compare_mode = "always";
|
||||
sc->cull_mode = "none";
|
||||
sc->vertex_shader = "depth_to_normal_pass.vert";
|
||||
sc->fragment_shader = "depth_to_normal_pass.frag";
|
||||
sc->shader_from_source = false;
|
||||
sc->color_attachments = string_array_create(1);
|
||||
sc->color_attachments->buffer[0] = "RGBA32";
|
||||
sc->vertex_elements = (vertex_element_t_array_t *)any_array_create(1);
|
||||
{
|
||||
vertex_element_t *ve = (vertex_element_t *)gc_alloc(sizeof(vertex_element_t));
|
||||
ve->name = "pos";
|
||||
ve->data = "float2";
|
||||
sc->vertex_elements->buffer[0] = ve;
|
||||
}
|
||||
sc->constants = (shader_const_t_array_t *)any_array_create(0);
|
||||
sc->texture_units = (tex_unit_t_array_t *)any_array_create(1);
|
||||
{
|
||||
tex_unit_t *tu = (tex_unit_t *)gc_alloc(sizeof(tex_unit_t));
|
||||
tu->name = "height_map";
|
||||
sc->texture_units->buffer[0] = tu;
|
||||
}
|
||||
sd->contexts->buffer[0] = sc;
|
||||
}
|
||||
scene->shader_datas->buffer[17] = sd;
|
||||
}
|
||||
|
||||
// objects
|
||||
scene->objects = any_array_create(5);
|
||||
|
||||
Reference in New Issue
Block a user