[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36682] branches: Recreating my soc-2010-moguri (BGE shaders) branch.

Mitchell Stokes mogurijin at gmail.com
Sat May 14 08:08:35 CEST 2011


Revision: 36682
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36682
Author:   moguri
Date:     2011-05-14 06:08:35 +0000 (Sat, 14 May 2011)
Log Message:
-----------
Recreating my soc-2010-moguri (BGE shaders) branch. I'm also committing all previous changes to this branch. This will make things a lot easier going forward (avoiding a nasty merge and future merges should be easier).

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

Added Paths:
-----------
    branches/soc-2010-moguri/
    branches/soc-2010-moguri/source/gameengine/Ketsji/KX_PythonShaders.cpp
    branches/soc-2010-moguri/source/gameengine/Ketsji/KX_PythonShaders.h

Property Changed:
----------------
    branches/soc-2010-moguri/source/blender/editors/render/render_intern.h
    branches/soc-2010-moguri/source/blender/editors/render/render_shading.c


Property changes on: branches/soc-2010-moguri
___________________________________________________________________
Added: svn:ignore
   + *.pdb
.*
TAGS
build
cscope.out
install
mingw
mingw-user-config.py
mingw-user-config_debug.py
msvc
msvc-user-config.py
obj
sgc.bat
sgd.bat
smc.bat
ssenv.bat
tags
user-config.py
user-def.mk
graphicall_32b
graphicall_64b
graphicall_64b_debug
installer_32b
installer_64b

Added: svn:mergeinfo
   + /branches/soc-2010-moguri-2:30920,30958,31015,31027,31079,31136-31137,31160,31175,31230,31277,31309,31331,31340,31342,31360-31361,31365-31367,32615,33759

Modified: branches/soc-2010-moguri/doc/python_api/rst/bge.types.rst
===================================================================
--- trunk/blender/doc/python_api/rst/bge.types.rst	2011-05-14 04:39:27 UTC (rev 36678)
+++ branches/soc-2010-moguri/doc/python_api/rst/bge.types.rst	2011-05-14 06:08:35 UTC (rev 36682)
@@ -658,6 +658,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.
@@ -706,6 +712,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/soc-2010-moguri/release/scripts/startup/bl_ui/properties_material.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_material.py	2011-05-14 04:39:27 UTC (rev 36678)
+++ branches/soc-2010-moguri/release/scripts/startup/bl_ui/properties_material.py	2011-05-14 06:08:35 UTC (rev 36682)
@@ -606,7 +606,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_physics(MaterialButtonsPanel, bpy.types.Panel):
     bl_label = "Physics"
     COMPAT_ENGINES = {'BLENDER_GAME'}

Modified: branches/soc-2010-moguri/source/blender/blenkernel/BKE_material.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_material.h	2011-05-14 04:39:27 UTC (rev 36678)
+++ branches/soc-2010-moguri/source/blender/blenkernel/BKE_material.h	2011-05-14 06:08:35 UTC (rev 36682)
@@ -42,6 +42,7 @@
 struct Material;
 struct ID;
 struct Object;
+struct CustomUniform;
 
 /* materials */
 
@@ -51,6 +52,8 @@
 void resize_object_material(struct Object *ob, const short totcol);
 void init_material(struct Material *ma);
 struct Material *add_material(const char *name);
+void init_custom_uniform(struct CustomUniform *cu);
+struct CustomUniform *copy_custom_uniform(struct CustomUniform *cu);
 struct Material *copy_material(struct Material *ma);
 struct Material *localize_material(struct Material *ma);
 struct Material *give_node_material(struct Material *ma); /* returns node material or self */

Modified: branches/soc-2010-moguri/source/blender/blenkernel/intern/material.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/material.c	2011-05-14 04:39:27 UTC (rev 36678)
+++ branches/soc-2010-moguri/source/blender/blenkernel/intern/material.c	2011-05-14 06:08:35 UTC (rev 36682)
@@ -88,6 +88,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);
 	
@@ -191,8 +193,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 *add_material(const char *name)
 {
 	Material *ma;

Modified: branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2011-05-14 04:39:27 UTC (rev 36678)
+++ branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c	2011-05-14 06:08:35 UTC (rev 36682)
@@ -2991,6 +2991,7 @@
 {
 	Material *ma;
 	MTex *mtex;
+	CustomUniform *cu;
 	int a;
 
 	ma= main->mat.first;
@@ -3015,7 +3016,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;
 		}
 		ma= ma->id.next;
@@ -3025,6 +3039,7 @@
 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);
@@ -3035,12 +3050,26 @@
 
 	ma->ramp_col= newdataadr(fd, ma->ramp_col);
 	ma->ramp_spec= newdataadr(fd, ma->ramp_spec);
+	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->nodetree= newdataadr(fd, ma->nodetree);
 	if(ma->nodetree)
 		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;
 }
 
@@ -11597,6 +11626,8 @@
 	/* put compatibility code here until next subversion bump */
 
 	{
+		Material *mat;
+
 		/* screen view2d settings were not properly initialized [#27164]
 		 * v2d->scroll caused the bug but best reset other values too which are in old blend files only.
 		 * need to make less ugly - possibly an iterator? */
@@ -11629,6 +11660,16 @@
 			}
 		}
 
+		
+		/* 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;
+			}
+		}
 		{
 			/* Initialize texture point density curve falloff */
 			Tex *tex;
@@ -12184,6 +12225,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)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list