[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11307] branches/soc-2007-maike/source/ blender: Added colorband texture creation and a colorband node for a material not reusable for node materials

Miguel Torres Lima torreslima at gmail.com
Wed Jul 18 18:43:40 CEST 2007


Revision: 11307
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11307
Author:   maike
Date:     2007-07-18 18:43:40 +0200 (Wed, 18 Jul 2007)

Log Message:
-----------
Added colorband texture creation and a colorband node for a material not reusable for node materials
Still don't send the texture to the shader nor concatenate hsv_to_rgb and rgb_to_hsv glsl functions

Modified Paths:
--------------
    branches/soc-2007-maike/source/blender/include/BIF_glsl_material_node.h
    branches/soc-2007-maike/source/blender/src/buttons_shading.c
    branches/soc-2007-maike/source/blender/src/glsl_colorband.c
    branches/soc-2007-maike/source/blender/src/glsl_drawobject.c
    branches/soc-2007-maike/source/blender/src/glsl_material.c
    branches/soc-2007-maike/source/blender/src/glsl_material_node.c
    branches/soc-2007-maike/source/blender/src/glsl_node_util.c
    branches/soc-2007-maike/source/blender/src/glsl_shader_util.c
    branches/soc-2007-maike/source/blender/src/glsl_uniforms.c

Added Paths:
-----------
    branches/soc-2007-maike/source/blender/include/BIF_glsl_colorband_node.h
    branches/soc-2007-maike/source/blender/src/glsl_colorband_node.c

Added: branches/soc-2007-maike/source/blender/include/BIF_glsl_colorband_node.h
===================================================================
--- branches/soc-2007-maike/source/blender/include/BIF_glsl_colorband_node.h	                        (rev 0)
+++ branches/soc-2007-maike/source/blender/include/BIF_glsl_colorband_node.h	2007-07-18 16:43:40 UTC (rev 11307)
@@ -0,0 +1,24 @@
+#define GLSL_CB_BLEND_MIX          1
+#define GLSL_CB_BLEND_ADD          2
+#define GLSL_CB_BLEND_MULT         4
+#define GLSL_CB_BLEND_SUB          8
+#define GLSL_CB_BLEND_SCREEN      16
+#define GLSL_CB_BLEND_DIV         32
+#define GLSL_CB_BLEND_DIF         64
+#define GLSL_CB_BLEND_DARK       128
+#define GLSL_CB_BLEND_LIGHT      256
+#define GLSL_CB_BLEND_OVERLAY    512
+#define GLSL_CB_BLEND_DODGE     1024
+#define GLSL_CB_BLEND_BURN      2048
+#define GLSL_CB_BLEND_HUE       4096
+#define GLSL_CB_BLEND_SAT       8192
+#define GLSL_CB_BLEND_VAL      16384
+#define GLSL_CB_BLEND_COLOR    32768
+
+struct GLSL_NodeCode_;
+struct Material;
+
+struct GLSL_NodeCode_ *glsl_colorband_node(struct Material *mat, int *blend, int num, int ramp_num);
+char *glsl_colorband_node_uniforms(int num, int ramp_num);
+char *glsl_colorband_node_defines(struct Material *mat, int *blend, int num, int ramp_num);
+char *glsl_colorband_blend_funcs(int blend);

Modified: branches/soc-2007-maike/source/blender/include/BIF_glsl_material_node.h
===================================================================
--- branches/soc-2007-maike/source/blender/include/BIF_glsl_material_node.h	2007-07-18 16:02:34 UTC (rev 11306)
+++ branches/soc-2007-maike/source/blender/include/BIF_glsl_material_node.h	2007-07-18 16:43:40 UTC (rev 11307)
@@ -3,9 +3,9 @@
 
 /* ---------------------------------------------------------------------------------------------------------- */
 
-struct GLSL_NodeCode_ *glsl_material_node(struct Material *mat, int *diffuse, int *specular, int *lights, int num);
+struct GLSL_NodeCode_ *glsl_material_node(struct Material *mat, int *diffuse, int *specular, int *lights, int *blend, int num);
 char *glsl_material_node_uniforms(int num);
-char *glsl_material_node_func(struct Material *mat, int *diffuse, int *specular, int *lights, int num);
+char *glsl_material_node_func(struct Material *mat, int *diffuse, int *specular, int *lights, int *blend, int num);
 char *glsl_material_lights(struct Material *mat, int *diff, int *spec, int *lights);
 
 char *glsl_write_light_funcs(int diff, int spec, int vis);

