Skip to content

Commit 2318393

Browse files
authored
UPBGE: Implement render extra attachment. (#774)
In the purpose of complex filters, data from the rendering other than the final color or the depth could be needed in filter like space reflection or ambient occlusion. The obvious one is the view normal, but any kind of data could be interesting passing from the albedo or diffuse to a debug color for screen ray cast. To expose such feature to the user, first a list of attachments need to be defined and secondly a way to output to these from simple material or node material. The attachments are to the number of 7, because the 8th is the first one dedicated to the final color. The UI is defined in "Render" panel under "Attachments" sub panel. A list of 7 items is exposed and the user can add an attachment or remove one from any item, the items have four properties, the name (only for debug), the type : either custom, normal or albedo, in case of custom the properties size and hdr are exposed, they both select the size of data into the attachment texture and it's precision type. Each GPU material is now tracking 8 out links, the first one is the same as the previous only out link and the other match the extra attachment. They are all iterated in codegen_call_functions to generate the GLSL lines for "gl_FragData[i] = ", a out link is registered using the function GPU_material_output_link. The attachment type "custom" is dedicated only for node materials where any kind of data could be output to a special node. This node is named "Output Attachment" and has only one input and a property for the index of the attachment, this node is responsible of registering the output link. The other attachment types "normal" and "abeldo" are detected in GPU_shaderesult_set and generate link for the view normal and the material diffuse (including vertex color and textures) multiplied by the object color. From the game engine side, the attachment info are converted into LA_Launcher and put inside RAS_ICanvas, this same class is now responsible of owning and creating the offscreens, by doing this the canvas can also detect properly a resize and recreate the offscreens. Other than that the function are equivalent, GetOffScreen is now called from RAS_ICanvas instead of RAS_Rasterizer. The attachments are readable form any filters defining the sampler uniform "bgl_DataTextures[7]", this uniform is bind as well as other uniforms in RAS_2DFilter::BindUniforms and the attachments textures in BindTextures/UnbindTextures. Because GPUOffScreen is not anymore used and is less flexible than hand configuration of a frame buffer, their sources are restored to the blender ones.
1 parent 9ec0894 commit 2318393

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+986
-731
lines changed

release/scripts/startup/bl_ui/properties_game.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# <pep8 compliant>
2020
import bpy
21-
from bpy.types import Panel, Menu
21+
from bpy.types import Panel, Menu, UIList
2222

2323

2424
class PhysicsButtonsPanel:
@@ -462,6 +462,42 @@ def draw(self, context):
462462
col.label("Exit Key:")
463463
col.prop(gs, "exit_key", text="", event=True)
464464

465+
class RENDER_UL_attachments(UIList):
466+
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
467+
if item is not None:
468+
layout.prop(item, "name", text="", emboss=False, icon="TEXTURE")
469+
layout.label(text=str(index))
470+
else:
471+
layout.label(text="", icon="TEXTURE")
472+
473+
class RENDER_PT_game_attachments(RenderButtonsPanel, Panel):
474+
bl_label = "Attachments"
475+
COMPAT_ENGINES = {'BLENDER_GAME'}
476+
477+
def draw(self, context):
478+
layout = self.layout
479+
480+
gs = context.scene.game_settings
481+
482+
row = layout.row()
483+
484+
row.template_list("RENDER_UL_attachments", "", gs, "attachment_slots", gs, "active_attachment_index", rows=2)
485+
486+
col = row.column(align=True)
487+
col.operator("scene.render_attachment_new", icon='ZOOMIN', text="")
488+
col.operator("scene.render_attachment_remove", icon='ZOOMOUT', text="")
489+
490+
attachment = gs.active_attachment
491+
492+
if attachment is not None:
493+
row = layout.row()
494+
row.prop(attachment, "type")
495+
row.prop(attachment, "hdr")
496+
497+
if attachment.type == "CUSTOM":
498+
row = layout.row()
499+
row.prop(attachment, "size")
500+
465501

466502
class RENDER_PT_game_animations(RenderButtonsPanel, Panel):
467503
bl_label = "Animations"
@@ -1061,10 +1097,12 @@ def draw(self, context):
10611097
RENDER_PT_game_stereo,
10621098
RENDER_PT_game_shading,
10631099
RENDER_PT_game_system,
1100+
RENDER_PT_game_attachments,
10641101
RENDER_PT_game_animations,
10651102
RENDER_PT_game_display,
10661103
RENDER_PT_game_color_management,
10671104
RENDER_PT_game_debug,
1105+
RENDER_UL_attachments,
10681106
SCENE_PT_game_physics,
10691107
SCENE_PT_game_physics_obstacles,
10701108
SCENE_PT_game_navmesh,

release/scripts/startup/nodeitems_builtins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def object_shader_nodes_poll(context):
165165
]),
166166
ShaderOldNodeCategory("SH_OUTPUT", "Output", items=[
167167
NodeItem("ShaderNodeOutput"),
168+
NodeItem("ShaderNodeOutputAttachment"),
168169
NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
169170
]),
170171
ShaderOldNodeCategory("SH_OP_COLOR", "Color", items=[

source/blender/blenkernel/BKE_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ struct ShadeResult;
800800
#define SH_NODE_OBJECT 1000
801801
#define SH_NODE_TIME 1001
802802
#define SH_NODE_PARALLAX 1002
803+
#define SH_NODE_OUTPUT_ATTACHMENT 1003
803804

804805
/* custom defines options for Material node */
805806
#define SH_NODE_MAT_DIFF 1

source/blender/blenkernel/intern/node.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,7 @@ void ntreeSetOutput(bNodeTree *ntree)
18791879
int output = 0;
18801880

18811881
/* we need a check for which output node should be tagged like this, below an exception */
1882-
if (node->type == CMP_NODE_OUTPUT_FILE)
1882+
if (ELEM(node->type, CMP_NODE_OUTPUT_FILE, SH_NODE_OUTPUT_ATTACHMENT))
18831883
continue;
18841884

18851885
/* there is more types having output class, each one is checked */
@@ -3637,6 +3637,7 @@ static void registerShaderNodes(void)
36373637
register_node_type_sh_uvmap();
36383638
register_node_type_sh_uvalongstroke();
36393639

3640+
register_node_type_sh_output_attachment();
36403641
register_node_type_sh_output_lamp();
36413642
register_node_type_sh_output_material();
36423643
register_node_type_sh_output_world();

source/blender/blenkernel/intern/scene.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,12 @@ void BKE_scene_free(Scene *sce)
518518

519519
BKE_previewimg_free(&sce->preview);
520520
curvemapping_free_data(&sce->r.mblur_shutter_curve);
521+
522+
for (unsigned short i = 0; i < GAME_ATTACHMENT_COUNT; ++i) {
523+
if (sce->gm.attachments[i]) {
524+
MEM_freeN(sce->gm.attachments[i]);
525+
}
526+
}
521527
}
522528

523529
void BKE_scene_init(Scene *sce)

source/blender/blenloader/intern/readfile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6305,6 +6305,10 @@ static void direct_link_scene(FileData *fd, Scene *sce)
63056305
sce->preview = direct_link_preview_image(fd, sce->preview);
63066306

63076307
direct_link_curvemapping(fd, &sce->r.mblur_shutter_curve);
6308+
6309+
for (unsigned short a = 0; a < GAME_ATTACHMENT_COUNT; a++) {
6310+
sce->gm.attachments[a] = newdataadr(fd, sce->gm.attachments[a]);
6311+
}
63086312
}
63096313

