[Bf-blender-cvs] [8fa55d9] master: World background working on cycle nodes.

Antony Riakiotakis noreply at git.blender.org
Wed Nov 26 15:07:56 CET 2014


Commit: 8fa55d95e43392a0e7925e1327e86220a33b4394
Author: Antony Riakiotakis
Date:   Mon Nov 24 17:18:56 2014 +0100
Branches: master
https://developer.blender.org/rB8fa55d95e43392a0e7925e1327e86220a33b4394

World background working on cycle nodes.

This is added in the spirit of the general cycles GLSL system
which is pretty much WIP still.

This will only work on cycles at the moment but generating for blender
internal is possible too of course though it will be done in a separate
commit.

This hasn't been tested with all and every node in cycles, but
environment and regular textures with texture coordinates work.

There is some difference between the way cycles treats some coordinates,
which is in world space and the way GLSL treats them, which is in view
space.
We might want to explore and improve this further in the future.

...also </drumroll>

===================================================================

M	SConstruct
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/world.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/render/render_update.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/SConscript
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_codegen.h
M	source/blender/gpu/intern/gpu_material.c
M	source/blender/gpu/shaders/gpu_shader_material.glsl
A	source/blender/gpu/shaders/gpu_shader_vertex_world.glsl
M	source/blender/makesdna/DNA_world_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_world.c
M	source/blender/nodes/shader/nodes/node_shader_background.c
M	source/blender/nodes/shader/nodes/node_shader_output_world.c
M	source/blender/nodes/shader/nodes/node_shader_tex_coord.c
M	source/blender/nodes/shader/nodes/node_shader_tex_environment.c

===================================================================

diff --git a/SConstruct b/SConstruct
index 45c9ae3..4c2097f 100644
--- a/SConstruct
+++ b/SConstruct
@@ -757,6 +757,7 @@ if B.targets != ['cudakernels']:
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vertex.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vertex_world.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl")
     data_to_c_simple("intern/opencolorio/gpu_shader_display_transform.glsl")
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index ea1b9a3f..af2080c 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -116,7 +116,7 @@ void BKE_material_free_ex(Material *ma, bool do_id_user)
 		MEM_freeN(ma->texpaintslot);
 
 	if (ma->gpumaterial.first)
-		GPU_material_free(ma);
+		GPU_material_free(&ma->gpumaterial);
 }
 
 void init_material(Material *ma)
@@ -1724,7 +1724,7 @@ void paste_matcopybuf(Material *ma)
 		MEM_freeN(ma->nodetree);
 	}
 
-	GPU_material_free(ma);
+	GPU_material_free(&ma->gpumaterial);
 
 	id = (ma->id);
 	memcpy(ma, &matcopybuf, sizeof(Material));
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index 8e3c923..29a345e 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -49,6 +49,8 @@
 #include "BKE_node.h"
 #include "BKE_world.h"
 
+#include "GPU_material.h"
+
 void BKE_world_free_ex(World *wrld, bool do_id_user)
 {
 	MTex *mtex;
@@ -69,6 +71,9 @@ void BKE_world_free_ex(World *wrld, bool do_id_user)
 		MEM_freeN(wrld->nodetree);
 	}
 
+	if (wrld->gpumaterial.first)
+		GPU_material_free(&wrld->gpumaterial);
+	
 	BKE_icon_delete((struct ID *)wrld);
 	wrld->id.icon_id = 0;
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9b043c6..05af147 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3260,6 +3260,7 @@ static void direct_link_world(FileData *fd, World *wrld)
 	}
 	
 	wrld->preview = direct_link_preview_image(fd, wrld->preview);
+	BLI_listbase_clear(&wrld->gpumaterial);
 }
 
 
diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c
index 1320fed..e4e16dd 100644
--- a/source/blender/editors/render/render_update.c
+++ b/source/blender/editors/render/render_update.c
@@ -281,7 +281,7 @@ static void material_changed(Main *bmain, Material *ma)
 
 	/* glsl */
 	if (ma->gpumaterial.first)
