diff --git a/CHANGELOG.md b/CHANGELOG.md index f03e97f25..9f2162352 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,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` @@ -41,6 +43,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 diff --git a/libnopegl/nodes.specs b/libnopegl/nodes.specs index 7cfe17150..edcbc52bb 100644 --- a/libnopegl/nodes.specs +++ b/libnopegl/nodes.specs @@ -3196,6 +3196,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" } ] }, @@ -3778,6 +3785,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" } ] }, diff --git a/libnopegl/src/api.c b/libnopegl/src/api.c index 911efbb07..6965377ae 100644 --- a/libnopegl/src/api.c +++ b/libnopegl/src/api.c @@ -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; @@ -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; diff --git a/libnopegl/src/internal.h b/libnopegl/src/internal.h index a9bfa9f97..e0034cc81 100644 --- a/libnopegl/src/internal.h +++ b/libnopegl/src/internal.h @@ -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; @@ -298,6 +300,7 @@ struct texture_opts { int direct_rendering; int clamp_video; float clear_color[4]; + int forward_transforms; }; struct texture_priv { diff --git a/libnopegl/src/node_rtt.c b/libnopegl/src/node_rtt.c index 3937b1ccb..c27740eab 100644 --- a/libnopegl/src/node_rtt.c +++ b/libnopegl/src/node_rtt.c @@ -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 { @@ -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} }; @@ -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; @@ -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) diff --git a/libnopegl/src/node_texture.c b/libnopegl/src/node_texture.c index 51d7b10d3..285f78d05 100644 --- a/libnopegl/src/node_texture.c +++ b/libnopegl/src/node_texture.c @@ -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} }; @@ -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; @@ -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) diff --git a/tests/benchmark.py b/tests/benchmark.py index 7ba175532..95acd6165 100644 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -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(