[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15467] branches/apricot/source/blender: Apricot Branch: GLSL

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Jul 7 12:52:09 CEST 2008


Revision: 15467
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15467
Author:   blendix
Date:     2008-07-07 12:52:09 +0200 (Mon, 07 Jul 2008)

Log Message:
-----------
Apricot Branch: GLSL
====================

* Added a separate "Layer" option for lamp shadows, that only
  restricts which objects cast shadow, instead of receive light
  and shadow.
* Added exp/log compatibility for GLSL versions < 1.10.
* Check for depth texture extension before using it.

Modified Paths:
--------------
    branches/apricot/source/blender/gpu/intern/gpu_codegen.c
    branches/apricot/source/blender/gpu/intern/gpu_extensions.c
    branches/apricot/source/blender/gpu/intern/gpu_material.c
    branches/apricot/source/blender/makesdna/DNA_lamp_types.h
    branches/apricot/source/blender/python/api2_2x/Lamp.c
    branches/apricot/source/blender/render/intern/include/render_types.h
    branches/apricot/source/blender/render/intern/source/rayshade.c
    branches/apricot/source/blender/render/intern/source/shadbuf.c
    branches/apricot/source/blender/render/intern/source/zbuf.c
    branches/apricot/source/blender/src/buttons_shading.c
    branches/apricot/source/blender/src/drawview.c

Added Paths:
-----------
    branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl
    branches/apricot/source/blender/gpu/intern/gpu_shader_vertex.glsl
    branches/apricot/source/blender/gpu/intern/gpu_shader_vertex.glsl.c

Removed Paths:
-------------
    branches/apricot/source/blender/gpu/intern/material_shaders.glsl
    branches/apricot/source/blender/gpu/intern/material_vertex_shader.glsl
    branches/apricot/source/blender/gpu/intern/material_vertex_shader.glsl.c

Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.c	2008-07-07 09:23:12 UTC (rev 15466)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c	2008-07-07 10:52:09 UTC (rev 15467)
@@ -51,8 +51,6 @@
 #include "GPU_extensions.h"
 
 #include "gpu_codegen.h"
-#include "material_vertex_shader.glsl.c"
-#include "material_shaders.glsl.c"
 
 #include <string.h>
 #include <stdarg.h>
@@ -66,6 +64,9 @@
 #endif
 #endif
 
+extern char datatoc_gpu_shader_material_glsl[];
+extern char datatoc_gpu_shader_vertex_glsl[];
+
 /* structs and defines */
 
 typedef enum GPUDataSource {
@@ -344,9 +345,9 @@
 {
 	if(!FUNCTION_HASH) {
 		FUNCTION_HASH = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp);
-		gpu_parse_functions_string(FUNCTION_HASH, datatoc_material_shaders_glsl);
+		gpu_parse_functions_string(FUNCTION_HASH, datatoc_gpu_shader_material_glsl);
 		FUNCTION_PROTOTYPES = gpu_generate_function_prototyps(FUNCTION_HASH);
-		FUNCTION_LIB = GPU_shader_create_lib(datatoc_material_shaders_glsl);
+		FUNCTION_LIB = GPU_shader_create_lib(datatoc_gpu_shader_material_glsl);
 	}
 
 	return (GPUFunction*)BLI_ghash_lookup(FUNCTION_HASH, name);
@@ -698,7 +699,7 @@
 	}
 
 	BLI_dynstr_append(ds, "\n");
-	BLI_dynstr_append(ds, datatoc_material_vertex_shader_glsl);
+	BLI_dynstr_append(ds, datatoc_gpu_shader_vertex_glsl);
 
 	for (node=nodes->first; node; node=node->next)
 		for (input=node->inputs.first; input; input=input->next)

Modified: branches/apricot/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_extensions.c	2008-07-07 09:23:12 UTC (rev 15466)
+++ branches/apricot/source/blender/gpu/intern/gpu_extensions.c	2008-07-07 10:52:09 UTC (rev 15467)
@@ -260,6 +260,9 @@
 	GLenum type, format;
 	void *pixels = NULL;
 
