[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15048] branches/apricot/source/blender:

Brecht Van Lommel brechtvanlommel at pandora.be
Thu May 29 15:07:45 CEST 2008


Revision: 15048
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15048
Author:   blendix
Date:     2008-05-29 15:07:45 +0200 (Thu, 29 May 2008)

Log Message:
-----------

Apricot Branch: basic material texture alpha support.

Modified Paths:
--------------
    branches/apricot/source/blender/gpu/GPU_material.h
    branches/apricot/source/blender/gpu/intern/gpu_codegen.c
    branches/apricot/source/blender/gpu/intern/gpu_material.c
    branches/apricot/source/blender/gpu/intern/material_shaders.glsl
    branches/apricot/source/blender/gpu/intern/material_shaders.glsl.c
    branches/apricot/source/blender/gpu/intern/material_vertex_shader.glsl
    branches/apricot/source/blender/src/drawobject.c

Modified: branches/apricot/source/blender/gpu/GPU_material.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_material.h	2008-05-29 11:41:06 UTC (rev 15047)
+++ branches/apricot/source/blender/gpu/GPU_material.h	2008-05-29 13:07:45 UTC (rev 15048)
@@ -9,6 +9,7 @@
 struct Image;
 struct ImageUser;
 struct Material;
+struct Object;
 struct GPUMaterial;
 typedef struct GPUMaterial GPUMaterial;
 
@@ -25,7 +26,7 @@
 GPUMaterial *GPU_material_construct_begin();
 int GPU_material_construct_end(GPUMaterial *material);
 void GPU_material_free(GPUMaterial *material);
-void GPU_material_bind(GPUMaterial *material);
+void GPU_material_bind(struct Object *ob, GPUMaterial *material);
 void GPU_material_unbind(GPUMaterial *material);
 
 void GPU_material_vertex_attributes(GPUMaterial *material,

Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.c	2008-05-29 11:41:06 UTC (rev 15047)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c	2008-05-29 13:07:45 UTC (rev 15048)
@@ -56,7 +56,7 @@
 #include <stdarg.h>
 
 #ifdef _WIN32
-#ifndef snprintf
+#ifndef vsnprintf
 #define _vsnprintf vsnprintf
 #endif
 #ifndef snprintf

Modified: branches/apricot/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_material.c	2008-05-29 11:41:06 UTC (rev 15047)
+++ branches/apricot/source/blender/gpu/intern/gpu_material.c	2008-05-29 13:07:45 UTC (rev 15048)
@@ -34,11 +34,16 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_image_types.h"
+#include "DNA_lamp_types.h"
 #include "DNA_listBase.h"
 #include "DNA_material_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
 #include "DNA_texture_types.h"
+#include "DNA_view3d_types.h"
 
 #include "BKE_DerivedMesh.h"
+#include "BKE_global.h"
 #include "BKE_utildefines.h"
 
 #include "BLI_blenlib.h"
@@ -56,6 +61,7 @@
 	ListBase passes;
 	GPUNodeBuf *outbuf;
 	GPUVertexAttribs attribs;
+	int alpha;
 };
 
 /* Functions */
@@ -175,16 +181,35 @@
 	MEM_freeN(material);
 }
 
-void GPU_material_bind(GPUMaterial *material)
+void GPU_material_bind(Object *ob, GPUMaterial *material)
 {
-	if (material->passes.last)
-		GPU_pass_bind(material->passes.last);
+	if (material->passes.last) {
+		GPUPass *pass = (GPUPass*)material->passes.last;
+		GPUShader *shader = pass->shader;
+
+		GPU_pass_bind(pass);
+
+		GPU_shader_uniform_vector(shader, "unfobmat", 16, 1, (float*)ob->obmat);
+		if(G.vd) /* hack */
+			GPU_shader_uniform_vector(shader, "unfviewmat", 16, 1, (float*)G.vd->viewmat);
+
+		if(material->alpha) {
+			glEnable(GL_BLEND);
+			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+		}
+	}
 }
 
 void GPU_material_unbind(GPUMaterial *material)
 {
-	if (material->passes.last)
-		GPU_pass_unbind(material->passes.last);
+	if (material->passes.last) {
+		GPUPass *pass = (GPUPass*)material->passes.last;
+
+		if(material->alpha)
+			glDisable(GL_BLEND);
+
+		GPU_pass_unbind(pass);
+	}
 }
 
 void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs)
@@ -257,17 +282,246 @@
 	GPU_node_output(node, out->type, out->name, &out->buf);
 }
 