-		GPU_material_free(ma);
+		GPU_material_free(&ma->gpumaterial);
 
 	/* find node materials using this */
 	for (parent = bmain->mat.first; parent; parent = parent->id.next) {
@@ -295,7 +295,7 @@ static void material_changed(Main *bmain, Material *ma)
 		BKE_icon_changed(BKE_icon_getid(&parent->id));
 
 		if (parent->gpumaterial.first)
-			GPU_material_free(parent);
+			GPU_material_free(&parent->gpumaterial);
 	}
 
 	/* find if we have a scene with textured display */
@@ -341,10 +341,10 @@ static void lamp_changed(Main *bmain, Lamp *la)
 
 	for (ma = bmain->mat.first; ma; ma = ma->id.next)
 		if (ma->gpumaterial.first)
-			GPU_material_free(ma);
+			GPU_material_free(&ma->gpumaterial);
 
 	if (defmaterial.gpumaterial.first)
-		GPU_material_free(&defmaterial);
+		GPU_material_free(&defmaterial.gpumaterial);
 }
 
 static int material_uses_texture(Material *ma, Tex *tex)
@@ -382,7 +382,7 @@ static void texture_changed(Main *bmain, Tex *tex)
 		BKE_icon_changed(BKE_icon_getid(&ma->id));
 
 		if (ma->gpumaterial.first)
-			GPU_material_free(ma);
+			GPU_material_free(&ma->gpumaterial);
 	}
 
 	/* find lamps */
@@ -411,6 +411,9 @@ static void texture_changed(Main *bmain, Tex *tex)
 		}
 
 		BKE_icon_changed(BKE_icon_getid(&wo->id));
+		
+		if (wo->gpumaterial.first)
+			GPU_material_free(&wo->gpumaterial);		
 	}
 
 	/* find compositing nodes */
@@ -456,14 +459,17 @@ static void world_changed(Main *bmain, World *wo)
 
 	/* icons */
 	BKE_icon_changed(BKE_icon_getid(&wo->id));
-
+	
 	/* glsl */
 	for (ma = bmain->mat.first; ma; ma = ma->id.next)
 		if (ma->gpumaterial.first)
-			GPU_material_free(ma);
+			GPU_material_free(&ma->gpumaterial);
 
 	if (defmaterial.gpumaterial.first)
-		GPU_material_free(&defmaterial);
+		GPU_material_free(&defmaterial.gpumaterial);
+	
+	if (wo->gpumaterial.first)
+		GPU_material_free(&wo->gpumaterial);
 }
 
 static void image_changed(Main *bmain, Image *ima)
@@ -483,6 +489,7 @@ static void scene_changed(Main *bmain, Scene *scene)
 {
 	Object *ob;
 	Material *ma;
+	World *wo;
 
 	/* glsl */
 	for (ob = bmain->object.first; ob; ob = ob->id.next) {
@@ -498,10 +505,14 @@ static void scene_changed(Main *bmain, Scene *scene)
 
 	for (ma = bmain->mat.first; ma; ma = ma->id.next)
 		if (ma->gpumaterial.first)
-			GPU_material_free(ma);
+			GPU_material_free(&ma->gpumaterial);
 
+	for (wo = bmain->world.first; wo; wo = wo->id.next)
+		if (wo->gpumaterial.first)
+			GPU_material_free(&wo->gpumaterial);
+	
 	if (defmaterial.gpumaterial.first)
-		GPU_material_free(&defmaterial);
+		GPU_material_free(&defmaterial.gpumaterial);
 }
 
 void ED_render_id_flush_update(Main *bmain, ID *id)
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index d52a351..1b82e89 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -342,14 +342,22 @@ void snode_dag_update(bContext *C, SpaceNode *snode)
 
 void snode_notify(bContext *C, SpaceNode *snode)
 {
+	ID *id = snode->id;
+
 	WM_event_add_notifier(C, NC_NODE | NA_EDITED, NULL);
 
-	if (ED_node_is_shader(snode))
-		WM_event_add_notifier(C, NC_MATERIAL | ND_NODES, snode->id);
+	if (ED_node_is_shader(snode)) {
+		if (GS(id->name) == ID_MA)
+			WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id);
+		else if (GS(id->name) == ID_LA)
+			WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id);
+		else if (GS(id->name) == ID_WO)
+			WM_main_add_notifier(NC_WORLD | ND_WORLD, id);
+	}
 	else if (ED_node_is_compositor(snode))
