[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48099] branches/ge_harmony: There is going to be some overlap with the 2010 GSoC custom shader project and Harmony phase 2 .

Daniel Stokes kupomail at gmail.com
Wed Jun 20 00:41:56 CEST 2012


Revision: 48099
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48099
Author:   kupoman
Date:     2012-06-19 22:41:47 +0000 (Tue, 19 Jun 2012)
Log Message:
-----------
There is going to be some overlap with the 2010 GSoC custom shader project and Harmony phase 2. Therefore I am bringing it into the branch now to make use of the code already in it. It is going to require some cleanup and refactoring, but it should be a good start.

Modified Paths:
--------------
    branches/ge_harmony/doc/python_api/rst/bge.types.rst
    branches/ge_harmony/release/scripts/startup/bl_ui/properties_material.py
    branches/ge_harmony/source/blender/blenkernel/BKE_material.h
    branches/ge_harmony/source/blender/blenkernel/intern/material.c
    branches/ge_harmony/source/blender/blenloader/intern/readfile.c
    branches/ge_harmony/source/blender/editors/render/render_intern.h
    branches/ge_harmony/source/blender/editors/render/render_ops.c
    branches/ge_harmony/source/blender/editors/render/render_shading.c
    branches/ge_harmony/source/blender/gpu/GPU_extensions.h
    branches/ge_harmony/source/blender/gpu/GPU_material.h
    branches/ge_harmony/source/blender/gpu/intern/gpu_codegen.c
    branches/ge_harmony/source/blender/gpu/intern/gpu_codegen.h
    branches/ge_harmony/source/blender/gpu/intern/gpu_draw.c
    branches/ge_harmony/source/blender/gpu/intern/gpu_extensions.c
    branches/ge_harmony/source/blender/gpu/intern/gpu_material.c
    branches/ge_harmony/source/blender/makesdna/DNA_material_types.h
    branches/ge_harmony/source/blender/makesrna/intern/rna_material.c
    branches/ge_harmony/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    branches/ge_harmony/source/gameengine/Ketsji/BL_BlenderShader.cpp
    branches/ge_harmony/source/gameengine/Ketsji/BL_BlenderShader.h
    branches/ge_harmony/source/gameengine/Ketsji/CMakeLists.txt
    branches/ge_harmony/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
    branches/ge_harmony/source/gameengine/Ketsji/KX_BlenderMaterial.h
    branches/ge_harmony/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/ge_harmony/source/gameengine/Ketsji/KX_GameObject.h
    branches/ge_harmony/source/gameengine/Ketsji/KX_PythonInit.cpp
    branches/ge_harmony/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
    branches/ge_harmony/source/gameengine/Ketsji/KX_PythonSeq.cpp
    branches/ge_harmony/source/gameengine/Ketsji/KX_PythonSeq.h
    branches/ge_harmony/source/gameengine/Rasterizer/CMakeLists.txt
    branches/ge_harmony/source/gameengine/Rasterizer/RAS_MaterialBucket.h
    branches/ge_harmony/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.cpp
    branches/ge_harmony/source/gameengine/Rasterizer/SConscript

Added Paths:
-----------
    branches/ge_harmony/source/gameengine/Ketsji/KX_PythonShaders.cpp
    branches/ge_harmony/source/gameengine/Ketsji/KX_PythonShaders.h

Modified: branches/ge_harmony/doc/python_api/rst/bge.types.rst
===================================================================
--- branches/ge_harmony/doc/python_api/rst/bge.types.rst	2012-06-19 22:17:19 UTC (rev 48098)
+++ branches/ge_harmony/doc/python_api/rst/bge.types.rst	2012-06-19 22:41:47 UTC (rev 48099)
@@ -670,6 +670,12 @@
 
    KX_BlenderMaterial
 
+   .. attribute:: blender_shader
+   
+      The current Blender shader that the material is using
+	  
+	  :type: :class:`Shader`
+
    .. method:: getShader()
 
       Returns the material's shader.
@@ -718,6 +724,63 @@
       :return: the material's index
       :rtype: integer
 
