Hi all :)

  well, I was expecting the GPU gems procedural parts before releasing the
patch in order to add others if needed but it didn't arrived.

 some use advice:

  at small scales (i.e the default textures values) it is a curl like
texture but at larger scales (size 1.0) and with 6 octaves in hard/soft
mode then it show the true planet procedural texture goodness :)


  Anyway, here's the patch, is very easy and don't disrup any existent
Blender code so is pretty safe:

http://www.pasteall.org/17124/diff

//---------------------------------

Index: release/scripts/ui/properties_texture.py
===================================================================
--- release/scripts/ui/properties_texture.py    (revision 32153)
+++ release/scripts/ui/properties_texture.py    (working copy)
@@ -444,8 +444,33 @@

         col = split.column()
         col.prop(tex, "nabla", text="Nabla")
+
+class TEXTURE_PT_planet(TextureTypePanel, bpy.types.Panel):
+    bl_label = "Planet"
+    tex_type = 'PLANET'
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}

+    def draw(self, context):
+        layout = self.layout

+        tex = context.texture
+
+        layout.prop(tex, "planet_type", expand=True)
+        layout.label(text="Noise:")
+        layout.prop(tex, "noise_type", text="Type", expand=True)
+        layout.prop(tex, "noise_basis", text="Basis")
+
+        split = layout.split()
+
+        col = split.column()
+        col.prop(tex, "noise_scale", text="Size")
+        col.prop(tex, "noise_depth", text="Depth")
+
+        col = split.column()
+        col.prop(tex, "nabla", text="Nabla")
+
+
+
 class TEXTURE_PT_wood(TextureTypePanel, bpy.types.Panel):
     bl_label = "Wood"
     tex_type = 'WOOD'
Index: source/blender/blenkernel/intern/node.c
===================================================================
--- source/blender/blenkernel/intern/node.c     (revision 32153)
+++ source/blender/blenkernel/intern/node.c     (working copy)
@@ -3185,6 +3185,7 @@
        nodeRegisterType(ntypelist, &tex_node_proc_noise);
        nodeRegisterType(ntypelist, &tex_node_proc_stucci);
        nodeRegisterType(ntypelist, &tex_node_proc_distnoise);
+       nodeRegisterType(ntypelist, &tex_node_proc_planet);
 }

 static void remove_dynamic_typeinfos(ListBase *list)
Index: source/blender/editors/space_node/drawnode.c
===================================================================
--- source/blender/editors/space_node/drawnode.c        (revision 32153)
+++ source/blender/editors/space_node/drawnode.c        (working copy)
@@ -1202,6 +1202,15 @@
                        uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, 
NULL, 0);
                        uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, 
"Depth", 0);
                        break;
+
+               case TEX_PLANET:
+                       uiItemR(col, &tex_ptr, "noise_basis", 0, "", 0);
+                       row= uiLayoutRow(col, 0);
+                       uiItemR(row, &tex_ptr, "stype", UI_ITEM_R_EXPAND, NULL, 
0);
+                       row= uiLayoutRow(col, 0);
+                       uiItemR(row, &tex_ptr, "noise_type", UI_ITEM_R_EXPAND, 
NULL, 0);
+                       uiItemR(col, &tex_ptr, "noise_depth", UI_ITEM_R_EXPAND, 
"Depth", 0);
+                       break;

                case TEX_DISTNOISE:
                        uiItemR(col, &tex_ptr, "noise_basis", 0, "", 0);
Index: source/blender/makesdna/DNA_texture_types.h
===================================================================
--- source/blender/makesdna/DNA_texture_types.h (revision 32153)
+++ source/blender/makesdna/DNA_texture_types.h (working copy)
@@ -294,6 +294,7 @@
 #define TEX_DISTNOISE  13
 #define TEX_POINTDENSITY       14
 #define TEX_VOXELDATA          15
+#define TEX_PLANET                     16

 /* musgrave stype */
 #define TEX_MFRACTAL           0
Index: source/blender/makesrna/intern/rna_texture.c
===================================================================
--- source/blender/makesrna/intern/rna_texture.c        (revision 32153)
+++ source/blender/makesrna/intern/rna_texture.c        (working copy)
@@ -66,6 +66,7 @@
        {TEX_VORONOI, "VORONOI", ICON_TEXTURE, "Voronoi", ""},
        {TEX_VOXELDATA, "VOXEL_DATA", ICON_TEXTURE, "Voxel Data", ""},
        {TEX_WOOD, "WOOD", ICON_TEXTURE, "Wood", ""},
+       {TEX_PLANET, "PLANET", ICON_TEXTURE, "Planet", ""},
        {0, NULL, 0, NULL, NULL}};

 #ifdef RNA_RUNTIME
@@ -119,6 +120,8 @@
                        return &RNA_VoxelDataTexture;
                case TEX_WOOD:
                        return &RNA_WoodTexture;