-		WM_event_add_notifier(C, NC_SCENE | ND_NODES, snode->id);
+		WM_event_add_notifier(C, NC_SCENE | ND_NODES, id);
 	else if (ED_node_is_texture(snode))
-		WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, snode->id);
+		WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, id);
 }
 
 void ED_node_set_tree_type(SpaceNode *snode, bNodeTreeType *typeinfo)
@@ -662,11 +670,16 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
 			/* if active texture changed, free glsl materials */
 			if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) {
 				Material *ma;
+				World *wo;
 
 				for (ma = bmain->mat.first; ma; ma = ma->id.next)
 					if (ma->nodetree && ma->use_nodes && ntreeHasTree(ma->nodetree, ntree))
-						GPU_material_free(ma);
+						GPU_material_free(&ma->gpumaterial);
 
+				for (wo = bmain->world.first; wo; wo = wo->id.next)
+					if (wo->nodetree && wo->use_nodes && ntreeHasTree(wo->nodetree, ntree))
+						GPU_material_free(&wo->gpumaterial);
+				
 				WM_main_add_notifier(NC_IMAGE, NULL);
 			}
 
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 81f926e..95b11d1 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -414,7 +414,7 @@ static void view3d_free(SpaceLink *sl)
 	/* matcap material, its preview rect gets freed via icons */
 	if (vd->defmaterial) {
 		if (vd->defmaterial->gpumaterial.first)
-			GPU_material_free(vd->defmaterial);
+			GPU_material_free(&vd->defmaterial->gpumaterial);
 		BKE_previewimg_free(&vd->defmaterial->preview);
 		MEM_freeN(vd->defmaterial);
 	}
@@ -1168,6 +1168,7 @@ static void space_view3d_listener(bScreen *UNUSED(sc), ScrArea *sa, struct wmNot
 		case NC_WORLD:
 			switch (wmn->data) {
 				case ND_WORLD_DRAW:
+				case ND_WORLD:
 					if (v3d->flag3 & V3D_SHOW_WORLD)
 						ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
 					break;
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index d4a0c01..26ce64f 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2807,10 +2807,34 @@ void ED_view3d_draw_offscreen_init(Scene *scene, View3D *v3d)
 static void view3d_main_area_clear(Scene *scene, View3D *v3d, ARegion *ar, bool force)
 {
 	/* clear background */
-	if (scene->world && ((v3d->flag3 & V3D_SHOW_WORLD) || force)) {  /* clear with solid color */
+	if (scene->world && ((v3d->flag3 & V3D_SHOW_WORLD) || force)) {
 		float alpha = (force) ? 1.0f : 0.0;
+		bool glsl = GPU_glsl_support() && BKE_scene_use_new_shading_nodes(scene) && scene->world->nodetree && scene->world->use_nodes;
 		
-		if (scene->world->skytype & WO_SKYBLEND) {  /* blend sky */
+		if (glsl) {
+			RegionView3D *rv3d = ar->regiondata;
+			GPUMaterial *gpumat = GPU_material_world(scene, scene->world);
+			
+			/* calculate full shader for background */
+			GPU_material_bind(gpumat, 1, 1, 1.0, true, rv3d->viewmat, rv3d->viewinv, (v3d->scenelock != 0));
+			
+			glEnable(GL_DEPTH_TEST);
+			glDepthFunc(GL_ALWAYS);
+			glShadeModel(GL_SMOOTH);
+			glBegin(GL_QUADS);
+			glVertex3f(-1.0, -1.0, 1.0);
+			glVertex3f(1.0, -1.0, 1.0);
+			glVertex3f(1.0, 1.0, 1.0);
+			glVertex3f(-1.0, 1.0, 1.0);
+			glEnd();
+			glShadeModel(GL_FLAT);
+
+			GPU_material_unbind(gpumat);
+			
+			glDepthFunc(GL_LEQUAL);
+			glDisable(GL_DEPTH_TEST);
+		}
+		else if (scene->world->skytype & WO_SKYBLEND) {  /* blend sky */
 			int x, y;
 			float col_hor[3];
 			float col_zen[3];
@@ -3009,7 +3033,9 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
 		 * warning! can be slow so only free animated images - campbell */
 		GPU_free_images_anim();
 	}
-
+	/* setup view ma

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list