[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53567] branches/ge_harmony/source/blender /gpu: The built in light fragment shader now combines the code from gpu_shader_material and gpu_shader_light_frag instead of duplicating the code .

Daniel Stokes kupomail at gmail.com
Sat Jan 5 02:08:23 CET 2013


Revision: 53567
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53567
Author:   kupoman
Date:     2013-01-05 01:08:20 +0000 (Sat, 05 Jan 2013)
Log Message:
-----------
The built in light fragment shader now combines the code from gpu_shader_material and gpu_shader_light_frag instead of duplicating the code.

Modified Paths:
--------------
    branches/ge_harmony/source/blender/gpu/intern/gpu_extensions.c
    branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl

Modified: branches/ge_harmony/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- branches/ge_harmony/source/blender/gpu/intern/gpu_extensions.c	2013-01-04 22:48:51 UTC (rev 53566)
+++ branches/ge_harmony/source/blender/gpu/intern/gpu_extensions.c	2013-01-05 01:08:20 UTC (rev 53567)
@@ -78,6 +78,8 @@
 extern char datatoc_gpu_shader_prepass_frag_glsl[];
 extern char datatoc_gpu_shader_prepass_vert_glsl[];
 
+extern char datatoc_gpu_shader_material_glsl[];
+
 typedef struct GPUShaders {
 	GPUShader *vsm_store;
 	GPUShader *sep_gaussian_blur;
@@ -1417,8 +1419,12 @@
 			retval = GG.shaders.sep_gaussian_blur;
 			break;
 		case GPU_SHADER_LIGHT:
-			if (!GG.shaders.light)
-				GG.shaders.light = GPU_shader_create(NULL, datatoc_gpu_shader_light_frag_glsl, NULL, NULL, 0, 0);
+			if (!GG.shaders.light) {
+				char *frag = MEM_mallocN(strlen(datatoc_gpu_shader_light_frag_glsl) + strlen(datatoc_gpu_shader_material_glsl) + 1, "Light fragment shader");
+				sprintf(frag, "%s%s", datatoc_gpu_shader_material_glsl, datatoc_gpu_shader_light_frag_glsl);
+				GG.shaders.light = GPU_shader_create(NULL, frag, NULL, NULL, 0, 0);
+				MEM_freeN(frag);
+			}
 			retval = GG.shaders.light;
 			break;
 		case GPU_SHADER_PREPASS:

Modified: branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl
===================================================================
--- branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl	2013-01-04 22:48:51 UTC (rev 53566)
+++ branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl	2013-01-05 01:08:20 UTC (rev 53567)
@@ -1,5 +1,3 @@
-#version 120
-
 #define SPOT	0
 #define SUN		1
 #define HEMI	2
@@ -12,18 +10,18 @@
 #define SLIDERS		4
 
 //diff_shader
-#define DIFF_LAMBERT		0
+#define DIFF_LAMBERT	0
 #define DIFF_ORENNAYAR	1
 #define DIFF_TOON		2
-#define DIFF_MINNAERT    3
-#define DIFF_FRESNEL     4
+#define DIFF_MINNAERT	3
+#define DIFF_FRESNEL	4
 
 //spec_shader
 #define SPEC_COOKTORR	0
 #define SPEC_PHONG		1
 #define SPEC_BLINN		2
 #define SPEC_TOON		3
-#define SPEC_WARDISO		4
+#define SPEC_WARDISO	4
 
 #define LN_511	6.23636959
 
@@ -49,212 +47,6 @@
 uniform mat4 inv_proj_matrix;
 uniform vec2 bounds;
 
-void shade_diffuse_oren_nayer(float nl, vec3 n, vec3 l, vec3 v, float rough, out float is)
-{
-	vec3 h = normalize(v + l);
-	float nh = max(dot(n, h), 0.0);
-	float nv = max(dot(n, v), 0.0);
-	float realnl = dot(n, l);
-
-	if(realnl < 0.0) {
-		is = 0.0;
-	}
-	else if(nl < 0.0) {
-		is = 0.0;
-	}
-	else {
-		float vh = max(dot(v, h), 0.0);
-		float Lit_A = acos(realnl);
-		float View_A = acos(nv);
-
-		vec3 Lit_B = normalize(l - realnl*n);
-		vec3 View_B = normalize(v - nv*n);
-
-		float t = max(dot(Lit_B, View_B), 0.0);
-
-		float a, b;
-
-		if(Lit_A > View_A) {
-			a = Lit_A;
-			b = View_A;
-		}
-		else {
-			a = View_A;
-			b = Lit_A;
-		}
-
-		float A = 1.0 - (0.5*((rough*rough)/((rough*rough) + 0.33)));
-		float B = 0.45*((rough*rough)/((rough*rough) + 0.09));
-
-		b *= 0.95;
-		is = nl*(A + (B * t * sin(a) * tan(b)));
-	}
-}
-
-void shade_diffuse_toon(vec3 n, vec3 l, vec3 v, float size, float tsmooth, out float is)
-{
-	float rslt = dot(n, l);
-	float ang = acos(rslt);
-
-	if(ang < size) is = 1.0;
-	else if(ang > (size + tsmooth) || tsmooth == 0.0) is = 0.0;
-	else is = 1.0 - ((ang - size)/tsmooth);
-}
-
-void shade_diffuse_minnaert(float nl, vec3 n, vec3 v, float darkness, out float is)
-{
-	if(nl <= 0.0) {
-		is = 0.0;
-	}
-	else {
-		float nv = max(dot(n, v), 0.0);
-
-		if(darkness <= 1.0)
-			is = nl*pow(max(nv*nl, 0.1), darkness - 1.0);
-		else
-			is = nl*pow(1.0001 - nv, darkness - 1.0);
-	}
-}
-
-float fresnel_fac(vec3 view, vec3 vn, float grad, float fac)
-{
-	float t1, t2;
-	float ffac;
-
-	if(fac==0.0) {
-		ffac = 1.0;
-	}
-	else {
-		t1= dot(view, vn);
-		if(t1>0.0)  t2= 1.0+t1;
-		else t2= 1.0-t1;
-
-		t2= grad + (1.0-grad)*pow(t2, fac);
-
-		if(t2<0.0) ffac = 0.0;
-		else if(t2>1.0) ffac = 1.0;
-		else ffac = t2;
-	}
-
-	return ffac;
-}
-
-void shade_diffuse_fresnel(vec3 vn, vec3 lv, vec3 view, float fac_i, float fac, out float is)
-{
-	is = fresnel_fac(lv, vn, fac_i, fac);
-}
-
-void shade_hemi_spec(vec3 vn, vec3 lv, vec3 view, float spec, float hard, float visifac, out float t)
-{
-	lv += view;
-	lv = normalize(lv);
-
-	t = dot(vn, lv);
-	t = 0.5*t + 0.5;
-
-	t = visifac*spec*pow(t, hard);
-}
-
-void shade_phong_spec(vec3 n, vec3 l, vec3 v, float hard, out float specfac)
-{
-	vec3 h = normalize(l + v);
-	float rslt = max(dot(h, n), 0.0);
-
-	specfac = pow(rslt, hard);
-}
-
-void shade_cooktorr_spec(vec3 n, vec3 l, vec3 v, float hard, out float specfac)
-{
-	vec3 h = normalize(v + l);
-	float nh = dot(n, h);
-
-	if(nh < 0.0) {
-		specfac = 0.0;
-	}
-	else {
-		float nv = max(dot(n, v), 0.0);
-		float i = pow(nh, hard);
-
-		i = i/(0.1+nv);
-		specfac = i;
-	}
-}
-
-void shade_blinn_spec(vec3 n, vec3 l, vec3 v, float refrac, float spec_power, out float specfac)
-{
-	if(refrac < 1.0) {
-		specfac = 0.0;
-	}
-	else if(spec_power == 0.0) {
-		specfac = 0.0;
-	}
-	else {
-		if(spec_power<100.0)
-			spec_power= sqrt(1.0/spec_power);
-		else
-			spec_power= 10.0/spec_power;
-
-		vec3 h = normalize(v + l);
-		float nh = dot(n, h);
-		if(nh < 0.0) {
-			specfac = 0.0;
-		}
-		else {
-			float nv = max(dot(n, v), 0.01);
-			float nl = dot(n, l);
-			if(nl <= 0.01) {
-				specfac = 0.0;
-			}
-			else {
-				float vh = max(dot(v, h), 0.01);
-
-				float a = 1.0;
-				float b = (2.0*nh*nv)/vh;
-				float c = (2.0*nh*nl)/vh;
-
-				float g = 0.0;
-
-				if(a < b && a < c) g = a;
-				else if(b < a && b < c) g = b;
-				else if(c < a && c < b) g = c;
-
-				float p = sqrt(((refrac * refrac)+(vh*vh)-1.0));
-				float f = (((p-vh)*(p-vh))/((p+vh)*(p+vh)))*(1.0+((((vh*(p+vh))-1.0)*((vh*(p+vh))-1.0))/(((vh*(p-vh))+1.0)*((vh*(p-vh))+1.0))));
-				float ang = acos(nh);
-
-				specfac = max(f*g*exp((-(ang*ang)/(2.0*spec_power*spec_power))), 0.0);
-			}
-		}
-	}
-}
-
-#define M_PI 3.14159265358979323846
-void shade_wardiso_spec(vec3 n, vec3 l, vec3 v, float rms, out float specfac)
-{
-	vec3 h = normalize(l + v);
-	float nh = max(dot(n, h), 0.001);
-	float nv = max(dot(n, v), 0.001);
-	float nl = max(dot(n, l), 0.001);
-	float angle = tan(acos(nh));
-	float alpha = max(rms, 0.001);
-
-	specfac= nl * (1.0/(4.0*M_PI*alpha*alpha))*(exp(-(angle*angle)/(alpha*alpha))/(sqrt(nv*nl)));
-}
-
-void shade_toon_spec(vec3 n, vec3 l, vec3 v, float size, float tsmooth, out float specfac)
-{
-	vec3 h = normalize(l + v);
-	float rslt = dot(h, n);
-	float ang = acos(rslt);
-
-	if(ang < size) rslt = 1.0;
-	else if(ang >= (size + tsmooth) || tsmooth == 0.0) rslt = 0.0;
-	else rslt = 1.0 - ((ang - size)/tsmooth);
-
-	specfac = rslt;
-}
-
-
 void main()
 {
 	vec3 L;




More information about the Bf-blender-cvs mailing list