+.. class:: Shader(PyObject_Plus)
+   Python object for handling Blender shaders
+   
+   .. attribute:: vertex
+      
+	  The vertex shader source.
+	  
+	  :type: string
+	  
+   .. attribute:: geometry
+      
+	  The geometry shader source.
+	  
+	  :type: string
+	  
+   .. attribute:: fragment
+   
+      The fragment shader source.
+	  
+	  :type: string
+	  
+   .. attribute:: uniforms
+   
+      A list of uniforms attached to the shader
+	  
+	  :type: list of :class:`Uniform`
+	  
+   .. method:: addUniform(uniform)
+      
+	  :arg uniform: The uniform to add
+	  :type uniform: :class:`Uniform`
+	  
+.. class:: Uniform(PyObject_Plus)
+   Python object for handling custom uniform values for Blender shaders
+   
+   .. attribute:: name
+   
+      The name of the uniform as it will appear in the shader
+	  
+	  :type: string
+	  
+   .. attribute:: type
+   
+      The type of the uniform
+	  
+	  :type: Value in...
+
+         * MA_UNF_FLOAT
+		 * MA_UNF_VEC2
+		 * MA_UNF_VEC3
+		 * MA_UNF_VEC4
+		 * MA_UNF_INT
+		 * MA_UNF_IVEC2
+		 * MA_UNF_IVEC3
+		 * MA_UNF_IVEC4
+		 * MA_UNF_SAMPLER2D
+
 .. class:: KX_CameraActuator(SCA_IActuator)
 
    Applies changes to a camera.

Modified: branches/ge_harmony/release/scripts/startup/bl_ui/properties_material.py
===================================================================
--- branches/ge_harmony/release/scripts/startup/bl_ui/properties_material.py	2012-06-19 22:17:19 UTC (rev 48098)
+++ branches/ge_harmony/release/scripts/startup/bl_ui/properties_material.py	2012-06-19 22:41:47 UTC (rev 48099)
@@ -611,7 +611,55 @@
         col.prop(halo, "flare_subflare_count", text="Subflares")
         col.prop(halo, "flare_subflare_size", text="Subsize")
 
+class MATERIAL_PT_shaders(MaterialButtonsPanel, bpy.types.Panel):
+    bl_label = "Custom Shaders"
+    COMPAT_ENGINES = {'BLENDER_GAME'}
 
+    @classmethod
+    def poll(cls,context):
+        mat = context.material
+        engine = context.scene.render.engine
+        return mat and (mat.type in ('SURFACE', 'WIRE')) and (engine in cls.COMPAT_ENGINES)
+
+    def draw(self, context):
+        layout = self.layout
+        col = layout.column()
+		
+        mat = active_node_mat(context.material)
+
+        col.prop(mat, "use_external_sources")
+
+        if mat.use_external_sources:
+            col.prop(mat, "vertex_shader")
+            col.prop(mat, "geometry_shader")
+            col.prop(mat, "fragment_shader")
+        else:
+            col.prop(mat, "vertex_text")
+            col.prop(mat, "geometry_text")
+            col.prop(mat, "fragment_text")
+
+        col.prop(mat, "geometry_input")
+        col.prop(mat, "geometry_output")
+
+        col.operator("material.force_update", text="Reload Shaders")
+		
+        col.label(text="Custom Uniforms:")
+        row = layout.row()
+        col = row.column()
+        col.template_list(mat, "uniforms", mat, "active_uniform_index")
+        col = row.column(align=True)
+        col.operator("material.uniform_add", icon='ZOOMIN', text="")
+        col.operator("material.uniform_remove", icon='ZOOMOUT', text="").index = mat.active_uniform_index
+		
+        lay = mat.active_uniform
+        if lay:
+            row = layout.row()
+            row.prop(lay, "name")
+            row.prop(lay, "type", text="")
+            if hasattr(lay, "value"):
+                row = layout.row()
+                row.prop(lay, "value")
+
 class MATERIAL_PT_game_settings(MaterialButtonsPanel, Panel):
     bl_label = "Game Settings"
     COMPAT_ENGINES = {'BLENDER_GAME'}

Modified: branches/ge_harmony/source/blender/blenkernel/BKE_material.h
===================================================================
--- branches/ge_harmony/source/blender/blenkernel/BKE_material.h	2012-06-19 22:17:19 UTC (rev 48098)
+++ branches/ge_harmony/source/blender/blenkernel/BKE_material.h	2012-06-19 22:41:47 UTC (rev 48099)
@@ -42,6 +42,7 @@
 struct Object;
 struct Mesh;
 struct MTFace;
