[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11569] branches/soc-2007-maike: Added vertex shader code generation for texturing

Miguel Torres Lima torreslima at gmail.com
Sun Aug 12 20:11:44 CEST 2007


Revision: 11569
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11569
Author:   maike
Date:     2007-08-12 20:11:44 +0200 (Sun, 12 Aug 2007)

Log Message:
-----------
Added vertex shader code generation for texturing

Modified Paths:
--------------
    branches/soc-2007-maike/release/glsl/tex_magic.gsl
    branches/soc-2007-maike/release/glsl/vertex_shader.gsl
    branches/soc-2007-maike/source/blender/include/BIF_glsl_texture.h
    branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h
    branches/soc-2007-maike/source/blender/src/buttons_shading.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_texture_node.c

Added Paths:
-----------
    branches/soc-2007-maike/release/glsl/vertex_uniforms.gsl

Modified: branches/soc-2007-maike/release/glsl/tex_magic.gsl
===================================================================
--- branches/soc-2007-maike/release/glsl/tex_magic.gsl	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/release/glsl/tex_magic.gsl	2007-08-12 18:11:44 UTC (rev 11569)
@@ -1,7 +1,8 @@
-vec4 magic(vec3 coords, float depth, float turbulence)
+vec4 magic(vec3 coords, vec3 colfac, float depth, float turbulence, float contrast, float brightness)
 {
   float x, y, z;
   float turb = turbulence / 5.0;
+  float i;
   
   x = sin((coords.x + coords.y + coords.z) * 5.0);
   y = cos((-coords.x + coords.y - coords.z) * 5.0);
@@ -71,5 +72,11 @@
   y = 0.5 - y;
   z = 0.5 - z;
 
-  return(x, y, z, 0.3333*(x+y+z));
+  i = 0.3333*(x + y + z);
+
+  x = max(colfac.r * ((x - 0.5) * contrast + brightness - 0.5), 0.0);
+  y = max(colfac.g * ((y - 0.5) * contrast + brightness - 0.5), 0.0);
+  z = max(colfac.b * ((z - 0.5) * contrast + brightness - 0.5), 0.0);
+
+  return(x, y, z, i);
 }

Modified: branches/soc-2007-maike/release/glsl/vertex_shader.gsl
===================================================================
--- branches/soc-2007-maike/release/glsl/vertex_shader.gsl	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/release/glsl/vertex_shader.gsl	2007-08-12 18:11:44 UTC (rev 11569)
@@ -1,12 +1,5 @@
-varying vec3 normal, pos;
-varying vec3 vert_color;
-varying vec4 realcolor;
-attribute vec3 v_col;
-    
-void main(){
-	normal = normalize(gl_NormalMatrix * gl_Normal);
-	vert_color = v_col;
-	realcolor = gl_Color;
-	gl_Position = ftransform();
-	pos = vec3(gl_ModelViewMatrix * gl_Vertex);
-}
+normal = normalize(gl_NormalMatrix * gl_Normal);
+vert_color = v_col;
+realcolor = gl_Color;
+gl_Position = ftransform();
+pos = vec3(gl_ModelViewMatrix * gl_Vertex);

Added: branches/soc-2007-maike/release/glsl/vertex_uniforms.gsl
===================================================================
--- branches/soc-2007-maike/release/glsl/vertex_uniforms.gsl	                        (rev 0)
+++ branches/soc-2007-maike/release/glsl/vertex_uniforms.gsl	2007-08-12 18:11:44 UTC (rev 11569)
@@ -0,0 +1,4 @@
+varying vec3 normal, pos;
+varying vec3 vert_color;
+varying vec4 realcolor;
+attribute vec3 v_col;

Modified: branches/soc-2007-maike/source/blender/include/BIF_glsl_texture.h
===================================================================
--- branches/soc-2007-maike/source/blender/include/BIF_glsl_texture.h	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/source/blender/include/BIF_glsl_texture.h	2007-08-12 18:11:44 UTC (rev 11569)
@@ -20,7 +20,7 @@
 typedef struct GLSL_Texture_ *GLSL_Texture;
 
 
