[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11542] branches/soc-2007-maike: Material shadeless mode combined with vertex color bugfix

Miguel Torres Lima torreslima at gmail.com
Fri Aug 10 20:15:44 CEST 2007


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

Log Message:
-----------
Material shadeless mode combined with vertex color bugfix

Modified Paths:
--------------
    branches/soc-2007-maike/release/glsl/material.gsl
    branches/soc-2007-maike/release/glsl/material_return.gsl
    branches/soc-2007-maike/release/glsl/tex_magic.gsl
    branches/soc-2007-maike/source/blender/src/buttons_shading.c
    branches/soc-2007-maike/source/blender/src/glsl_drawobject.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_uniforms.c

Modified: branches/soc-2007-maike/release/glsl/material.gsl
===================================================================
--- branches/soc-2007-maike/release/glsl/material.gsl	2007-08-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/release/glsl/material.gsl	2007-08-10 18:15:44 UTC (rev 11542)
@@ -1,4 +1,4 @@
-vec3 MATERIAL_FUNC(inout vec3 diff_color, inout vec3 spec_color, inout vec3 normal, inout float alpha, float diff1, float diff2, float diff3, float spec1, float spec2, float spec3, float amb_fac, float emit, float hard, float tanv){
+vec3 MATERIAL_FUNC(inout vec3 diff_color, inout vec3 spec_color, inout vec3 normal, inout float alpha, float diff1, float diff2, float diff3, float spec1, float spec2, float spec3, float amb_fac, float emit, float hard, float tanv, float shless){
   vec3 diff_rslt = vec3(0.0, 0.0, 0.0);
   vec3 spec_rslt = vec3(0.0, 0.0, 0.0);
   vec3 amb_rslt = amb_color * amb_fac;
@@ -8,6 +8,8 @@
   float spec_cb_res = 0.0;
   vec3 norm = normal;
 
+  if(shless == 0.0){
+
   if(tanv > 0.0){
     norm = -(cross(cross(eye - pos, normal), normal));
   }

Modified: branches/soc-2007-maike/release/glsl/material_return.gsl
===================================================================
--- branches/soc-2007-maike/release/glsl/material_return.gsl	2007-08-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/release/glsl/material_return.gsl	2007-08-10 18:15:44 UTC (rev 11542)
@@ -41,7 +41,9 @@
 #else
   return(vec3(0.0, 0.0, 0.0));
 #endif
+}
 
+return(diff_color);
 
 #undef DIFF_CB_TYPE
 #undef SPEC_CB_TYPE

Modified: branches/soc-2007-maike/release/glsl/tex_magic.gsl
===================================================================
--- branches/soc-2007-maike/release/glsl/tex_magic.gsl	2007-08-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/release/glsl/tex_magic.gsl	2007-08-10 18:15:44 UTC (rev 11542)
@@ -1,54 +1,55 @@
-vec3 magic(vec3 coords, float depth, float turbulence)
+vec4 magic(vec3 coords, float depth, float turbulence)
 {
   float x, y, z;
+  float turb = turbulence / 5.0;
   
   x = sin((coords.x + coords.y + coords.z) * 5.0);
   y = cos((-coords.x + coords.y - coords.z) * 5.0);
   z = -cos((-coords.x - coords.y + coords.z) * 5.0);
 
   if(depth > 0){
-    x *= turbulence;
-    y *= turbulence;
-    z *= turbulence;
+    x *= turb;
+    y *= turb;
+    z *= turb;
     
     y = -cos(x-y+z);
-    y *= turbulence;
+    y *= turb;
 
     if(depth > 1){
       x = cos(x-y-z);
-      x *= turbulence;
+      x *= turb;
 
       if(depth > 2){
 	z = sin(-x-y-z);
-	z *= turbulence;
+	z *= turb;
 
 	if(depth > 3){
 	  x = -cos(-x+y-z);
-	  x *= turbulence;
+	  x *= turb;
 
 	  if(depth > 4){
 	    y = -sin(-x+y+z);
-	    y *= turbulence;
+	    y *= turb;
 
 	    if(depth > 5){
 	      y = -cos(-x+y+z);
-	      y *= turbulence;
+	      y *= turb;
 
 	      if(depth > 6){
 		x = cos(x+y+z);
-		x *= turbulence;
+		x *= turb;
 
 		if(depth > 7){
 		  z = sin(x+y-z);
-		  z *= turbulence;
+		  z *= turb;
 
 		  if(depth > 8){
 		    x = -cos(-x-y+z);
-		    x *= turbulence;
+		    x *= turb;
 
 		    if(depth > 9){
 		      y = -sin(x-y+z);
-		      y *= turbulence;
+		      y *= turb;
 		    }
 		  }
 		}
@@ -60,11 +61,15 @@
     }
   }
 
-  if(turbulence > 0.0){
-    x = x / (turbulence * 2.0);
-    y = y / (turbulence * 2.0);
-    z = z / (turbulence * 2.0);
+  if(turb > 0.0){
+    x = x / (turb * 2.0);
+    y = y / (turb * 2.0);
+    z = z / (turb * 2.0);
   }
 
-  return(0.5 - x, 0.5 - y, 0.5 - z);
+  x = 0.5 - x;
+  y = 0.5 - y;
+  z = 0.5 - z;
+
+  return(x, y, z, 0.3333*(x+y+z));
 }

Modified: branches/soc-2007-maike/source/blender/src/buttons_shading.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/buttons_shading.c	2007-08-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/source/blender/src/buttons_shading.c	2007-08-10 18:15:44 UTC (rev 11542)
@@ -3936,7 +3936,7 @@
 			uiDefButBitI(block, TOG, MA_VERTEXCOL, B_MAT_VCOL_LIGHT,	"VCol Light",	8,166,74,20, &(ma->mode), 0, 0, 0, 0, "Adds vertex colors as extra light");
 			uiDefButBitI(block, TOG, MA_VERTEXCOLP, B_MAT_VCOL_PAINT, "VCol Paint",	82,166,74,20, &(ma->mode), 0, 0, 0, 0, "Replaces material's colors with vertex colors");
 			uiDefButBitI(block, TOG, MA_FACETEXTURE, B_MAT_TEXFACE, "TexFace",		156,166,74,20, &(ma->mode), 0, 0, 0, 0, "Sets UV-Editor assigned texture as color and texture info for faces");
-			uiDefButBitI(block, TOG, MA_SHLESS, B_MATPRV, "Shadeless",	230,166,73,20, &(ma->mode), 0, 0, 0, 0, "Makes material insensitive to light or shadow");
+			uiDefButBitI(block, TOG, MA_SHLESS, B_MAT_UNIFS, "Shadeless",	230,166,73,20, &(ma->mode), 0, 0, 0, 0, "Makes material insensitive to light or shadow");
 			
 			uiDefButBitI(block, TOG, MA_NOMIST, B_NOP,	"No Mist",		8,146,74,20, &(ma->mode), 0, 0, 0, 0, "Sets the material to ignore mist values");
 			uiDefButBitI(block, TOG, MA_ENV, B_MATPRV,	"Env",			82,146,74,20, &(ma->mode), 0, 0, 0, 0, "Causes faces to render with alpha zero: allows sky/backdrop to show through (only for solid faces)");

Modified: branches/soc-2007-maike/source/blender/src/glsl_drawobject.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_drawobject.c	2007-08-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/source/blender/src/glsl_drawobject.c	2007-08-10 18:15:44 UTC (rev 11542)
@@ -366,12 +366,8 @@
     MCol *tmpcol;
     float tangent[12];
   
-    if(mat && mat->mode & MA_SHLESS){
-      glUseProgram(0);
-      glColor4f(mat->r, mat->g, mat->b, mat->alpha);
-    }
     
-    else if(!oldmat || mat != oldmat){
+    if(!oldmat || mat != oldmat){
       if(!mat)
 	mat = &defmaterial;
  
@@ -421,19 +417,27 @@
 
     if(program)
       set_vertex_color(mat, tmpcol, 1, program->program); 
+    else if(mat->mode & MA_SHLESS)
+      set_vertex_color(mat, tmpcol, 1, NULL); 
     create_vertex(ob, vert, face->v1, face->flag, &tangent[0], (mat->mode & MA_TANGENT_V)?1:0, 0);
 
     if(program)
       set_vertex_color(mat, tmpcol, 5, program->program); 
+    else if(mat->mode & MA_SHLESS)
+      set_vertex_color(mat, tmpcol, 5, NULL); 
     create_vertex(ob, vert, face->v2, face->flag, &tangent[0], (mat->mode & MA_TANGENT_V)?1:0, 1);
 
     if(program)
       set_vertex_color(mat, tmpcol, 9, program->program); 
+    else if(mat->mode & MA_SHLESS)
+      set_vertex_color(mat, tmpcol, 9, NULL); 
     create_vertex(ob, vert, face->v3, face->flag, &tangent[0], (mat->mode & MA_TANGENT_V)?1:0, 2);
     
     if(face->v4){
       if(program)
 	set_vertex_color(mat, tmpcol, 13, program->program); 
+      else if(mat->mode & MA_SHLESS)
+	set_vertex_color(mat, tmpcol, 13, NULL);  
       create_vertex(ob, vert, face->v4, face->flag, &tangent[0], (mat->mode & MA_TANGENT_V)?1:0, 3);
     }
     
@@ -551,7 +555,6 @@
   
   if(mat && mat->mode & MA_SHLESS){
     glUseProgram(0);
-    glColor4f(mat->r, mat->g, mat->b, mat->alpha);
   } 
   else{
     if(mat && mat->mode & MA_TANGENT_V){
@@ -642,10 +645,26 @@
 
 void set_vertex_color(Material *mat, MCol *mcol, int n, GLuint program)
 {
+  if(mat->mode & MA_SHLESS){
+    if(mat->mode & MA_VERTEXCOLP){
+      if(mcol){
+	unsigned char *col = (unsigned char *) mcol;
+	glColor4f(col[n+2] / 255.0f, col[n+1] / 255.0f, col[n] / 255.0f, col[n-1] / 255.0f);
+      }
+      else{
+	glColor4f(0.0, 0.0, 0.0, 1.0);
+      }
+    }
+    else{
+      glColor4f(mat->r, mat->g, mat->b, mat->alpha);
+    }
+    return;
+  }
+
   if(mat->mode & MA_VERTEXCOLP){
     if(mcol){
-      unsigned char *col = (unsigned char *) mcol;
-      glColor4f(col[n+2] / 255.0f, col[n+1] / 255.0f, col[n] / 255.0f, col[n-1] / 255.0f);
+	unsigned char *col = (unsigned char *) mcol;
+	glColor4f(col[n+2] / 255.0f, col[n+1] / 255.0f, col[n] / 255.0f, col[n-1] / 255.0f);
     }
     else{
       glColor4f(0.0, 0.0, 0.0, 1.0);

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-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/source/blender/src/glsl_material_node.c	2007-08-10 18:15:44 UTC (rev 11542)
@@ -60,7 +60,7 @@
 {
   char *code = NULL;
 
-  code = glsl_string(42,
+  code = glsl_string(45,
 		     0, "uniform vec3 u_mat_", GINT, num, 0, "_diff_color;\n",
 		     0, "uniform vec3 u_mat_", GINT, num, 0,"_spec_color;\n",
 		     0, "uniform vec3 u_mat_", GINT, num, 0, "_normal;\n",
@@ -74,7 +74,8 @@
 		     0, "uniform float u_mat_", GINT, num, 0, "_amb_fac;\n",
 		     0, "uniform float u_mat_", GINT, num, 0, "_emit;\n",
 		     0, "uniform float u_mat_", GINT, num, 0, "_hard;\n",
-		     0, "uniform float u_mat_", GINT, num, 0, "_tanv;\n");
+		     0, "uniform float u_mat_", GINT, num, 0, "_tanv;\n",
+		     0, "uniform float u_mat_", GINT, num, 0, "_shless;\n");
 
   return 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-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/source/blender/src/glsl_node_util.c	2007-08-10 18:15:44 UTC (rev 11542)
@@ -174,8 +174,9 @@
     " float emit = u_mat_0_emit;"
     " float hard = u_mat_0_hard;"
     " float tanv = u_mat_0_tanv;"
+    " float shless = u_mat_0_shless;"
 
-    " vec3 result = material_0(diff_color, spec_color, norm, alpha, diff1, diff2, diff3, spec1, spec2, spec3, amb_fac, emit, hard, tanv);"
+    " vec3 result = material_0(diff_color, spec_color, norm, alpha, diff1, diff2, diff3, spec1, spec2, spec3, amb_fac, emit, hard, tanv, shless);"
  
     " gl_FragColor = vec4(result, alpha);"
     "}\n" 

Modified: branches/soc-2007-maike/source/blender/src/glsl_uniforms.c
===================================================================
--- branches/soc-2007-maike/source/blender/src/glsl_uniforms.c	2007-08-10 17:27:36 UTC (rev 11541)
+++ branches/soc-2007-maike/source/blender/src/glsl_uniforms.c	2007-08-10 18:15:44 UTC (rev 11542)
@@ -116,7 +116,7 @@
   char *spec, *alpha, *amb_fac;
   char *diff1, *diff2, *diff3;
   char *spec1, *spec2, *spec3;
-  char *emit, *hard;
+  char *emit, *hard, *shless;
 
   glUseProgram(program);
 
@@ -142,6 +142,7 @@
   amb_fac = glsl_string(3, 0, "u_mat_", GINT, index, 0, "_amb_fac");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list