Page MenuHome

BGE: add pre-render 2D filters option
AbandonedPublic

Authored by Quentin Wenger (Matpi) on Jun 24 2015, 6:48 PM.

Details

Summary

The goal of this patch is to provide a way to render 2D filters before the scene, for example to create custom skies or backgrounds.

The patch also gives access to new vec3 uniforms bgl_BackgroundColor, bgl_AmbientColor and bgl_MistColor (values provided by KX_WorldInfo).

This feature has been suggested by @Ulysse Martin (youle).

Diff Detail

Repository
rB Blender
Branch
blender_ge_prerender_2dfilters

Event Timeline

Small enhancements.

  • Other enhancement.

I have only made a Quick look at it. I don't tested it.

Did you tested your patch with the video texture module (render camera to texture)?

source/gameengine/Converter/KX_ConvertActuators.cpp
997–999

The second case is useless. If not ACT_2DFILTER_PRERENDER we always use ACT_2DFILTER_POSTRENDER as default.

source/gameengine/Ketsji/KX_Scene.cpp
2102–2103

vector<STR_String> &propNames, void *gameObj

2103

STR_String &text

2108

RAS_ICanvas *canvas

source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
186

vector<STR_String> &propNames

189

std::vector<STR_String> *m_properties.

Are there four or one one space between > and *?

405

(RAS_ICanvas *canvas

518–519

vector<STR_String> &propNames, void *gameObj

519

STR_String &text

source/gameengine/Rasterizer/RAS_2DFilterManager.h
114

RAS_ICanvas *canvas

116–117

std::vector<STR_String> &propNames, void *gameObj

117

STR_String &text

Quentin Wenger (Matpi) marked 12 inline comments as done.Jun 24 2015, 10:52 PM
Quentin Wenger (Matpi) added inline comments.
source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
189

It was a tab. Fixed.

Quentin Wenger (Matpi) marked an inline comment as done.
Quentin Wenger (Matpi) edited edge metadata.
  • Changes as suggested by HG1.
  • Add proper initialization value.
  • Make previous change more consistent.
source/blender/editors/space_logic/logic_window.c
1682

Why an empty string instead of a NULL pointer ?

source/blender/editors/space_logic/logic_window.c
1682

To have a continuous layout row, see picture above.

Did you tested your patch with the video texture module (render camera to texture)?

ATM the VideoTexture module doesn't care about pre-rendering of filters.

It would be quite easy do add basic communication between them (i.e. pre-render filters for cameras used by the RenderToTexture feature) - though there would be a small bug to be fixed then.

But IMHO if we want it to be really useful, we should add uniforms representing position/orientation/perspective of the camera...

Basic example: One uses this patched version to generate a procedural sky gradient. Imagine now that one wants to add plane in the scene with a videotexture on it, using rendering from another camera somewhere else in the scene. If we want the pre-rendering feature to be useful with the videotexture one, we have to make sure that the sky gradient is computed with respect to the orientation of the second camera. Thus we should be able to have access to uniforms referencing the position/orientation/perspective of that second camera in our custom filter. We can't simply pass in uniforms from the object in which the 2D Filters actuator is stored, because we have 2 cameras involved (and we cannot simply distinguish between those two cams, unless we create another uniform referencing the currently used camera, etc...).

Is that something needed, from your point of view?

Hi! Thanks for all your work! About your last comment: Yes I thought about this when I had the idea of prerender pass, but I thought that we could pass camera position and orientation with uniforms to the filter. But if you can include it in your revision, it would be great!

Yes I thought about this when I had the idea of prerender pass, but I thought that we could pass camera position and orientation with uniforms to the filter. But if you can include it in your revision, it would be great!

Yes we can pass information from one camera, but not if we use a second one for videotexture rendering - so the question is more about videotexture than more uniforms.

@Quentin Pointillart (Quentin) Wenger (Matpi) and Ulysse MARTIN (youle) actually I don't know how useful this patch is. Maybe I misunderstand something. But I think you can also simply use background scene to do the same.
Also the uniforms can passed as three floats for eg. the ambient color.

I tried to passing vector or matrices with properties like I have done in D1370, but it was not working.
So I have done a script which allows to pass textures, matrices and vectors to the 2D filter. This allows to easy directly bind a matrix, instead of passing 16 floats to the 2D filter for a matrix. http://blenderartists.org/forum/showthread.php?374488-Bind-custom-uniform-values-to-a-2D-filter-%28using-bgl-wrapper%29
At the weekend I want to write a patch that allows to to the same with a new API like we have for the material GLSL shader. Actually I only don't know if I should add the new API, to a new general new class or to the filter actuator.

@Quentin Pointillart (Quentin) Wenger (Matpi)
Also It would be fine if you split the patch into two. One for the 2D filters pretender and one for the new uniforms. Because the two things are not related.
In general so it is easier to review, and so the feature will be applied faster and if we need to revert a patch we don't revert two things.

source/gameengine/Ketsji/KX_Scene.h
602–604

STR_String> &propNames, void *gameObj

603

STR_String &text

604

RAS_ICanvas *canvas

@Quentin Pointillart (Quentin) Wenger (Matpi) and Ulysse MARTIN (youle) actually I don't know how useful this patch is. Maybe I misunderstand something. But I think you can also simply use background scene to do the same.

You're right, background scenes can be used up to some point. This patch

  1. simplifies that use (no need for background scene)
  2. could - if further developed that way - allow using filters with videotexture; ATM videotexture don't care about background scenes either.

Also the uniforms can passed as three floats for eg. the ambient color.

I tried to passing vector or matrices with properties like I have done in D1370, but it was not working.
So I have done a script which allows to pass textures, matrices and vectors to the 2D filter. This allows to easy directly bind a matrix, instead of passing 16 floats to the 2D filter for a matrix. http://blenderartists.org/forum/showthread.php?374488-Bind-custom-uniform-values-to-a-2D-filter-%28using-bgl-wrapper%29

Yes, but as said before, this doesn't work for videotexture unless something else is coded in this patch.

At the weekend I want to write a patch that allows to to the same with a new API like we have for the material GLSL shader. Actually I only don't know if I should add the new API, to a new general new class or to the filter actuator.

Ok, looking forward to see what you can do there. ;)