Modified: branches/soc-2007-maike/source/blender/src/buttons_shading.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/buttons_shading.c	2007-07-18 16:02:34 UTC (rev 11306)
+++ branches/soc-2007-maike/source/blender/src/buttons_shading.c	2007-07-18 16:43:40 UTC (rev 11307)
@@ -3055,32 +3055,32 @@
 		}
 		break;
 	case B_MAT_CB_REWR:
+	  do_matbuts(B_MATPRV);
 	  if(ma){
 	    if(glsl_active())
 	      glsl_update_material(ma, event);
 	  }
-	  do_matbuts(B_MATPRV);
 	  break;
 	case B_MAT_CB_REDR:
+	  do_matbuts(B_MATPRV);
 	  if(ma){
 	    if(glsl_active())
 	      glsl_colorband_create_tex(ma);
 	  }
-	  do_matbuts(B_MATPRV);
 	  break;
 	case B_MAT_CB_UNIFS:
+	  do_matbuts(B_MATPRV);
 	  if(ma){
 	    if(glsl_active())
 	      glsl_update_mat_colorband_uniforms(ma);
 	  }
-	  do_matbuts(B_MATPRV);
 	  break;
 	case B_MAT_UNIFS:
+	  do_matbuts(B_MATPRV);
 	  if(ma){
 	    if(glsl_active())
 	      glsl_update_material(ma, 0);
 	  }
-	  do_matbuts(B_MATPRV);
 	  break;
 	}
    

Modified: branches/soc-2007-maike/source/blender/src/glsl_colorband.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_colorband.c	2007-07-18 16:02:34 UTC (rev 11306)
+++ branches/soc-2007-maike/source/blender/src/glsl_colorband.c	2007-07-18 16:43:40 UTC (rev 11307)
@@ -19,6 +19,7 @@
 #include "BIF_glsl_material_node.h"
 #include "BIF_glsl_node_util.h"
 #include "BIF_glsl_colorband.h"
+#include "BIF_glsl_uniforms.h"
 
 #include "DNA_material_types.h"
 #include "DNA_texture_types.h"
@@ -112,6 +113,10 @@
     default:
       break;
     }
+
+  glsl_colorband_create_tex(mat);
+  glsl_update_mat_colorband_uniforms(mat);
+  glsl_redo_mat_program(material);
 }
 
 
@@ -133,6 +138,8 @@
     default:
       break;
     }
+
+  glsl_redo_mat_program(material);
 }
 
 
@@ -162,7 +169,7 @@
     glDeleteTextures(1, &colorband->texid);
 
   for(i = 0; i < 512; i++){
-    do_colorband(cb, i / 512, texels);
+    do_colorband(cb, (float) i / 511, texels);
     cb_tex[i][0] = texels[0];
     cb_tex[i][1] = texels[1];
     cb_tex[i][2] = texels[2];
@@ -170,13 +177,31 @@
   }
 
   glEnable(GL_TEXTURE_1D);
+  glActiveTexture(GL_TEXTURE0);
   glGenTextures(1, &tex_name);
-  
+  glBindTexture(GL_TEXTURE_1D, tex_name);
   colorband->texid = tex_name;
-
-  glBindTexture(GL_TEXTURE_1D, tex_name);
   glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, COLORBAND_WIDTH, 0, GL_RGBA, GL_UNSIGNED_BYTE, cb_tex);
   glDisable(GL_TEXTURE_1D);
 
   colorband->tex_set = 1;
 }
+
+
+void glsl_colorband_attach_tex(GLSL_Material material, int type)
+{
+  GHashIterator *iter = BLI_ghashIterator_new(material->parent);
+  int i;
+
+  for(i = 0; i < BLI_ghash_size(material->parent); i++, BLI_ghashIterator_step(iter)){
+    GLSL_MaterialTree tree = BLI_ghashIterator_getKey(iter);
+    GLSL_Program shaded = tree->shaded_program;
+
+    while(shaded){
+      
+      shaded = shaded->next;
+    }
+  }
+
+  BLI_ghashIterator_free(iter);
+}