+#if 0
+static void declare(char *name, ...)
+{
+	char *c;
+
+}
+
+static void call(char *name, ...)
+{
+	va_list params;
+	int i;
+
+	va_start(params, totparam)
+	for(i=0; i<totparam; i++) {
+	}
+	va_end(params);
+
+	int i;
+	double val;
+	printf ("Floats passed: ");
+	va_list vl;
+	va_start(vl,amount);
+	for (i=0;i<amount;i++)
+	{
+		val=va_arg(vl,double);
+		printf ("\t%.2f",val);
+	}
+	va_end(vl);
+	printf ("\n");
+}
+
+#include <stdarg.h>
+
+static int gpu_str_prefix(char *str, char *prefix)
+{
+	while(*str && *prefix) {
+		if(*str != *prefix)
+			return 0;
+
+		str++;
+		prefix++;
+	}
+	
+	return (*str == *prefix);
+}
+
+static char *gpu_str_skip(char *str)
+{
+	/* skip a variable/function name */
+	while(*str) {
+		if(ELEM6(*str, ' ', '(', ')', ',', '\t', '\n'))
+			break;
+		else
+			str++;
+	}
+
+	/* skip the next special characters */
+	while(*str) {
+		if(ELEM6(*str, ' ', '(', ')', ',', '\t', '\n'))
+			str++;
+		else
+			break;
+	}
+
+	return str;
+}
+
+static char* GPU_DATATYPE_STR[17] = {"", "float", "vec2", "vec3", "vec4",
+	0, 0, 0, 0, "mat3", 0, 0, 0, 0, 0, 0, "mat4"};
+
+#define decl(function, contents) GPU_declare(mat, #function, #contents);
+static void GPU_declare(GPUMaterial *mat, char *function, char *contents)
+{
+	int a, totparam, params[256];
+
+	/* skip void and function name */
+	if(!gpu_str_prefix(function, "void "))
+		return;
+	
+	function = gpu_str_skip(function);
+	function = gpu_str_skip(function);
+
+	/* get parameters */
+	totparam= 0;
+
+	while(*function) {
+		for(a=1; a<=16; a++) {
+			if(gpu_str_prefix(function, "out "))
+				function = gpu_str_skip(function);
+			else if(gpu_str_prefix(function, "in "))
+				function = gpu_str_skip(function);
+
+			if(gpu_str_prefix(function, GPU_DATATYPE_STR[a])) {
+				params[totparam]= a;
+				totparam++;
+
+				function = gpu_str_skip(function);
+				function = gpu_str_skip(function);
+				continue;
+			}
+		}
+		
+		break;
+	}
+}
+
+static void call(GPUMaterial *mat, char *name, ...)
+{
+	GPUNode *node;
+	va_list params;
+	int i, totparam = 0;
+
+	node = GPU_mat_node_create(mat, name, NULL, NULL);
+
+	va_start(params, name);
+	for(i=0; i<totparam; i++) {
+	}
+	va_end(params);
+}
+#endif
+
 /* Code generation */
 