@Quentin Pointillart (Quentin) Wenger (Matpi)
Also It would be fine if you split the patch into two. One for the 2D filters pretender and one for the new uniforms. Because the two things are not related.
In general so it is easier to review, and so the feature will be applied faster and if we need to revert a patch we don't revert two things.

Yep, true. My motivation for putting both patches together was that a background/pre-render filter is potentially much more concerned about ambient/mist/background color than a post-render one, so I thought both things belong together. See next paragraph for further explaination.

So the question is - what do we do with this patch. IMO there is a fundamental choice to be made here:

  • either we decide that using 2D filters on background scenes is a convenient enough way to use
  • or we decide we should have an easier/more straightforward way, ie. as provided by this patch: pre-render filters

Then, there are some other, smaller features that more ore less belong to the same subject:

  • interaction between videotexture and 2d filters
  • interaction between videotexture and background scenes
  • uniforms: colors (back/mist/ambient)
  • uniforms: position/orientation/perspective of the currently used camera.

I believe we should agree on the first choice; then, other decisions about the other points can follow and be implemented if needed; for some of the points above there already is at least a workaround, but I think following points simply miss ATM:

  • retrieval of the ambient/mist/back colors (at the moment they can only be set), either in Python or as uniforms, or both
  • interaction of videotextures, either with background scenes or filters.

While I like the idea of more built in uniforms, I don't really see the need for the pre render filter. You can already use depth testing in a regular 2D filter to render a background, and it would be cheaper. I see some potential use with logic bricks, but I don't see many people using the built in filters specifically for a background (or at all really).

Yep, makes sense.

I close then, and I'll make a proposal about what features should be added (uniforms, interaction with videotextures, etc.).