+               case TEX_PLANET:
+                       return &RNA_PlanetTexture;
                default:
                        return &RNA_Texture;
        }
@@ -706,6 +709,60 @@
        RNA_def_property_update(prop, 0, "rna_Texture_update");
 }

+static void rna_def_texture_planet(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       static EnumPropertyItem prop_planet_stype[] = {
+       {TEX_DEFAULT, "GREYSCALE", 0, "Greyscale", ""},
+       {TEX_COLOR, "COLOR", 0, "Color", ""},
+       {0, NULL, 0, NULL, NULL}};
+
+       srna= RNA_def_struct(brna, "PlanetTexture", "Texture");
+       RNA_def_struct_ui_text(srna, "Planet Texture", "Procedural noise 
texture");
+       RNA_def_struct_sdna(srna, "Tex");
+
+       prop= RNA_def_property(srna, "noise_scale", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "noisesize");
+       RNA_def_property_range(prop, 0.0001, FLT_MAX);
+       RNA_def_property_ui_range(prop, 0.0001, 2, 10, 2);
+       RNA_def_property_ui_text(prop, "Noise Size", "Sets scaling for noise
input");
+       RNA_def_property_update(prop, 0, "rna_Texture_update");
+
+       prop= RNA_def_property(srna, "noise_depth", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "noisedepth");
+       RNA_def_property_range(prop, 0, INT_MAX);
+       RNA_def_property_ui_range(prop, 0, 6, 0, 2);
+       RNA_def_property_ui_text(prop, "Noise Depth", "Sets the depth of the
cloud calculation");
+       RNA_def_property_update(prop, 0, "rna_Texture_nodes_update");
+
+       prop= RNA_def_property(srna, "noise_basis", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "noisebasis");
+       RNA_def_property_enum_items(prop, prop_noise_basis_items);
+       RNA_def_property_ui_text(prop, "Noise Basis", "Sets the noise basis used
for turbulence");
+       RNA_def_property_update(prop, 0, "rna_Texture_nodes_update");
+
+       prop= RNA_def_property(srna, "noise_type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "noisetype");
+       RNA_def_property_enum_items(prop, prop_noise_type);
+       RNA_def_property_ui_text(prop, "Noise Type", "");
+       RNA_def_property_update(prop, 0, "rna_Texture_nodes_update");
+
+       prop= RNA_def_property(srna, "planet_type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "stype");
+       RNA_def_property_enum_items(prop, prop_planet_stype);
+       RNA_def_property_ui_text(prop, "Color", "");
+       RNA_def_property_update(prop, 0, "rna_Texture_nodes_update");
+
+       prop= RNA_def_property(srna, "nabla", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_range(prop, 0.001, 0.1);
+       RNA_def_property_ui_range(prop, 0.001, 0.1, 1, 2);
+       RNA_def_property_ui_text(prop, "Nabla", "Size of derivative offset used
for calculating normal");
+       RNA_def_property_update(prop, 0, "rna_Texture_update");
+}
+
+
 static void rna_def_texture_wood(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -1768,6 +1825,7 @@
        rna_def_texture_distorted_noise(brna);
        rna_def_texture_pointdensity(brna);
        rna_def_texture_voxeldata(brna);
+       rna_def_texture_planet(brna);
        /* XXX add more types here .. */
 }

Index: source/blender/makesrna/RNA_access.h
===================================================================
--- source/blender/makesrna/RNA_access.h        (revision 32153)
+++ source/blender/makesrna/RNA_access.h        (working copy)
@@ -93,6 +93,7 @@
 extern StructRNA RNA_ClothModifier;
 extern StructRNA RNA_ClothSettings;
 extern StructRNA RNA_CloudsTexture;
+extern StructRNA RNA_PlanetTexture;
 extern StructRNA RNA_CollectionProperty;
 extern StructRNA RNA_CollisionModifier;
 extern StructRNA RNA_CollisionSensor;
Index: source/blender/nodes/intern/TEX_nodes/TEX_proc.c
===================================================================
--- source/blender/nodes/intern/TEX_nodes/TEX_proc.c    (revision 32153)
+++ source/blender/nodes/intern/TEX_nodes/TEX_proc.c    (working copy)
@@ -202,6 +202,18 @@
 }
 ProcDef(clouds)

+/* --- Planet --- */
+static bNodeSocketType planet_inputs[]= {
+       COMMON_INPUTS,
+       { SOCK_VALUE, 1, "Size",       0.25f, 0.0f, 0.0f, 0.0f,   0.0001f, 2.0f 
},
+       { -1, 0, "" }
+};
+static void planet_map_inputs(Tex *tex, bNodeStack **in, TexParams *p,
short thread)
+{
+       tex->noisesize = tex_input_value(in[I+0], p, thread);
+}
+ProcDef(planet)
+
 /* --- DISTORTED NOISE --- */
 static bNodeSocketType distnoise_inputs[]= {
        COMMON_INPUTS,
@@ -307,4 +319,5 @@
 bNodeType tex_node_proc_noise     = TexDef(TEX_NOISE,     C,  noise,    
"Noise"    );
 bNodeType tex_node_proc_stucci    = TexDef(TEX_STUCCI,    CV, stucci,   
"Stucci"   );
 bNodeType tex_node_proc_distnoise = TexDef(TEX_DISTNOISE, CV, distnoise,
"Distorted Noise" );
+bNodeType tex_node_proc_planet    = TexDef(TEX_PLANET,    CV, planet,   
"Planet"   );

Index: source/blender/nodes/TEX_node.h
===================================================================
--- source/blender/nodes/TEX_node.h     (revision 32153)
+++ source/blender/nodes/TEX_node.h     (working copy)
@@ -74,5 +74,6 @@
 extern bNodeType tex_node_proc_noise;
 extern bNodeType tex_node_proc_stucci;
 extern bNodeType tex_node_proc_distnoise;
+extern bNodeType tex_node_proc_planet;

 #endif
Index: source/blender/render/intern/source/texture.c
===================================================================
--- source/blender/render/intern/source/texture.c       (revision 32153)
+++ source/blender/render/intern/source/texture.c       (working copy)
@@ -234,12 +234,11 @@

 /*
-------------------------------------------------------------------------
*/
 /*
*************************************************************************
*/
-
 /* newnoise: all noisebased types now have different noisebases to choose
from */

 static int clouds(Tex *tex, float *texvec, TexResult *texres)
-{
-       int rv = TEX_INT;
+{
+       int rv = TEX_INT;

        texres->tin = BLI_gTurbulence(tex->noisesize, texvec[0], texvec[1],
texvec[2], tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT),
tex->noisebasis);

@@ -270,6 +269,70 @@

 }

+/* planet procedural noise */
+static void planet_noise(float *result, float noisesize, float x, float
y, float z, int oct, int hard, int noisebasis, float nabla){
+       float xdy, xdz, ydx, ydz, zdx, zdy;
+       float d = 0.001f;
+       float offset = nabla * 1000.f;
+
+       float dx[3], dy[3], xo , yo, zo;
+
+       x = BLI_gTurbulence(noisesize, x, y, z, oct, hard, noisebasis);
+       y = BLI_gTurbulence(noisesize, x + offset, y , z, oct, hard, 
noisebasis);
+       z = BLI_gTurbulence(noisesize, x, y + offset, z , oct, hard, 
noisebasis);
+
+       //-------------------------------
+       xdy = x - BLI_gTurbulence(noisesize, x , y + d, z, oct, hard, 
noisebasis);
+       xdz = x - BLI_gTurbulence(noisesize, x, y, z + d, oct, hard, 
noisebasis);
+
+       ydx = y - BLI_gTurbulence(noisesize, x + d, y, z, oct, hard, 
noisebasis);
+       ydz = y - BLI_gTurbulence(noisesize, x, y, z + d, oct, hard, 
noisebasis);
+
+       zdx = z - BLI_gTurbulence(noisesize, x + d, y, z, oct, hard, 
noisebasis);
+       zdy = z - BLI_gTurbulence(noisesize, x, y + d, z, oct, hard, 
noisebasis);
+
+       result[0] = (zdy - ydz);
+       result[1] = (zdx - xdz);
+       result[2] = (ydx - xdy);
+
+}
+
+static int planet(Tex *tex, float *texvec, TexResult *texres)
+{
+       float result[3] = {0.f,0.f,0.f};
+       int rv = TEX_INT;
+
+       planet_noise(result, tex->noisesize, texvec[0], texvec[1], texvec[2],
tex->noisedepth, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis,
tex->nabla);
+
+       texres->tin = result[0];
+
+       if (texres->nor!=NULL) {
+               // calculate bumpnormal
+               texres->nor[0] = result[0];
+               texres->nor[1] = result[1];
+               texres->nor[2] = result[2];
+
+               tex_normal_derivate(tex, texres);
+               rv |= TEX_NOR;
+       }
+
+       if (tex->stype==TEX_COLOR) {
+               // in this case, int. value should really be computed from 
color,
+               // and bumpnormal from that, would be too slow, looks ok as is
+               texres->tr = result[0];
+               texres->tg = result[1];
+               texres->tb = result[2];
+               BRICONTRGB;
+               texres->ta = 1.0;
+               return (rv | TEX_RGB);
+       }
+
+       BRICONT;
+
+       return rv;
+
+}
+
 /* creates a sine wave */
 static float tex_sin(float a)
 {
@@ -1257,6 +1320,8 @@
        case TEX_VOXELDATA:
                retval= voxeldatatex(tex, texvec, texres);
                break;
+       case TEX_PLANET:
+               retval= planet(tex, texvec, texres);

        }




_______________________________________________
Bf-committers mailing list
Bf-committers@blender.org
http://lists.blender.org/mailman/listinfo/bf-committers

Reply via email to