+	if(depth && !GLEW_ARB_depth_texture)
+		return NULL;
+
 	tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
 	tex->w = tex->realw = w;
 	tex->h = tex->realh = h;
@@ -285,10 +288,10 @@
 	tex->number = 0;
 	glBindTexture(tex->target, tex->bindcode);
 
-	if(depth) { /* TODO extensions */
+	if(depth) {
 		type = GL_UNSIGNED_BYTE;
 		format = GL_DEPTH_COMPONENT;
-		tex->internalformat = GL_DEPTH_COMPONENT16;
+		tex->internalformat = GL_DEPTH_COMPONENT;
 	}
 	else if (halffloat && (GLEW_ARB_texture_float || GLEW_ATI_texture_float)) {
 		type = GL_FLOAT;

Modified: branches/apricot/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_material.c	2008-07-07 09:23:12 UTC (rev 15466)
+++ branches/apricot/source/blender/gpu/intern/gpu_material.c	2008-07-07 10:52:09 UTC (rev 15467)
@@ -1184,9 +1184,9 @@
 
 int GPU_lamp_shadow_layer(GPULamp *lamp)
 {
-	if(lamp->fb && lamp->tex && (lamp->mode & LA_LAYER))
+	if(lamp->fb && lamp->tex && (lamp->mode & LA_LAYER|LA_LAYER_SHADOW))
 		return lamp->lay;
 	else
-		return 0;
+		return -1;
 }
 

Copied: branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl (from rev 15465, branches/apricot/source/blender/gpu/intern/material_shaders.glsl)
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl	                        (rev 0)
+++ branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl	2008-07-07 10:52:09 UTC (rev 15467)
@@ -0,0 +1,1551 @@
+
+#if __VERSION__ < 110
+
+float exp(float f)
+{
+	return pow(2.71828182846, f);
+}
+
+float log(float f)
+{
+	return log2(f)/log2(2.71828182846);
+}
+
+#endif
+
+void rgb_to_hsv(vec4 rgb, out vec4 outcol)
+{
+	float cmax, cmin, h, s, v, cdelta;
+	vec3 c;
+
+	cmax = max(rgb[0], max(rgb[1], rgb[2]));
+	cmin = min(rgb[0], min(rgb[1], rgb[2]));
+	cdelta = cmax-cmin;
+
+	v = cmax;
+	if (cmax!=0.0)
+		s = cdelta/cmax;
+	else {
+		s = 0.0;
+		h = 0.0;
+	}
+
+	if (s == 0.0) {
+		h = 0.0;
+	}
+	else {
+		c = (vec3(cmax, cmax, cmax) - rgb.xyz)/cdelta;
+
+		if (rgb.x==cmax) h = c[2] - c[1];
+		else if (rgb.y==cmax) h = 2.0 + c[0] -  c[2];
+		else h = 4.0 + c[1] - c[0];
+
+		h /= 6.0;
+
+		if (h<0.0)
+			h += 1.0;
+	}
+
+	outcol = vec4(h, s, v, rgb.w);
+}
+
+void hsv_to_rgb(vec4 hsv, out vec4 outcol)
+{
+	float i, f, p, q, t, h, s, v;
+	vec3 rgb;
+
+	h = hsv[0];
+	s = hsv[1];
+	v = hsv[2];
+
+	if(s==0.0) {
+		rgb = vec3(v, v, v);
+	}
+	else {
+		if(h==1.0)
+			h = 0.0;
+		
+		h *= 6.0;
+		i = floor(h);
+		f = h - i;
+		rgb = vec3(f, f, f);
+		p = v*(1.0-s);
+		q = v*(1.0-(s*f));
+		t = v*(1.0-(s*(1.0-f)));
+		
+		if (i == 0.0) rgb = vec3(v, t, p);
+		else if (i == 1.0) rgb = vec3(q, v, p);
+		else if (i == 2.0) rgb = vec3(p, v, t);
+		else if (i == 3.0) rgb = vec3(p, q, v);
+		else if (i == 4.0) rgb = vec3(t, p, v);
+		else rgb = vec3(v, p, q);
+	}
+
+	outcol = vec4(rgb, hsv.w);
+}
+
+#define M_PI 3.14159265358979323846
+
+/*********** SHADER NODES ***************/
+
+void vcol_attribute(vec4 attvcol, out vec4 vcol)
+{
+	vcol = vec4(attvcol.x/255.0, attvcol.y/255.0, attvcol.z/255.0, 1.0);
+}
+
+void uv_attribute(vec2 attuv, out vec3 uv)
+{
+	uv = vec3(attuv*2.0 - vec2(1.0, 1.0), 0.0);
+}
+
+void geom(vec3 co, vec3 nor, mat4 viewinvmat, vec3 attorco, vec2 attuv, vec4 attvcol, out vec3 global, out vec3 local, out vec3 view, out vec3 orco, out vec3 uv, out vec3 normal, out vec4 vcol, out float frontback)
+{
+	local = co;
+	view = normalize(local);
+	global = (viewinvmat*vec4(local, 1.0)).xyz;
+	orco = attorco;
+	uv_attribute(attuv, uv);
+	normal = -normalize(nor);	/* blender render normal is negated */
+	vcol_attribute(attvcol, vcol);
+	frontback = 1.0;
+}
+
+void mapping(vec3 vec, mat4 mat, vec3 minvec, vec3 maxvec, float domin, float domax, out vec3 outvec)
+{
+	outvec = (mat * vec4(vec, 1.0)).xyz;
+	if(domin == 1.0)
+		outvec = max(outvec, minvec);
+	if(domax == 1.0)
+		outvec = min(outvec, maxvec);
+}
+
+void camera(vec3 co, out vec3 outview, out float outdepth, out float outdist)
+{
+	outview = co;
+	outdepth = abs(outview.z);
+	outdist = length(outview);
+	outview = normalize(outview);
+}
+
+void math_add(float val1, float val2, out float outval)
+{
+	outval = val1 + val2;
+}
+
+void math_subtract(float val1, float val2, out float outval)
+{
+	outval = val1 - val2;
+}
+
+void math_multiply(float val1, float val2, out float outval)
+{
+	outval = val1 * val2;
+}
+
+void math_divide(float val1, float val2, out float outval)
+{
+	if (val2 == 0.0)
+		outval = 0.0;
+	else
+		outval = val1 / val2;
+}
+
+void math_sine(float val, out float outval)
+{
+	outval = sin(val);
+}
+
+void math_cosine(float val, out float outval)
+{
+	outval = cos(val);
+}
+
+void math_tangent(float val, out float outval)
+{
+	outval = tan(val);
+}
+
+void math_asin(float val, out float outval)
+{
+	if (val <= 1.0 && val >= -1.0)
+		outval = asin(val);
+	else
+		outval = 0.0;
+}
+
+void math_acos(float val, out float outval)
+{
+	if (val <= 1.0 && val >= -1.0)
+		outval = acos(val);
+	else
+		outval = 0.0;
+}
+
+void math_atan(float val, out float outval)
+{
+	outval = atan(val);
+}
+
+void math_pow(float val1, float val2, out float outval)
+{
+	if (val1 >= 0.0)
+		outval = pow(val1, val2);
+	else
+		outval = 0.0;
+}
+
+void math_log(float val1, float val2, out float outval)
+{
+	if(val1 > 0.0  && val2 > 0.0)
+		outval= log(val1) / log(val2);
+	else
+		outval= 0.0;
+}
+
+void math_max(float val1, float val2, out float outval)
+{
+	outval = max(val1, val2);
+}
+
+void math_min(float val1, float val2, out float outval)
+{
+	outval = min(val1, val2);
+}
+
+void math_round(float val, out float outval)
+{
+	outval= floor(val + 0.5);
+}
+
+void math_less_than(float val1, float val2, out float outval)
+{
+	if(val1 < val2)
+		outval = 1.0;
+	else
+		outval = 0.0;
+}
+
+void math_greater_than(float val1, float val2, out float outval)
+{
+	if(val1 > val2)
+		outval = 1.0;
+	else
+		outval = 0.0;
+}
+
+void squeeze(float val, float width, float center, out float outval)
+{
+	outval = 1.0/(1.0 + pow(2.71828183, -((val-center)*width)));
+}
+
+void vec_math_add(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
+{
+	outvec = v1 + v2;
+	outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2]))/3.0;
+}
+
+void vec_math_sub(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
+{
+	outvec = v1 - v2;
+	outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2]))/3.0;
+}
+
+void vec_math_average(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
+{
+	outvec = v1 + v2;
+	outval = length(outvec);
+	outvec = normalize(outvec);
+}
+
+void vec_math_dot(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
+{
+	outvec = vec3(0, 0, 0);
+	outval = dot(v1, v2);
+}
+
+void vec_math_cross(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
+{
+	outvec = cross(v1, v2);
+	outval = length(outvec);
+}
+
+void vec_math_normalize(vec3 v, out vec3 outvec, out float outval)
+{
+	outval = length(v);
+	outvec = normalize(v);
+}
+
+void vec_math_negate(vec3 v, out vec3 outv)
+{
+	outv = -v;
+}
+
+void normal(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
+{
+	outnor = dir;
+	outdot = -dot(dir, nor);
+}
+
+void curves_vec(vec3 vec, sampler1D curvemap, out vec3 outvec)
+{
+	outvec.x = texture1D(curvemap, (vec.x + 1.0)*0.5).x;
+	outvec.y = texture1D(curvemap, (vec.y + 1.0)*0.5).y;
+	outvec.z = texture1D(curvemap, (vec.z + 1.0)*0.5).z;
+}
+
+void curves_rgb(vec4 col, sampler1D curvemap, out vec4 outcol)
+{
+	outcol.r = texture1D(curvemap, texture1D(curvemap, col.r).a).r;
+	outcol.g = texture1D(curvemap, texture1D(curvemap, col.g).a).g;
+	outcol.b = texture1D(curvemap, texture1D(curvemap, col.b).a).b;
+	outcol.a = col.a;
+}
+
+void set_value(float val, out float outval)
+{
+	outval = val;
+}
+
+void set_rgb(vec3 col, out vec3 outcol)
+{
+	outcol = col;
+}
+
+void set_rgba(vec4 col, out vec4 outcol)
+{
+	outcol = col;
+}
+
+void set_value_zero(out float outval)
+{
+	outval = 0.0;
+}
+
+void set_rgb_zero(out vec3 outval)
+{
+	outval = vec3(0.0);
+}
+
+void set_rgba_zero(out vec4 outval)
+{
+	outval = vec4(0.0);
+}
+
+void mix_blend(float fac, vec4 col1, vec4 col2, out vec4 outcol)
+{
+	fac = clamp(fac, 0.0, 1.0);
+	outcol = mix(col1, col2, fac);
+	outcol.a = col1.a;
+}
+
+void mix_add(float fac, vec4 col1, vec4 col2, out vec4 outcol)
+{
+	fac = clamp(fac, 0.0, 1.0);
+	outcol = mix(col1, col1 + col2, fac);
+	outcol.a = col1.a;
+}
+
+void mix_mult(float fac, vec4 col1, vec4 col2, out vec4 outcol)
+{
+	fac = clamp(fac, 0.0, 1.0);
+	outcol = mix(col1, col1 * col2, fac);
+	outcol.a = col1.a;
+}
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list