+#if 0
+static void material_lights(GPUMaterial *mat, Material *ma, GPUNodeBuf *col, GPUNodeBuf *spec, GPUNodeBuf *nor)
+{
+	Base *base;
+	Object *lampob;
+	Lamp *la;
+	GPUNode *node;
+	GPUNodeBuf *lv, *dist, *visifac, *outcol;
+	float hard;
+	
+	for(base=G.scene->base.first; base; base=base->next) {
+		if(base->object->type==OB_LAMP) {
+			if(G.vd && base->lay & G.vd->lay) {
+				lampob= base->object;
+				la= lampob->data;
+
+				/* lamp_visibility */
+				if(la->type==LA_SUN || la->type==LA_HEMI)
+					node = GPU_mat_node_create(mat, "lamp_visibility_sun_hemi", NULL, NULL);
+				else
+					node = GPU_mat_node_create(mat, "lamp_visibility_other", NULL, NULL);
+
+				GPU_mat_node_uniform(node, GPU_VEC4, lampob->obmat[3]);
+				GPU_mat_node_uniform(node, GPU_VEC4, lampob->obmat[2]);
+				GPU_node_output(node, GPU_VEC3, "lv", &lv);
+				GPU_node_output(node, GPU_FLOAT, "dist", &dist);
+				GPU_node_output(node, GPU_FLOAT, "visifac", &visifac);
+
+				/* shade_one_light */
+				node = GPU_mat_node_create(mat, "shade_one_light", NULL, NULL);
+				GPU_node_input(node, GPU_VEC4, "col", NULL, col);
+				GPU_mat_node_uniform(node, GPU_FLOAT, &ma->ref);
+				GPU_node_input(node, GPU_VEC4, "spec", NULL, spec);
+				GPU_mat_node_uniform(node, GPU_FLOAT, &ma->spec);
+				hard= ma->har;
+				GPU_mat_node_uniform(node, GPU_FLOAT, &hard);
+				GPU_node_input(node, GPU_VEC3, "nor", NULL, nor);
+				GPU_node_input(node, GPU_VEC3, "lv", NULL, lv);
+				GPU_node_input(node, GPU_FLOAT, "visifac", NULL, visifac);
+				GPU_node_output(node, GPU_VEC4, "outcol", &outcol);
+
+				/* shade_one_light */
+				node = GPU_mat_node_create(mat, "shade_add", NULL, NULL);
+				GPU_node_input(node, GPU_VEC4, "col1", NULL, mat->outbuf);
+				GPU_node_input(node, GPU_VEC4, "col2", NULL, outcol);
+				GPU_node_output(node, GPU_VEC4, "outcol", &mat->outbuf);
+			}
+		}
+	}
+}
+#if 0
+				la= base->object->data;
+				
+				glPushMatrix();
+				glLoadMatrixf((float *)G.vd->viewmat);
+				
+				where_is_object_simul(base->object);
+				VECCOPY(vec, base->object->obmat[3]);
+				
+				if(la->type==LA_SUN) {
+					vec[0]= base->object->obmat[2][0];
+					vec[1]= base->object->obmat[2][1];
+					vec[2]= base->object->obmat[2][2];
+					vec[3]= 0.0;
+					glLightfv(GL_LIGHT0+count, GL_POSITION, vec); 
+				}
+				else {
+					vec[3]= 1.0;
+					glLightfv(GL_LIGHT0+count, GL_POSITION, vec); 
+					glLightf(GL_LIGHT0+count, GL_CONSTANT_ATTENUATION, 1.0);
+					glLightf(GL_LIGHT0+count, GL_LINEAR_ATTENUATION, la->att1/la->dist);
+					/* post 2.25 engine supports quad lights */
+					glLightf(GL_LIGHT0+count, GL_QUADRATIC_ATTENUATION, la->att2/(la->dist*la->dist));
+					
+					if(la->type==LA_SPOT) {
+						vec[0]= -base->object->obmat[2][0];
+						vec[1]= -base->object->obmat[2][1];
+						vec[2]= -base->object->obmat[2][2];
+						glLightfv(GL_LIGHT0+count, GL_SPOT_DIRECTION, vec);
+						glLightf(GL_LIGHT0+count, GL_SPOT_CUTOFF, la->spotsize/2.0);
+						glLightf(GL_LIGHT0+count, GL_SPOT_EXPONENT, 128.0*la->spotblend);
+					}
+					else glLightf(GL_LIGHT0+count, GL_SPOT_CUTOFF, 180.0);
+				}
+				
+				vec[0]= la->energy*la->r;
+				vec[1]= la->energy*la->g;
+				vec[2]= la->energy*la->b;
+				vec[3]= 1.0;
+				glLightfv(GL_LIGHT0+count, GL_DIFFUSE, vec); 
+				glLightfv(GL_LIGHT0+count, GL_SPECULAR, vec);//zero); 
+				glEnable(GL_LIGHT0+count);
+				
+				glPopMatrix();					
+				
+				count++;
+				if(count>7) break;
+			}
+			}
+		}
+		base= base->next;
+	}
+
+	return count;
+}
+#endif
+#endif
+
 static GPUNodeBuf *texture_rgb_blend(GPUMaterial *mat, GPUNodeBuf *texbuf, GPUNodeBuf *outbuf, GPUNodeBuf *factbuf, GPUNodeBuf *facgbuf, int blendtype)
 {
 	GPUNodeBuf *inbuf;
 	GPUNode *node;
 
 	if(blendtype == MTEX_BLEND)
-		node = GPU_mat_node_create(mat, "mtex_blend", NULL, NULL);
+		node = GPU_mat_node_create(mat, "mtex_rgb_blend", NULL, NULL);
 	else
-		node = GPU_mat_node_create(mat, "mtex_blend", NULL, NULL);
+		node = GPU_mat_node_create(mat, "mtex_rgb_blend", NULL, NULL);
 
 	GPU_node_input(node, GPU_VEC3, "out", NULL, outbuf);
 	GPU_node_input(node, GPU_VEC3, "tex", NULL, texbuf);
@@ -279,15 +533,36 @@
 	return inbuf;
 }
 
-static void material_tex_nodes_create(GPUMaterial *mat, Material *ma, GPUNodeBuf **colbuf_r, GPUNodeBuf **specbuf_r, GPUNodeBuf **norbuf_r)
+static GPUNodeBuf *texture_value_blend(GPUMaterial *mat, GPUNodeBuf *texbuf, GPUNodeBuf *outbuf, GPUNodeBuf *factbuf, GPUNodeBuf *facgbuf, int blendtype)
 {
+	GPUNodeBuf *inbuf;
+	GPUNode *node;
+
+	if(blendtype == MTEX_BLEND)
+		node = GPU_mat_node_create(mat, "mtex_value_blend", NULL, NULL);
+	else
+		node = GPU_mat_node_create(mat, "mtex_value_blend", NULL, NULL);
+
+	GPU_node_input(node, GPU_FLOAT, "out", NULL, outbuf);
+	GPU_node_input(node, GPU_FLOAT, "tex", NULL, texbuf);
+	GPU_node_input(node, GPU_FLOAT, "fact", NULL, factbuf);
+	GPU_node_input(node, GPU_FLOAT, "facg", NULL, facgbuf);
+
+	GPU_node_output(node, GPU_FLOAT, "in", &inbuf);
+
+	return inbuf;
+}
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list