[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29499] branches/soc-2010-moguri: I can now send texture data to shaders with a sampler2D uniform.
Mitchell Stokes
mogurijin at gmail.com
Thu Jun 17 00:56:03 CEST 2010
Revision: 29499
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29499
Author: moguri
Date: 2010-06-17 00:56:03 +0200 (Thu, 17 Jun 2010)
Log Message:
-----------
I can now send texture data to shaders with a sampler2D uniform. This works great in the BGE, but the viewport doesn't seem to be sending the UV data I expect. I need to do more digging into this. There is also the beginnings of my fumblings with vec3 uniforms. These aren't working yet.
I've also made some read/write file updates based on suggestions from Matt.
Modified Paths:
--------------
branches/soc-2010-moguri/release/scripts/ui/properties_material.py
branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c
branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c
branches/soc-2010-moguri/source/blender/gpu/GPU_material.h
branches/soc-2010-moguri/source/blender/gpu/intern/gpu_draw.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
Modified: branches/soc-2010-moguri/release/scripts/ui/properties_material.py
===================================================================
--- branches/soc-2010-moguri/release/scripts/ui/properties_material.py 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/release/scripts/ui/properties_material.py 2010-06-16 22:56:03 UTC (rev 29499)
@@ -820,7 +820,7 @@
if hasattr(lay, "value"):
row = layout.row()
row.prop(lay, "value")
- row.prop(lay, "size")
+ # row.prop(lay, "size")
class VolumeButtonsPanel(bpy.types.Panel):
bl_space_type = 'PROPERTIES'
Modified: branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c 2010-06-16 22:56:03 UTC (rev 29499)
@@ -2859,6 +2859,7 @@
{
Material *ma;
MTex *mtex;
+ CustomUniform *cu;
int a;
ma= main->mat.first;
@@ -2883,7 +2884,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;
@@ -2893,7 +2907,6 @@
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);
@@ -2904,11 +2917,6 @@
ma->ramp_col= newdataadr(fd, ma->ramp_col);
ma->ramp_spec= newdataadr(fd, ma->ramp_spec);
-
- 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);
-
link_list(fd, &ma->csi.uniforms);
ma->nodetree= newdataadr(fd, ma->nodetree);
Modified: branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c 2010-06-16 22:56:03 UTC (rev 29499)
@@ -2779,4 +2779,4 @@
return !error;
}
-#endif /* !__APPLE__ */
+#endif /* !__APPLE__ */
\ No newline at end of file
Modified: branches/soc-2010-moguri/source/blender/gpu/GPU_material.h
===================================================================
--- branches/soc-2010-moguri/source/blender/gpu/GPU_material.h 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/source/blender/gpu/GPU_material.h 2010-06-16 22:56:03 UTC (rev 29499)
@@ -127,6 +127,7 @@
void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap);
void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4]);
void GPU_material_unbind(GPUMaterial *material);
+void GPU_material_unbind_uniforms(GPUMaterial *material);
int GPU_material_bound(GPUMaterial *material);
void GPU_material_vertex_attributes(GPUMaterial *material,
Modified: branches/soc-2010-moguri/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/soc-2010-moguri/source/blender/gpu/intern/gpu_draw.c 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/source/blender/gpu/intern/gpu_draw.c 2010-06-16 22:56:03 UTC (rev 29499)
@@ -1125,6 +1125,7 @@
if(GMS.gboundmat) {
if(GMS.alphapass) glDepthMask(0);
GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
+ GPU_material_unbind_uniforms(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
GMS.gboundmat= NULL;
}
Modified: branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c 2010-06-16 22:56:03 UTC (rev 29499)
@@ -394,6 +394,19 @@
GPU_shader_uniform_vector(shader, loc, 1, 1, (float*)(&cu->data));
else if(cu->type == MA_UNF_INT)
GPU_shader_uniform_ivector(shader, loc, 1, 1, (int*)(&cu->data));
+ else if(cu->type == MA_UNF_SAMPLER2D)
+ {
+ Tex *tex;
+ GPUTexture *gtex;
+
+ tex = (Tex*)cu->data;
+ if (tex)
+ {
+ gtex = GPU_texture_from_blender(tex->ima, &tex->iuser, 1.0, 0);
+ GPU_texture_bind(gtex, 3);
+ GPU_shader_uniform_texture(shader, loc, gtex);
+ }
+ }
}
/* update lamps */
@@ -430,6 +443,29 @@
}
}
+void GPU_material_unbind_uniforms(GPUMaterial *material)
+{
+ if (material->pass) {
+ CustomUniform *cu;
+
+ /* handle custom uniforms */
+ for(cu=material->ma->csi.uniforms.first; cu; cu=cu->next) {
+ if(cu->type == MA_UNF_SAMPLER2D)
+ {
+ Tex *tex;
+ GPUTexture *gtex;
+
+ tex = (Tex*)cu->data;
+ if (tex)
+ {
+ gtex = GPU_texture_from_blender(tex->ima, &tex->iuser, 1.0, 0);
+ GPU_texture_unbind(gtex);
+ }
+ }
+ }
+ }
+}
+
int GPU_material_bound(GPUMaterial *material)
{
return material->bound;
Modified: branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h 2010-06-16 22:56:03 UTC (rev 29499)
@@ -230,11 +230,15 @@
/* Uniform type */
#define MA_UNF_FLOAT 1
-#define MA_UNF_VEC 2
-#define MA_UNF_INT 3
-#define MA_UNF_IVEC 4
-#define MA_UNF_MAT 5
-#define MA_UNF_SAMPLER2D 6
+#define MA_UNF_VEC2 2
+#define MA_UNF_VEC3 3
+#define MA_UNF_VEC4 4
+#define MA_UNF_INT 5
+#define MA_UNF_IVEC2 6
+#define MA_UNF_IVEC3 7
+#define MA_UNF_IVEC4 8
+#define MA_UNF_MAT 9
+#define MA_UNF_SAMPLER2D 10
/* mode (is int) */
#define MA_TRACEBLE 1
Modified: branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c
===================================================================
--- branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c 2010-06-16 22:22:59 UTC (rev 29498)
+++ branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c 2010-06-16 22:56:03 UTC (rev 29499)
@@ -216,11 +216,16 @@
switch(cu->type){
case MA_UNF_FLOAT:
+ cu->size= 1;
return &RNA_FloatUniform;
case MA_UNF_INT:
+ cu->size= 1;
return &RNA_IntUniform;
- //case MA_UNF_SAMPLER2D:
- // return &RNA_Sampler2DUniform;
+ //case MA_UNF_VEC3:
+ // cu->size= 3;
+ // return &RNA_Vec3Uniform;
+ case MA_UNF_SAMPLER2D:
+ return &RNA_Sampler2DUniform;
default:
return &RNA_CustomUniform;
}
@@ -967,7 +972,7 @@
}
/* Helper function for defining the different uniform data types */
-static void rna_def_uniformtype(BlenderRNA *brna, const char *name, const char *doc, int type, int min, int max)
+static void rna_def_uniformtype(BlenderRNA *brna, const char *name, const char *doc, int type, int subtype, int min, int max)
{
PropertyRNA *prop;
StructRNA *srna;
@@ -976,7 +981,7 @@
RNA_def_struct_ui_text(srna, name, doc);
RNA_def_struct_sdna(srna, "CustomUniform");
- prop= RNA_def_property(srna, "value", type, PROP_NONE);
+ prop= RNA_def_property(srna, "value", type, subtype);
if (type == PROP_INT)
RNA_def_property_int_sdna(prop, NULL, "data");
else if (type == PROP_FLOAT)
@@ -987,18 +992,18 @@
else if (type == PROP_POINTER)
{
RNA_def_property_pointer_sdna(prop, NULL, "data");
- RNA_def_property_struct_type(prop, "Image");
+ RNA_def_property_struct_type(prop, "Texture");
RNA_def_property_flag(prop, PROP_EDITABLE);
}
RNA_def_property_ui_text(prop, "Value", "Uniform value");
RNA_def_property_update(prop, 0, "rna_Material_update");
- prop= RNA_def_property(srna, "size", PROP_INT, PROP_NONE);
+ /*prop= RNA_def_property(srna, "size", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "size");
RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, "Size", "The number of elements in the uniform");
- RNA_def_property_update(prop, 0, "rna_Material_update");
+ RNA_def_property_update(prop, 0, "rna_Material_update");*/
}
static void rna_def_material_uniform(BlenderRNA *brna)
@@ -1008,10 +1013,11 @@
static EnumPropertyItem prop_type_items[] = {
{MA_UNF_FLOAT, "FLOAT", 0, "float", "float"},
+ {MA_UNF_VEC3, "VEC3", 0, "vec3", "vec3"},
//{MA_UNF_VEC, "VEC", 0, "vec", "vec"},
{MA_UNF_INT, "INT", 0, "int", "int"},
//{MA_UNF_IVEC2, "IVEC", 0, "ivec", "ivec"},
- //{MA_UNF_SAMPLER2D, "SAMPLER2D", 0, "sampler2D", "sampler2D"},
+ {MA_UNF_SAMPLER2D, "SAMPLER2D", 0, "sampler2D", "sampler2D"},
{0, NULL, 0, NULL, NULL}};
srna= RNA_def_struct(brna, "CustomUniform", NULL);
@@ -1033,9 +1039,10 @@
RNA_def_property_ui_text(prop, "Uniform type", "The data type of the uniform");
RNA_def_property_update(prop, 0, "rna_Material_update");
- rna_def_uniformtype(brna, "FloatUniform", "Custom float uniform", PROP_FLOAT, 1, 1);
- rna_def_uniformtype(brna, "IntUniform", "Custom integer uniform", PROP_INT, 1, 1);
- //rna_def_uniformtype(brna, "Sampler2DUniform", "Custom sampler2D uniform", PROP_POINTER, 1, 1);
+ rna_def_uniformtype(brna, "FloatUniform", "Custom float uniform", PROP_FLOAT, PROP_NONE, 1, 1);
+ rna_def_uniformtype(brna, "IntUniform", "Custom integer uniform", PROP_INT, PROP_NONE, 1, 1);
+// rna_def_uniformtype(brna, "Vec3Uniform", "Custom vector 3 uniform", PROP_FLOAT, PROP_TRANSLATION, 3, 3);
+ rna_def_uniformtype(brna, "Sampler2DUniform", "Custom sampler2D uniform", PROP_POINTER, PROP_NONE, 1, 1);
}
static void rna_def_material_raymirror(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list