Added: branches/soc-2007-maike/source/blender/src/glsl_colorband_node.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_colorband_node.c	                        (rev 0)
+++ branches/soc-2007-maike/source/blender/src/glsl_colorband_node.c	2007-07-18 16:43:40 UTC (rev 11307)
@@ -0,0 +1,206 @@
+#include <GL/glew.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <stdio.h>
+
+#include "blendef.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_ghash.h"
+
+#include "BIF_glsl_program.h"
+#include "BIF_glsl_material.h"
+#include "BIF_glutil.h"
+#include "BIF_glsl_light.h"
+#include "BIF_glsl_util.h"
+#include "BIF_glsl_shader_util.h"
+#include "BIF_glsl_material_node.h"
+#include "BIF_glsl_node_util.h"
+#include "BIF_glsl_colorband.h"
+#include "BIF_glsl_colorband_node.h"
+
+#include "DNA_material_types.h"
+#include "DNA_texture_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_key_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BKE_bad_level_calls.h"
+#include "BKE_global.h"
+#include "BKE_texture.h"
+
+
+
+GLSL_NodeCode glsl_colorband_node(Material *mat, int *blend, int num, int ramp_num)
+{
+  GLSL_NodeCode node_code = glsl_init_nodecode();
+
+  node_code->uniform_code = glsl_colorband_node_uniforms(num, ramp_num);
+  node_code->node_code = glsl_colorband_node_defines(mat, blend, num, ramp_num);
+  node_code->main_code = NULL;
+  
+  return node_code;
+}
+
+
+char *glsl_colorband_node_uniforms(int num, int ramp_num)
+{
+  char *code, *sampler, *fac;
+
+  sampler = glsl_string(5,
+			0, "uniform sampler1D u_mat_", 
+			GINT, num, 
+			0, "_ramp_",
+			GINT, ramp_num, 
+			0, "_tex;\n");
+  
+  fac = glsl_string(5,
+		    0, "uniform float u_mat_",
+		    GINT, num,
+		    0, "_ramp_",
+		    GINT, ramp_num,
+		    0, "_fac;\n");
+
+  code = glsl_string(2, GFREE, sampler, GFREE, fac);
+
+  return code;
+}
+
+
+char *glsl_colorband_node_defines(Material *mat, int *blend, int num, int ramp_num)
+{
+  char *blendmode[16] = { "mix", "add", "mult", "sub", "screen", "div", "dif", "dark", "light", "overlay", "dodge", "burn", "hue", "sat", "val", "color" };
+  char *code, *type, *func, *tex, *fac;
+  int blen_type;
+
+  if(!ramp_num){
+    type = glsl_string(3, 
+		       0, "#define DIFF_CB_TYPE ", 
+		       GINT, mat->rampin_col, 
+		       0, "\n");
+    
+    func = glsl_string(3, 
+		       0, "#define DIFF_CB_BLEND_FUNC colorband_blend_", 
+		       0, blendmode[mat->rampblend_col],
+		       0, "\n");
+    
+    tex  = glsl_string(5, 
+		       0, "#define DIFF_CB_TEX u_mat_", 
+		       GINT, num, 
+		       0, "_ramp_", 
+		       GINT, ramp_num, 
+		       0, "_tex\n");
+    
+    fac  = glsl_string(5, 
+		       0, "#define DIFF_CB_FAC u_mat_", 
+		       GINT, num, 
+		       0, "_ramp_", 
+		       GINT, ramp_num, 
+		       0, "_fac\n");
+
+    blen_type = pow(2, mat->rampblend_col);
+  }
+  else{
+    type = glsl_string(3, 
+		       0, "#define SPEC_CB_TYPE ", 
+		       GINT, mat->rampin_spec, 
+		       0, "\n");
+    
+    func = glsl_string(3, 
+		       0, "#define SPEC_CB_BLEND_FUNC colorband_blend_", 
+		       0, blendmode[mat->rampblend_spec],
+		       0, "\n");
+    
+    tex  = glsl_string(5, 
+		       0, "#define SPEC_CB_TEX u_mat_", 
+		       GINT, num, 
+		       0, "_ramp_", 
+		       GINT, ramp_num, 
+		       0, "_tex\n");
+    
+    fac  = glsl_string(5, 
+		       0, "#define SPEC_CB_FAC u_mat_", 
+		       GINT, num, 
+		       0, "_ramp_", 
+		       GINT, ramp_num, 
+		       0, "_fac\n");
+
+    blen_type = pow(2, mat->rampblend_spec);
+  }
+
+  code = glsl_string(4, 
+		     GFREE, type, 
+		     GFREE, func, 
+		     GFREE, tex, 
+		     GFREE, fac);
+  
+  if(!(*blend & blen_type))
+    *blend += blen_type;
+ 
+  return code;
+}
+
+
+char *glsl_colorband_blend_funcs(int blend)
+{
+  char *code = NULL;
+
+  if(blend & GLSL_CB_BLEND_COLOR){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_color.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_VAL){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_val.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_SAT){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_sat.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_HUE){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_hue.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_BURN){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_burn.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_DODGE){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_dodge.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_OVERLAY){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_overlay.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_LIGHT){
+    code = glsl_string(2, GFREE, code, GFREE, glsl_get_func("colorband_blend_light.gsl"));
+  }
+  if(blend & GLSL_CB_BLEND_DARK){

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list