-GLSL_Texture glsl_init_texture(struct Material *mat, struct MTex *mtex, int index);
+struct GLSL_Texture_ *glsl_init_texture(struct Material *mat, struct MTex *mtex, int index);
 void glsl_clear_texture(struct Material *mat, int index);
 void glsl_paste_texture(struct Material *mat, int index);
 void glsl_set_texture_state(struct Material *mat, int index);

Modified: branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h
===================================================================
--- branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/source/blender/include/BIF_glsl_texture_node.h	2007-08-12 18:11:44 UTC (rev 11569)
@@ -1,7 +1,12 @@
 struct Material;
 struct GLSL_Material_;
+struct GLSL_MaterialTree_;
 struct GLSL_Texture_;
+struct GLSL_NodeCode_;
 
-GLSL_NodeCode glsl_texture_node(struct Material *mat, int num);
+/* ------------------------------------------------------------------------ */
+
+struct GLSL_NodeCode_ *glsl_texture_vertex_code(struct GLSL_MaterialTree_ *tree);
+struct GLSL_NodeCode_ *glsl_texture_node(struct Material *mat, int num);
 char *glsl_texture_struct(struct GLSL_Material_ *material);
 char *glsl_texture_magic(struct GLSL_Texture_ *texture, struct GLSL_Material_ *material, int index);

Modified: branches/soc-2007-maike/source/blender/src/buttons_shading.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/buttons_shading.c	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/source/blender/src/buttons_shading.c	2007-08-12 18:11:44 UTC (rev 11569)
@@ -1639,14 +1639,14 @@
 	/* RGB-BRICON */
 	if((tex->flag & TEX_COLORBAND)==0) {
 		uiBlockBeginAlign(block);
-		uiDefButF(block, NUMSLI, B_TEXPRV, "R ",		60,80,200,20, &tex->rfac, 0.0, 2.0, 0, 0, "Changes the red value of the texture");
-		uiDefButF(block, NUMSLI, B_TEXPRV, "G ",		60,60,200,20, &tex->gfac, 0.0, 2.0, 0, 0, "Changes the green value of the texture");
-		uiDefButF(block, NUMSLI, B_TEXPRV, "B ",		60,40,200,20, &tex->bfac, 0.0, 2.0, 0, 0, "Changes the blue value of the texture");
+		uiDefButF(block, NUMSLI, B_TEX_VAL, "R ",		60,80,200,20, &tex->rfac, 0.0, 2.0, 0, 0, "Changes the red value of the texture");
+		uiDefButF(block, NUMSLI, B_TEX_VAL, "G ",		60,60,200,20, &tex->gfac, 0.0, 2.0, 0, 0, "Changes the green value of the texture");
+		uiDefButF(block, NUMSLI, B_TEX_VAL, "B ",		60,40,200,20, &tex->bfac, 0.0, 2.0, 0, 0, "Changes the blue value of the texture");
 	}
 
 	uiBlockBeginAlign(block);
-	uiDefButF(block, NUMSLI, B_TEXPRV, "Bright",		10,10,150,20, &tex->bright, 0.0, 2.0, 0, 0, "Changes the brightness of the color or intensity of a texture");
-	uiDefButF(block, NUMSLI, B_TEXPRV, "Contr",			160,10,150,20, &tex->contrast, 0.01, 5.0, 0, 0, "Changes the contrast of the color or intensity of a texture");
+	uiDefButF(block, NUMSLI, B_TEX_VAL, "Bright",		10,10,150,20, &tex->bright, 0.0, 2.0, 0, 0, "Changes the brightness of the color or intensity of a texture");
+	uiDefButF(block, NUMSLI, B_TEX_VAL, "Contr",			160,10,150,20, &tex->contrast, 0.01, 5.0, 0, 0, "Changes the contrast of the color or intensity of a texture");
 }
 
 

Modified: branches/soc-2007-maike/source/blender/src/glsl_material_node.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_material_node.c	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/source/blender/src/glsl_material_node.c	2007-08-12 18:11:44 UTC (rev 11569)
@@ -50,8 +50,6 @@
     node_code->uniform_code = glsl_string(2, GFREE, node_code->uniform_code, GFREE, spec_ramp);
   }
 
-  
-  
   return node_code;
 }
 

