Skip to content

Commit

Permalink
rtt,texture: add forward_transforms parameter
Browse files Browse the repository at this point in the history
This commit changes the default behavior of the render target nodes (rtt,
texture) regarding the camera/model transformations: they are no longer
forwarded to the subgraph unless `forward_transforms` is enabled.
  • Loading branch information
mbouron committed Dec 4, 2023
1 parent 69058c4 commit 8682f79
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Versioning](https://semver.org/spec/v2.0.0.html) for `libnopegl`.
- `FastGaussianBlur` node to apply a post processing gaussian blur effect to a
scene that is suitable for real time rendering on mobile devices as well as
providing a resolution independent blurriness parameter
- `forward_transforms` parameter to the `Texture` and `RenderToTexture` nodes
to enable forwarding of the camera/model transformations

### Fixed
- Moving the split position in `ngl-diff`
Expand All @@ -39,6 +41,8 @@ Versioning](https://semver.org/spec/v2.0.0.html) for `libnopegl`.
`ngl_scene_init()` with the associated `ngl_scene_params` structure
- the `ngl_scene` structure is now private; its parameters can now be obtained
using `ngl_scene_get_params()`
- the `Texture` and `RenderToTexture` nodes no longer forward the camera/model
transformations by default

### Removed
- `%s_dimensions` uniform for 2D array and 3D images/textures, users must use
Expand Down
14 changes: 14 additions & 0 deletions libnopegl/nodes.specs
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,13 @@
"default": [0.000000,0.000000,0.000000,0.000000],
"flags": [],
"desc": "color used to clear the `color_texture`"
},
{
"name": "forward_transforms",
"type": "bool",
"default": 0,
"flags": [],
"desc": "enable forwarding of camera/model transformations"
}
]
},
Expand Down Expand Up @@ -3785,6 +3792,13 @@
"default": [0.000000,0.000000,0.000000,0.000000],
"flags": [],
"desc": "color used to clear the texture when used as an implicit render target"
},
{
"name": "forward_transforms",
"type": "bool",
"default": 0,
"flags": [],
"desc": "enable forwarding of camera/model transformations when used as an implicit render target"
}
]
},
Expand Down
5 changes: 5 additions & 0 deletions libnopegl/src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ int ngli_ctx_configure(struct ngl_ctx *s, const struct ngl_config *config)

NGLI_ALIGNED_MAT(matrix) = NGLI_MAT4_IDENTITY;
ngli_gpu_ctx_transform_projection_matrix(s->gpu_ctx, matrix);
memcpy(s->default_projection_matrix, matrix, sizeof(matrix));