+struct CustomUniform;
 
 /* materials */
 
@@ -52,6 +53,8 @@
 void init_material(struct Material *ma);
 struct Material *BKE_material_add(const char *name);
 struct Material *BKE_material_copy(struct Material *ma);
+void init_custom_uniform(struct CustomUniform *cu);
+struct CustomUniform *copy_custom_uniform(struct CustomUniform *cu);
 struct Material *localize_material(struct Material *ma);
 struct Material *give_node_material(struct Material *ma); /* returns node material or self */
 void BKE_material_make_local(struct Material *ma);

Modified: branches/ge_harmony/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/ge_harmony/source/blender/blenkernel/intern/material.c	2012-06-19 22:17:19 UTC (rev 48098)
+++ branches/ge_harmony/source/blender/blenkernel/intern/material.c	2012-06-19 22:41:47 UTC (rev 48099)
@@ -90,6 +90,8 @@
 	
 	if (ma->ramp_col) MEM_freeN(ma->ramp_col);
 	if (ma->ramp_spec) MEM_freeN(ma->ramp_spec);
+
+	/* XXX - To Do - if custom uniforms we need to clear the vector ones */
 	
 	BKE_free_animdata((ID *)ma);
 	
@@ -197,8 +199,57 @@
 	ma->mode = MA_TRACEBLE | MA_SHADBUF | MA_SHADOW | MA_RAYBIAS | MA_TANGENT_STR | MA_ZTRANSP;
 	ma->shade_flag = MA_APPROX_OCCLUSION;
 	ma->preview = NULL;
+
+	ma->csi.flag= 0;
+	ma->csi.geom_in= MA_CS_GEOM_IN_TRIS;
+	ma->csi.geom_out= MA_CS_GEOM_OUT_TRIANGLE_STRIP;
+	ma->csi.sources = NULL;
 }
 