Modified: branches/soc-2007-maike/source/blender/src/glsl_node_util.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_node_util.c	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/source/blender/src/glsl_node_util.c	2007-08-12 18:11:44 UTC (rev 11569)
@@ -21,6 +21,8 @@
 #include "BIF_glsl_material_node.h"
 #include "BIF_glsl_node_util.h"
 #include "BIF_glsl_colorband_node.h"
+#include "BIF_glsl_texture_node.h"
+#include "BIF_glsl_texture.h"
 
 #include "DNA_material_types.h"
 #include "DNA_lamp_types.h"
@@ -71,16 +73,37 @@
 GLuint glsl_vertex_code(GLSL_MaterialTree tree)
 {
   GLuint shader = 0; 
-
+  GLSL_NodeCode texture_node;
+  char *uniforms = NULL;
   char *code = NULL;
-  char vertexfile[FILE_MAXDIR + FILE_MAXFILE]; 
- 
-  BLI_make_file_string("/", vertexfile, install_dir, "vertex_shader.gsl");
 
-  if((code = read_shader_file(vertexfile)) == NULL){
+  if(!(uniforms = glsl_get_func("vertex_uniforms.gsl"))){
     return -1;
   }
 
+  if(!(code = glsl_get_func("vertex_shader.gsl"))){
+    MEM_freeN(uniforms);
+    return -1;
+  }
+  
+  if(!(texture_node = glsl_texture_vertex_code(tree))){
+    MEM_freeN(uniforms);
+    MEM_freeN(code);
+    return -1;
+  }
+
+  code = glsl_string(6,
+		     GFREE, uniforms,
+		     GFREE, texture_node->uniform_code,
+		     0, "void main(void){\n",
+		     GFREE, code,
+		     GFREE, texture_node->main_code,
+		     0, "}\n");
+
+  MEM_freeN(texture_node);
+
+  printf("\n Code:\n%s\n", code);
+
   shader = glsl_create_GLshader(code, GL_VERTEX_SHADER, 1);
 
   return shader;

Modified: branches/soc-2007-maike/source/blender/src/glsl_texture_node.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_texture_node.c	2007-08-12 14:41:54 UTC (rev 11568)
+++ branches/soc-2007-maike/source/blender/src/glsl_texture_node.c	2007-08-12 18:11:44 UTC (rev 11569)
@@ -12,6 +12,7 @@
 
 #include "BIF_glsl_program.h"
 #include "BIF_glsl_material.h"
+#include "BIF_glsl_materialtree.h"
 #include "BIF_glutil.h"
 #include "BIF_glsl_light.h"
 #include "BIF_glsl_util.h"
@@ -38,6 +39,56 @@
 #include "butspace.h"
 
 
+GLSL_NodeCode glsl_texture_vertex_code(GLSL_MaterialTree tree)
+{
+  GLSL_NodeCode texture_node = glsl_init_nodecode();
+  GHashIterator *iter = BLI_ghashIterator_new(tree->hash);
+  int i;
+
+  for(i = 0; i < BLI_ghash_size(tree->hash); i++, BLI_ghashIterator_step(iter)){
+    Material *mat = BLI_ghashIterator_getKey(iter);
+    int j;
+
+    for(j = 0; j < MAX_MTEX; j++){
+      if(mat->mtex[j]){
+	texture_node->uniform_code = glsl_string(6,
+					     GFREE, texture_node->uniform_code,
+					     0, "attribute vec3 mat_",
+					     GINT, i, 
+					     0, "_tex_",
+					     GINT, j,
+					     0, ";\n");
+
+	texture_node->uniform_code = glsl_string(6,
+					     GFREE, texture_node->uniform_code,
+					     0, "varying vec3 mat_",
+					     GINT, i, 
+					     0, "_tex_",
+					     GINT, j, 
+					     0, "_coords;\n");
+
+	texture_node->main_code = glsl_string(10,
+					      GFREE, texture_node->main_code,
+					      0, "mat_",
+					      GINT, i, 
+					      0, "_tex_",
+					      GINT, j, 
+					      0, "_coords = mat_",
+					      GINT, i, 
+					      0, "_tex_",
+					      GINT, j,
+					      0, ";\n");
+      }
+    }
+  }
+  
+  
+  BLI_ghashIterator_free(iter);
+
+  return texture_node;
+}
+
+
 GLSL_NodeCode glsl_texture_node(Material *mat, int num)
 {
 





More information about the Bf-blender-cvs mailing list