ngli_darray_clear(&s->projection_matrix_stack);
if (!ngli_darray_push(&s->projection_matrix_stack, matrix)) {
ret = NGL_ERROR_MEMORY;
Expand Down Expand Up @@ -640,6 +642,9 @@ struct ngl_ctx *ngl_create(void)
ngli_darray_init(&s->activitycheck_nodes, sizeof(struct ngl_node *), 0);

static const NGLI_ALIGNED_MAT(id_matrix) = NGLI_MAT4_IDENTITY;
memcpy(s->default_modelview_matrix, id_matrix, sizeof(id_matrix));
memcpy(s->default_projection_matrix, id_matrix, sizeof(id_matrix));

if (!ngli_darray_push(&s->modelview_matrix_stack, id_matrix) ||
!ngli_darray_push(&s->projection_matrix_stack, id_matrix))
goto fail;
Expand Down
3 changes: 3 additions & 0 deletions libnopegl/src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ struct ngl_ctx {
struct rendertarget *available_rendertargets[2];
struct rendertarget *current_rendertarget;
int render_pass_started;
float default_modelview_matrix[16];
float default_projection_matrix[16];
struct darray modelview_matrix_stack;
struct darray projection_matrix_stack;

Expand Down Expand Up @@ -298,6 +300,7 @@ struct texture_opts {
int direct_rendering;
int clamp_video;
float clear_color[4];
int forward_transforms;
};

struct texture_priv {
Expand Down
15 changes: 15 additions & 0 deletions libnopegl/src/node_rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct rtt_opts {
struct ngl_node *depth_texture;
int32_t samples;
float clear_color[4];
int forward_transforms;
};

struct rtt_priv {
Expand Down Expand Up @@ -72,6 +73,8 @@ static const struct node_param rtt_params[] = {
.desc=NGLI_DOCSTRING("number of samples used for multisampling anti-aliasing")},
{"clear_color", NGLI_PARAM_TYPE_VEC4, OFFSET(clear_color),
.desc=NGLI_DOCSTRING("color used to clear the `color_texture`")},
{"forward_transforms", NGLI_PARAM_TYPE_BOOL, OFFSET(forward_transforms), {.i32=0},
.desc=NGLI_DOCSTRING("enable forwarding of camera/model transformations")},
{NULL}
};

Expand Down Expand Up @@ -442,6 +445,7 @@ static int rtt_resize(struct ngl_node *node)

static void rtt_draw(struct ngl_node *node)
{
struct ngl_ctx *ctx = node->ctx;
struct rtt_priv *s = node->priv_data;
const struct rtt_opts *o = node->opts;

Expand All @@ -451,9 +455,20 @@ static void rtt_draw(struct ngl_node *node)
return;
}

if (!o->forward_transforms) {
if (!ngli_darray_push(&ctx->modelview_matrix_stack, ctx->default_modelview_matrix) ||
!ngli_darray_push(&ctx->projection_matrix_stack, ctx->default_projection_matrix))
return;
}

ngli_rtt_begin(s->rtt_ctx);
ngli_node_draw(o->child);
ngli_rtt_end(s->rtt_ctx);

if (!o->forward_transforms) {
ngli_darray_pop(&ctx->modelview_matrix_stack);
ngli_darray_pop(&ctx->projection_matrix_stack);
}
}

static void rtt_release(struct ngl_node *node)
Expand Down
14 changes: 14 additions & 0 deletions libnopegl/src/node_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ static const struct node_param texture2d_params[] = {
.desc=NGLI_DOCSTRING("clamp ngl_texvideo() output to [0;1]")},
{"clear_color", NGLI_PARAM_TYPE_VEC4, OFFSET(clear_color),
.desc=NGLI_DOCSTRING("color used to clear the texture when used as an implicit render target")},
{"forward_transforms", NGLI_PARAM_TYPE_BOOL, OFFSET(forward_transforms), {.i32=0},
.desc=NGLI_DOCSTRING("enable forwarding of camera/model transformations when used as an implicit render target")},
{NULL}
};

Expand Down Expand Up @@ -556,6 +558,7 @@ static int rtt_resize(struct ngl_node *node)

static void texture_draw(struct ngl_node *node)
{
struct ngl_ctx *ctx = node->ctx;
struct texture_priv *s = node->priv_data;
struct texture_opts *o = node->opts;

Expand All @@ -568,9 +571,20 @@ static void texture_draw(struct ngl_node *node)
return;
}

if (!o->forward_transforms) {
if (!ngli_darray_push(&ctx->modelview_matrix_stack, ctx->default_modelview_matrix) ||
!ngli_darray_push(&ctx->projection_matrix_stack, ctx->default_projection_matrix))
return;
}

ngli_rtt_begin(s->rtt_ctx);
ngli_node_draw(o->data_src);
ngli_rtt_end(s->rtt_ctx);

if (!o->forward_transforms) {
ngli_darray_pop(&ctx->modelview_matrix_stack);
ngli_darray_pop(&ctx->projection_matrix_stack);
}
}

static void texture_release(struct ngl_node *node)
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def _get_random_layer(cfg: ngl.SceneCfg, rng, t0, t1, enable_computes, layer=4):
rtt = ngl.RenderToTexture(
child,
clear_color=_get_random_color(rng) + (1,),
forward_transforms=True,
)
rtt.add_color_textures(rtt_tex)
rtt_render = ngl.RenderTexture(
Expand Down

0 comments on commit 8682f79

Please sign in to comment.