[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29117] branches/soc-2010-moguri: Add the start of custom uniforms.
Mitchell Stokes
mogurijin at gmail.com
Tue Jun 1 06:15:10 CEST 2010
Revision: 29117
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29117
Author: moguri
Date: 2010-06-01 06:15:00 +0200 (Tue, 01 Jun 2010)
Log Message:
-----------
Add the start of custom uniforms. They can now be added and named through the UI, but they don't do much beyond that.
I'm also fixing up some do_version stuff so the geometry shader flags should be properly set.
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/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/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-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/release/scripts/ui/properties_material.py 2010-06-01 04:15:00 UTC (rev 29117)
@@ -803,6 +803,13 @@
col.prop(mat, "geometry_input")
col.prop(mat, "geometry_output")
+
+ col.template_list(mat, "uniforms", mat, "active_uniform_index")
+ col.operator("material.uniform_add", icon='ZOOMIN', text="")
+
+ lay = mat.active_uniform
+ if lay:
+ layout.prop(lay, "name")
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-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/source/blender/blenloader/intern/readfile.c 2010-06-01 04:15:00 UTC (rev 29117)
@@ -2906,6 +2906,8 @@
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);
if(ma->nodetree)
@@ -10835,7 +10837,6 @@
if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 5)) {
bScreen *sc;
- Material *mat;
/* Image editor scopes */
for(sc= main->screen.first; sc; sc= sc->id.next) {
@@ -10850,7 +10851,16 @@
}
}
}
+ }
+
+ /* put 2.50 compatibility code here until next subversion bump */
+ {
+ Object *ob;
+ bScreen *sc;
+ Material *mat;
+
+
/* geometry shader flags */
for(mat= main->mat.first; mat; mat= mat->id.next) {
if (mat->csi.geom_in == 0)
@@ -10860,14 +10870,7 @@
mat->csi.geom_out = MA_CS_GEOM_OUT_TRIANGLE_STRIP;
}
}
- }
-
- /* put 2.50 compatibility code here until next subversion bump */
- {
- Object *ob;
- bScreen *sc;
-
for (sc= main->screen.first; sc; sc= sc->id.next) {
ScrArea *sa;
for (sa= sc->areabase.first; sa; sa= sa->next) {
Modified: branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c 2010-06-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/source/blender/blenloader/intern/writefile.c 2010-06-01 04:15:00 UTC (rev 29117)
@@ -1678,6 +1678,19 @@
mywrite(wd, MYWRITE_FLUSH, 0);
}
+static void write_uniforms(WriteData *wd, ListBase *lb)
+{
+ CustomUniform *cu;
+
+ cu= lb->first;
+
+ while(cu) {
+ writestruct(wd, DATA, "CustomUniform", 1, cu);
+
+ cu= cu->next;
+ }
+}
+
static void write_materials(WriteData *wd, ListBase *idbase)
{
Material *ma;
@@ -1707,6 +1720,8 @@
if(ma->csi.vert_text) writestruct(wd, DATA, "Text", 1, ma->csi.vert_text);
if(ma->csi.frag_text) writestruct(wd, DATA, "Text", 1, ma->csi.frag_text);
if(ma->csi.geom_text) writestruct(wd, DATA, "Text", 1, ma->csi.geom_text);
+
+ write_uniforms(wd, &ma->csi.uniforms);
/* nodetree is integral part of material, no libdata */
if(ma->nodetree) {
Modified: branches/soc-2010-moguri/source/blender/editors/render/render_intern.h
===================================================================
--- branches/soc-2010-moguri/source/blender/editors/render/render_intern.h 2010-06-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/source/blender/editors/render/render_intern.h 2010-06-01 04:15:00 UTC (rev 29117)
@@ -47,6 +47,8 @@
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 SCENE_OT_render_layer_add(struct wmOperatorType *ot);
void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
Modified: branches/soc-2010-moguri/source/blender/editors/render/render_ops.c
===================================================================
--- branches/soc-2010-moguri/source/blender/editors/render/render_ops.c 2010-06-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/source/blender/editors/render/render_ops.c 2010-06-01 04:15:00 UTC (rev 29117)
@@ -53,6 +53,7 @@
WM_operatortype_append(MATERIAL_OT_copy);
WM_operatortype_append(MATERIAL_OT_paste);
+ WM_operatortype_append(MATERIAL_OT_uniform_add);
WM_operatortype_append(SCENE_OT_render_layer_add);
WM_operatortype_append(SCENE_OT_render_layer_remove);
Modified: branches/soc-2010-moguri/source/blender/editors/render/render_shading.c
===================================================================
--- branches/soc-2010-moguri/source/blender/editors/render/render_shading.c 2010-06-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/source/blender/editors/render/render_shading.c 2010-06-01 04:15:00 UTC (rev 29117)
@@ -1046,7 +1046,32 @@
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+static int uniform_add_exec(bContext *C, wmOperator *op)
+{
+ Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
+ CustomUniform *cu= MEM_callocN(sizeof(CustomUniform), "New Uniform");
+ strcpy(&cu->name[0], "Uniform");
+
+ BLI_addtail(&ma->csi.uniforms, cu);
+
+ return OPERATOR_FINISHED;
+}
+
+void MATERIAL_OT_uniform_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add Uniform";
+ ot->idname= "MATERIAL_OT_uniform_add";
+ ot->description= "Add a new uniform value";
+
+ /* api callbacks */
+ ot->exec= uniform_add_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
static short mtexcopied=0; /* must be reset on file load */
static MTex mtexcopybuf;
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-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h 2010-06-01 04:15:00 UTC (rev 29117)
@@ -73,10 +73,11 @@
} VolumeSettings;
typedef struct CustomUniform {
+ struct CustomUniform *next, *prev;
char name[64];
- short type;
- void *data;
-}
+ short type, pad[3];
+ //void *data;
+} CustomUniform;
typedef struct CustomShaderInfo {
char vertex_shader[64];
@@ -87,7 +88,10 @@
struct Text *frag_text;
struct Text *geom_text;
- short flag, geom_in, geom_out, pad;
+ short flag, geom_in, geom_out;
+ short actuniform;
+
+ ListBase uniforms;
} CustomShaderInfo;
typedef struct Material {
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-01 02:33:15 UTC (rev 29116)
+++ branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c 2010-06-01 04:15:00 UTC (rev 29117)
@@ -158,6 +158,33 @@
nodeSetActiveID(ma->nodetree, ID_MA, &ma_act->id);
}
+static PointerRNA rna_Material_active_uniform_get(PointerRNA *ptr)
+{
+ Material *ma= (Material*)ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_CustomUniform, BLI_findlink(&ma->csi.uniforms, (int)ma->csi.actuniform-1));
+}
+
+static int rna_Material_active_uniform_index_get(PointerRNA *ptr)
+{
+ Material *ma= (Material*)ptr->data;
+ return MAX2(ma->csi.actuniform-1, 0);
+}
+
+static void rna_Material_active_uniform_index_set(PointerRNA *ptr, int value)
+{
+ Material *ma= (Material*)ptr->data;
+ ma->csi.actuniform= value+1;
+}
+
+static void rna_Material_active_uniform_index_range(PointerRNA *ptr, int *min, int *max)
+{
+ Material *ma= (Material*)ptr->data;
+
+ *min= 0;
+ *max= BLI_countlist(&ma->csi.uniforms)-1;
+ *max= MAX2(0, *max);
+}
+
static void rna_MaterialStrand_start_size_range(PointerRNA *ptr, float *min, float *max)
{
Material *ma= (Material*)ptr->id.data;
@@ -878,8 +905,44 @@
RNA_def_property_enum_items(prop, prop_geomout_items);
RNA_def_property_ui_text(prop, "Geometry shader output", "The output type for the geometry shader");
RNA_def_property_update(prop, 0, "rna_Material_update");
+
+ /* uniforms */
+ prop= RNA_def_property(srna, "uniforms", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "csi.uniforms", NULL);
+ RNA_def_property_struct_type(prop, "CustomUniform");
+ RNA_def_property_ui_text(prop, "Custom Uniforms", "Uniform values to send to custom shaders.");
+
+ prop= RNA_def_property(srna, "active_uniform", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "CustomUniform");
+ RNA_def_property_pointer_funcs(prop, "rna_Material_active_uniform_get", "rna_Material_active_uniform_set", NULL);
+ //RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Active Uniform", "");
+ RNA_def_property_update(prop, 0, "rna_Material_update");
+
+ prop= RNA_def_property(srna, "active_uniform_index", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "csi.actuniform");
+ RNA_def_property_int_funcs(prop, "rna_Material_active_uniform_index_get", "rna_Material_active_uniform_index_set", "rna_Material_active_uniform_index_range");
+ RNA_def_property_ui_text(prop, "Active Uniform Index", "");
+ RNA_def_property_update(prop, 0, "rna_Material_update");
}
+static void rna_def_material_uniform(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna= RNA_def_struct(brna, "CustomUniform", NULL);
+ RNA_def_struct_sdna(srna, "CustomUniform");
+ RNA_def_struct_nested(brna, srna, "Material");
+ RNA_def_struct_ui_text(srna, "Uniform", "Uniform data for custom shaders.");
+
+ prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_string_sdna(prop, NULL, "name");
+ RNA_def_property_ui_text(prop, "Name", "The name of the uniform");
+ RNA_def_property_update(prop, 0, "rna_Material_update");
+}
+
static void rna_def_material_raymirror(BlenderRNA *brna)
{
StructRNA *srna;
@@ -1838,6 +1901,7 @@
rna_def_material_mtex(brna);
rna_def_material_strand(brna);
rna_def_material_physics(brna);
+ rna_def_material_uniform(brna);
RNA_api_material(srna);
}
More information about the Bf-blender-cvs
mailing list