+void init_custom_uniform(CustomUniform *cu)
+{
+	strcpy(&cu->name[0], "Uniform");
+	cu->type = MA_UNF_FLOAT;
+}
+
+CustomUniform *copy_custom_uniform(CustomUniform *cu)
+{
+	CustomUniform *copy = MEM_callocN(sizeof(CustomUniform), "copycustomuniform");
+
+	strcpy(copy->name, cu->name);
+	copy->type = cu->type;
+	copy->size = cu->size;
+
+	// Copy the data
+	switch(cu->type)
+	{
+	case MA_UNF_FLOAT:
+		copy->data = cu->data;
+		break;
+	case MA_UNF_VEC2:
+	case MA_UNF_VEC3:
+	case MA_UNF_VEC4:
+		copy->data = malloc(sizeof(float)*cu->size);
+		memcpy(copy->data, cu->data, sizeof(float)*cu->size);
+		break;
+	case MA_UNF_INT:
+		copy->data = cu->data;
+		break;
+	case MA_UNF_IVEC2:
+	case MA_UNF_IVEC3:
+	case MA_UNF_IVEC4:
+		copy->data = malloc(sizeof(int)*cu->size);
+		memcpy(copy->data, cu->data, sizeof(int)*cu->size);
+		break;
+	case MA_UNF_SAMPLER2D:
+		copy->data = malloc(sizeof(Tex));
+		memcpy(copy->data, cu->data, sizeof(Tex));
+		break;
+	}
+
+	return copy;
+}
+
 Material *BKE_material_add(const char *name)
 {
 	Material *ma;

Modified: branches/ge_harmony/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/ge_harmony/source/blender/blenloader/intern/readfile.c	2012-06-19 22:17:19 UTC (rev 48098)
+++ branches/ge_harmony/source/blender/blenloader/intern/readfile.c	2012-06-19 22:41:47 UTC (rev 48099)
@@ -3210,6 +3210,7 @@
 {
 	Material *ma;
 	MTex *mtex;
+	CustomUniform *cu;
 	int a;
 	
 	for (ma = main->mat.first; ma; ma = ma->id.next) {
@@ -3233,7 +3234,20 @@
 			
 			if (ma->nodetree)
 				lib_link_ntree(fd, &ma->id, ma->nodetree);
-			
+
+			ma->csi.vert_text= newlibadr(fd, ma->id.lib, ma->csi.vert_text);
+			ma->csi.frag_text= newlibadr(fd, ma->id.lib, ma->csi.frag_text);
+			ma->csi.geom_text= newlibadr(fd, ma->id.lib, ma->csi.geom_text);
+
+			cu = ma->csi.uniforms.first;
+
+			while(cu) {
+				if(cu->type==MA_UNF_SAMPLER2D)
+					cu->data= newlibadr(fd, ma->id.lib, cu->data);
+
+				cu = cu->next;
+			}
+
 			ma->id.flag -= LIB_NEEDLINK;
 		}
 	}
@@ -3242,6 +3256,8 @@
 static void direct_link_material(FileData *fd, Material *ma)
 {
 	int a;
+	CustomUniform *cu;
+
 	
 	ma->adt = newdataadr(fd, ma->adt);
 	direct_link_animdata(fd, ma->adt);
@@ -3249,6 +3265,19 @@
 	for (a = 0; a < MAX_MTEX; a++) {
 		ma->mtex[a] = newdataadr(fd, ma->mtex[a]);
 	}
+	link_list(fd, &ma->csi.uniforms);
+		
+	cu = ma->csi.uniforms.first;
+
+	while(cu) {
+		// Sampler2D is handled in lib_link, so only vec* and ivec* need special attention here
+		if (cu->type != MA_UNF_FLOAT &&
+			cu->type != MA_UNF_INT &&
+			cu->type != MA_UNF_SAMPLER2D)
+			cu->data= newdataadr(fd, cu->data);
+
+		cu = cu->next;
+	}
 	
 	ma->ramp_col = newdataadr(fd, ma->ramp_col);
 	ma->ramp_spec = newdataadr(fd, ma->ramp_spec);
@@ -3258,6 +3287,7 @@
 		direct_link_nodetree(fd, ma->nodetree);
 	
 	ma->preview = direct_link_preview_image(fd, ma->preview);
+	ma->csi.sources = NULL;
 	ma->gpumaterial.first = ma->gpumaterial.last = NULL;
 }
 
@@ -7448,6 +7478,18 @@
 					BLI_strncpy(ks->idname, ks->name, sizeof(ks->idname));
 			}
 		}
+		{
+			Material *mat;
+			/* geometry shader flags */
+			for(mat= main->mat.first; mat; mat= mat->id.next) {
+				if (mat->csi.geom_in == 0)
+				{
+					mat->csi.flag = 0;
+					mat->csi.geom_in = MA_CS_GEOM_IN_TRIS;
+					mat->csi.geom_out = MA_CS_GEOM_OUT_TRIANGLE_STRIP;
+				}
+			}
+		}
 	}
 	
 	if (main->versionfile < 262 || (main->versionfile == 262 && main->subversionfile < 3)) {
@@ -8354,6 +8396,10 @@
 	}
 	
 	expand_doit(fd, mainvar, ma->ipo); // XXX depreceated - old animation system
+
+	/*expand_doit(fd, mainvar, ma->vert_text);
+	expand_doit(fd, mainvar, ma->frag_text);
+	expand_doit(fd, mainvar, ma->geom_text);*/
 	
 	if (ma->adt)
 		expand_animdata(fd, mainvar, ma->adt);

Modified: branches/ge_harmony/source/blender/editors/render/render_intern.h
===================================================================
--- branches/ge_harmony/source/blender/editors/render/render_intern.h	2012-06-19 22:17:19 UTC (rev 48098)
+++ branches/ge_harmony/source/blender/editors/render/render_intern.h	2012-06-19 22:41:47 UTC (rev 48099)
@@ -50,6 +50,9 @@
 
 void MATERIAL_OT_copy(struct wmOperatorType *ot);
 void MATERIAL_OT_paste(struct wmOperatorType *ot);
+void MATERIAL_OT_uniform_add(struct wmOperatorType *ot);
+void MATERIAL_OT_uniform_remove(struct wmOperatorType *ot);
+void MATERIAL_OT_force_update(struct wmOperatorType *ot);
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list