63106314
/* ************ READ WM ***************** */

source/blender/blenloader/intern/writefile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,6 +2735,12 @@ static void write_scene(WriteData *wd, Scene *sce)
27352735

27362736
write_previews(wd, sce->preview);
27372737
write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve);
2738+
2739+
for (unsigned short a = 0; a < GAME_ATTACHMENT_COUNT; a++) {
2740+
if (sce->gm.attachments[a]) {
2741+
writestruct(wd, DATA, RenderAttachment, 1, sce->gm.attachments[a]);
2742+
}
2743+
}
27382744
}
27392745

27402746
static void write_gpencil(WriteData *wd, bGPdata *gpd)

source/blender/editors/render/render_intern.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
5959
void SCENE_OT_render_view_add(struct wmOperatorType *ot);
6060
void SCENE_OT_render_view_remove(struct wmOperatorType *ot);
6161

62+
void SCENE_OT_render_attachment_new(struct wmOperatorType *ot);
63+
void SCENE_OT_render_attachment_remove(struct wmOperatorType *ot);
64+
6265
#ifdef WITH_FREESTYLE
6366
void SCENE_OT_freestyle_module_add(struct wmOperatorType *ot);
6467
void SCENE_OT_freestyle_module_remove(struct wmOperatorType *ot);

source/blender/editors/render/render_opengl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
634634
sizey = (scene->r.size * scene->r.ysch) / 100;
635635

636636
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
637-
ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, GPU_HDR_NONE, GPU_OFFSCREEN_DEPTH_COMPARE, err_out);
637+
ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out);
638638

639639
if (!ofs) {
640640
BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);

source/blender/editors/render/render_ops.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ void ED_operatortypes_render(void)
6262
WM_operatortype_append(SCENE_OT_render_view_add);
6363
WM_operatortype_append(SCENE_OT_render_view_remove);
6464

65+
WM_operatortype_append(SCENE_OT_render_attachment_new);
66+
WM_operatortype_append(SCENE_OT_render_attachment_remove);
67+
6568
#ifdef WITH_FREESTYLE
6669
WM_operatortype_append(SCENE_OT_freestyle_module_add);
6770
WM_operatortype_append(SCENE_OT_freestyle_module_remove);

0 commit comments

Comments
 (0)