[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58938] branches/soc-2013-viewport_fx/ source/blender/gpu: Cleaning up shader code.
Jason Wilkins
Jason.A.Wilkins at gmail.com
Mon Aug 5 19:11:35 CEST 2013
Revision: 58938
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58938
Author: jwilkins
Date: 2013-08-05 17:11:35 +0000 (Mon, 05 Aug 2013)
Log Message:
-----------
Cleaning up shader code. Added transform code for spot lights. Still doesn't draw...
Modified Paths:
--------------
branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c
branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_font_shader.c
branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_lighting.c
branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl
branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_constants.glsl
branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_uniforms.glsl
Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c 2013-08-05 16:45:36 UTC (rev 58937)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_basic_shader.c 2013-08-05 17:11:35 UTC (rev 58938)
@@ -114,10 +114,12 @@
static uint32_t tweak_options(void)
{
/* detect if we can do faster lighting for solid draw mode */
- if (BASIC_SHADER.options & GPU_BASIC_LIGHTING && gpu_fast_lighting())
+ if ( BASIC_SHADER.options & GPU_BASIC_LIGHTING &&
+ !(BASIC_SHADER.options & GPU_BASIC_LOCAL_VIEWER) &&
+ gpu_fast_lighting())
+ {
BASIC_SHADER.options |= GPU_BASIC_FAST_LIGHTING;
- else
- BASIC_SHADER.options &= ~GPU_BASIC_FAST_LIGHTING;
+ }
return BASIC_SHADER.options;
}
@@ -170,7 +172,7 @@
if (options & GPU_BASIC_FAST_LIGHTING)
BLI_dynstr_append(defs, "#define USE_FAST_LIGHTING\n");
- else if (options & GPU_BASIC_LIGHTING)
+ else
BLI_dynstr_append(defs, "#define USE_SCENE_LIGHTING\n");
}
Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_font_shader.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_font_shader.c 2013-08-05 16:45:36 UTC (rev 58937)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_font_shader.c 2013-08-05 17:11:35 UTC (rev 58938)
@@ -90,7 +90,7 @@
BLI_dynstr_append(frag, datatoc_gpu_shader_font_frag_glsl);
gpu_include_common_defs(defs);
- BLI_dynstr_append(defs, "#define USE_TEXTURE\n");
+ BLI_dynstr_append(defs, "#define USE_TEXTURE_2D\n");
FONT_SHADER =
GPU_shader_create(
Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_lighting.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_lighting.c 2013-08-05 16:45:36 UTC (rev 58937)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_lighting.c 2013-08-05 17:11:35 UTC (rev 58938)
@@ -177,28 +177,30 @@
-static void feedback_light_position(float position[4] /* in-out */)
+void GPU_restore_basic_lights(int light_count, GPUbasiclight lights[])
{
- gpuFeedbackVertex4fv(GL_MODELVIEW_MATRIX, position[0], position[1], position[2], position[3], position);
- gpuFeedbackVertex4fv(GL_PROJECTION_MATRIX, position[0], position[1], position[2], position[4], position);
+ GPU_ASSERT(light_count < GPU_MAX_COMMON_LIGHTS);
+
+ memcpy(LIGHTING.light, lights, light_count*sizeof(GPUbasiclight));
+
+ LIGHTING.light_count = light_count;
}
-static void feedback_spot_direction(float spot_direction[4] /* in-out */)
+static void feedback_light_position(float position[4] /* in-out */)
{
- // XXX jwilkins: ToDo!!
+ gpuFeedbackVertex4fv(GL_MODELVIEW_MATRIX, position[0], position[1], position[2], position[3], position);
}
-void GPU_restore_basic_lights(int light_count, GPUbasiclight lights[])
+static void feedback_spot_direction(float spot_direction[3] /* in-out */)
{
- GPU_ASSERT(light_count < GPU_MAX_COMMON_LIGHTS);
+ float n[3][3];
- memcpy(LIGHTING.light, lights, light_count*sizeof(GPUbasiclight));
-
- LIGHTING.light_count = light_count;
+ copy_m3_m4(n, (float (*)[4])gpuGetMatrix(GL_MODELVIEW_MATRIX, NULL));
+ mul_m3_v3(n, spot_direction);
}
Modified: branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl 2013-08-05 16:45:36 UTC (rev 58937)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl 2013-08-05 17:11:35 UTC (rev 58938)
@@ -1,19 +1,25 @@
/* Options:
- *
- * USE_TEXTURE_2D: use texture for diffuse colors
- * USE_SCENE_LIGHTING: use lights (up to 8)
- * USE_SOLID_LIGHTING: assume 3 directional lights for solid draw mode
- * USE_TWO_SIDE: flip normal towards viewer
- * NO_SPECULAR: use specular component
- */
+ USE_LIGHTING
+ USE_FAST_LIGHTING
+ USE_TWO_SIDE
+ USE_SPECULAR
+ USE_LOCAL_VIEWER
+ USE_TEXTURE_2D
+*/
-#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
+
+#define USE_SPECULAR
+
+
+
+#ifdef USE_LIGHTING
+
varying vec3 varying_normal;
-#ifndef USE_SOLID_LIGHTING
+#ifndef USE_FAST_LIGHTING
varying vec3 varying_position;
#endif
@@ -25,7 +31,7 @@
-#ifdef USE_TEXTURE
+#ifdef USE_TEXTURE_2D
varying vec2 varying_texture_coord;
#endif
@@ -33,11 +39,11 @@
void main()
{
-#if defined(USE_LIGHTING)
+#ifdef USE_LIGHTING
/* compute normal */
vec3 N = normalize(varying_normal);
-#if defined(USE_TWO_SIDE)
+#ifdef USE_TWO_SIDE
if (!gl_FrontFacing)
N = -N;
#endif
@@ -45,11 +51,11 @@
/* compute diffuse and specular lighting */
vec3 L_diffuse = vec3(0.0);
-#ifndef NO_SPECULAR
+#ifdef USE_SPECULAR
vec3 L_specular = vec3(0.0);
#endif
-#if defined(USE_SOLID_LIGHTING)
+#ifdef USE_FAST_LIGHTING
/* assume 3 directional lights */
for (int i = 0; i < b_LightCount; i++) {
vec3 light_direction = b_LightSource[i].position.xyz;
@@ -59,25 +65,18 @@
float diffuse_bsdf = max(dot(N, light_direction), 0.0);
L_diffuse += light_diffuse*diffuse_bsdf;
-#if !defined(NO_SPECULAR)
+#ifdef USE_SPECULAR
/* specular light */
vec3 light_specular = b_LightSource[i].specular.rgb;
- vec3 H = b_LightSource[i].halfVector.xyz;
+ vec3 H = normalize(light_direction - vec3(0, 0, -1));
float specular_bsdf = pow(max(dot(N, H), 0.0), b_FrontMaterial.shininess);
L_specular += light_specular*specular_bsdf;
#endif
}
-#else
+#else /* all 8 lights, makes no assumptions, potentially slow */
- /* all 8 lights, makes no assumptions, potentially slow */
-
-#if !defined(NO_SPECULAR)
- /* view vector computation, depends on orthographics or perspective */
- vec3 V = (b_ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position): vec3(0.0, 0.0, -1.0);
-#endif
-
for (int i = 0; i < b_LightCount; i++) {
float intensity = 1.0;
vec3 light_direction;
@@ -111,11 +110,16 @@
float diffuse_bsdf = max(dot(N, light_direction), 0.0);
L_diffuse += light_diffuse*diffuse_bsdf*intensity;
-#if !defined(NO_SPECULAR)
+#ifdef USE_SPECULAR
/* specular light */
vec3 light_specular = b_LightSource[i].specular.rgb;
- vec3 H = normalize(light_direction - V);
+#ifdef USE_LOCAL_VIEWER
+ vec3 H = normalize(light_direction - vec3(0, 0, -1));
+#else
+ vec3 H = normalize(light_direction - normalize(varying_position));
+#endif
+
float specular_bsdf = pow(max(dot(N, H), 0.0), b_FrontMaterial.shininess);
L_specular += light_specular*specular_bsdf*intensity;
#endif
@@ -126,7 +130,7 @@
/* compute diffuse color, possibly from texture or vertex colors */
float alpha;
-#if defined(USE_TEXTURE)
+#ifdef USE_TEXTURE_2D
vec4 texture_color = texture2D(b_Sampler[0], varying_texture_coord);
L_diffuse *= texture_color.rgb * varying_vertex_color.rgb;
@@ -139,17 +143,17 @@
/* sum lighting */
vec3 L = L_diffuse;
-#ifndef NO_SPECULAR
+#ifdef USE_SPECULAR
L += L_specular * b_FrontMaterial.specular.rgb;
#endif
/* write out fragment color */
gl_FragColor = vec4(L, alpha);
-#else
- /* no lighting */
-#if defined(USE_TEXTURE)
- gl_FragColor = texture2D(b_Sampler[0], varying_texture_coord) * varying_vertex_color;
+#else /* no lighting */
+
+#ifdef USE_TEXTURE_2D
+ gl_FragColor = texture2D(b_Sampler2D[0], varying_texture_coord) * varying_vertex_color;
#else
gl_FragColor = varying_vertex_color;
#endif
Modified: branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl 2013-08-05 16:45:36 UTC (rev 58937)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl 2013-08-05 17:11:35 UTC (rev 58938)
@@ -1,29 +1,39 @@
-#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
+
+
+#ifdef USE_LIGHTING
+
varying vec3 varying_normal;
-#ifndef USE_SOLID_LIGHTING
+#ifndef USE_FAST_LIGHTING
varying vec3 varying_position;
#endif
#endif
+
+
varying vec4 varying_vertex_color;
-#ifdef USE_TEXTURE
+
+
+#ifdef USE_TEXTURE_2D
varying vec2 varying_texture_coord;
#endif
+
+
void main()
{
vec4 co = b_ModelViewMatrix * b_Vertex;
-#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
+#ifdef USE_LIGHTING
varying_normal = normalize(b_NormalMatrix * b_Normal);
-#ifndef USE_SOLID_LIGHTING
+#ifndef USE_FAST_LIGHTING
varying_position = co.xyz;
#endif
+
#endif
gl_Position = b_ProjectionMatrix * co;
@@ -35,11 +45,10 @@
// gl_ClipVertex = b_ModelViewMatrix * b_Vertex;
//#endif
-#ifdef USE_COLOR
varying_vertex_color = b_Color;
-#endif
-#ifdef USE_TEXTURE
+#ifdef USE_TEXTURE_2D
varying_texture_coord = (b_TextureMatrix[0] * b_MultiTexCoord0).st;
#endif
}
+
Modified: branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl 2013-08-05 16:45:36 UTC (rev 58937)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_attribs.glsl 2013-08-05 17:11:35 UTC (rev 58938)
@@ -2,15 +2,13 @@
attribute vec4 b_Vertex;
-#if !defined(USE_MATERIAL_COLOR)
attribute vec4 b_Color;
-#endif
-#if defined(USE_LIGHTING)
+#ifdef USE_LIGHTING
attribute vec3 b_Normal;
#endif
-#if defined(USE_TEXTURE)
+#ifdef USE_TEXTURE_2D
#if GPU_MAX_COMMON_TEXCOORDS > 0
attribute vec4 b_MultiTexCoord0;
@@ -47,4 +45,3 @@
#endif
/* end known attributes */
-
Modified: branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_constants.glsl
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_constants.glsl 2013-08-05 16:45:36 UTC (rev 58937)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/shaders/gpu_shader_common_constants.glsl 2013-08-05 17:11:35 UTC (rev 58938)
@@ -1,11 +1,11 @@
-/* begin known constants */
+/* begin common constants */
-#if defined(USE_TEXTURE)
+#ifdef USE_TEXTURE_2D
const int b_MaxTextureCoords = GPU_MAX_COMMON_TEXCOORDS;
const int b_MaxCombinedTextureImageUnits = GPU_MAX_COMMON_SAMPLERS;
#endif
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list