[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54869] trunk/blender: OpenGL: implemenation of fixed function lighting as per pixel GLSL shaders.

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Feb 26 01:49:42 CET 2013


Revision: 54869
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54869
Author:   blendix
Date:     2013-02-26 00:49:42 +0000 (Tue, 26 Feb 2013)
Log Message:
-----------
OpenGL: implemenation of fixed function lighting as per pixel GLSL shaders. The
code is still unused, but the intention is to use this to solve the double sided
lighting problem on NVidia, and to make the materials work on OpenGL ES 2.0
eventually.

The code works and matches the fixed function lighting pretty much exactly, but
still needs optimizations. The actual integration in object draw will be
committed later when more fixing & testing, there's lots of different combinations
and unclear OpenGL state here.

Modified Paths:
--------------
    trunk/blender/SConstruct
    trunk/blender/source/blender/gpu/CMakeLists.txt
    trunk/blender/source/blender/gpu/GPU_extensions.h
    trunk/blender/source/blender/gpu/SConscript
    trunk/blender/source/blender/gpu/intern/gpu_codegen.c
    trunk/blender/source/blender/gpu/intern/gpu_extensions.c
    trunk/blender/source/blender/gpu/intern/gpu_material.c
    trunk/blender/source/blender/gpu/shaders/gpu_shader_vertex.glsl

Added Paths:
-----------
    trunk/blender/source/blender/gpu/intern/gpu_fixed_material.c
    trunk/blender/source/blender/gpu/shaders/gpu_shader_fixed_fragment.glsl
    trunk/blender/source/blender/gpu/shaders/gpu_shader_fixed_vertex.glsl

Modified: trunk/blender/SConstruct
===================================================================
--- trunk/blender/SConstruct	2013-02-26 00:49:38 UTC (rev 54868)
+++ trunk/blender/SConstruct	2013-02-26 00:49:42 UTC (rev 54869)
@@ -527,11 +527,13 @@
     data_to_c_simple("release/datafiles/preview_cycles.blend")
 
     # --- glsl ---
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fixed_fragment.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fixed_vertex.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
-    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vertex.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl")
-    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_material.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vertex.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl")
 

Modified: trunk/blender/source/blender/gpu/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/gpu/CMakeLists.txt	2013-02-26 00:49:38 UTC (rev 54868)
+++ trunk/blender/source/blender/gpu/CMakeLists.txt	2013-02-26 00:49:42 UTC (rev 54869)
@@ -50,6 +50,7 @@
 	intern/gpu_codegen.c
 	intern/gpu_draw.c
 	intern/gpu_extensions.c
+	intern/gpu_fixed_material.c
 	intern/gpu_material.c
 
 	GPU_buffers.h
@@ -59,10 +60,12 @@
 	intern/gpu_codegen.h
 )
 
+data_to_c_simple(shaders/gpu_shader_fixed_fragment.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_fixed_vertex.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_material.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vsm_store_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_vsm_store_vert.glsl SRC)
 

Modified: trunk/blender/source/blender/gpu/GPU_extensions.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_extensions.h	2013-02-26 00:49:38 UTC (rev 54868)
+++ trunk/blender/source/blender/gpu/GPU_extensions.h	2013-02-26 00:49:42 UTC (rev 54869)
@@ -32,6 +32,8 @@
 #ifndef __GPU_EXTENSIONS_H__
 #define __GPU_EXTENSIONS_H__
 
+#include "BLI_utildefines.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -160,17 +162,17 @@
  * - only for fragment shaders now
  * - must call texture bind before setting a texture as uniform! */
 
-GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode); /*GPUShader *lib);*/
-/*GPUShader *GPU_shader_create_lib(const char *code);*/
+GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines);
 void GPU_shader_free(GPUShader *shader);
 
 void GPU_shader_bind(GPUShader *shader);
-void GPU_shader_unbind(GPUShader *shader);
+void GPU_shader_unbind(void);
 
 int GPU_shader_get_uniform(GPUShader *shader, const char *name);
 void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
 	int arraysize, float *value);
 void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex);
+void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
 
 int GPU_shader_get_attribute(GPUShader *shader, const char *name);
 
@@ -199,6 +201,30 @@
 	int totlayer;
 } GPUVertexAttribs;
 
+/* Fixed Function Materials */
+
+typedef enum GPUFixedMaterialOption {
+	GPU_FIXED_COLOR_MATERIAL = (1<<0),   /* replace diffuse with glcolor */
+	GPU_FIXED_SOLID_LIGHTING = (1<<1),   /* use solid lighting (only 3 directional lights) */
+	GPU_FIXED_SCENE_LIGHTING = (1<<2),   /* use scene lighting (up to 8 arbitrary lights) */
+	GPU_FIXED_TWO_SIDED = (1<<3),        /* flip normals towards viewer */
+	GPU_FIXED_TEXTURE_2D = (1<<4),       /* use 2D texture to replace diffuse color */
+
+	GPU_FIXED_OPTIONS_NUM = 5,
+	GPU_FIXED_OPTION_COMBINATIONS = (1<<GPU_FIXED_OPTIONS_NUM)
+} GPUFixedMaterialOption;
+
+void GPU_fixed_materials_init(void);
+void GPU_fixed_materials_exit(void);
+
+void GPU_fixed_material_shader_bind(int options);
+void GPU_fixed_material_shader_unbind(void);
+
+void GPU_fixed_material_colors(const float diffuse[3], const float specular[3],
+	int shininess, float alpha);
+
+bool GPU_fixed_material_need_normals(void);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/blender/source/blender/gpu/SConscript
===================================================================
--- trunk/blender/source/blender/gpu/SConscript	2013-02-26 00:49:38 UTC (rev 54868)
+++ trunk/blender/source/blender/gpu/SConscript	2013-02-26 00:49:42 UTC (rev 54869)
@@ -49,10 +49,12 @@
 # generated data files
 import os
 sources.extend((
+	os.path.join(env['DATA_SOURCES'], "gpu_shader_fixed_fragment.glsl.c"),
+	os.path.join(env['DATA_SOURCES'], "gpu_shader_fixed_vertex.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_material.glsl.c"),
-	os.path.join(env['DATA_SOURCES'], "gpu_shader_vertex.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_sep_gaussian_blur_frag.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_sep_gaussian_blur_vert.glsl.c"),
+	os.path.join(env['DATA_SOURCES'], "gpu_shader_vertex.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_vsm_store_frag.glsl.c"),
 	os.path.join(env['DATA_SOURCES'], "gpu_shader_vsm_store_vert.glsl.c"),
 	))

Modified: trunk/blender/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_codegen.c	2013-02-26 00:49:38 UTC (rev 54868)
+++ trunk/blender/source/blender/gpu/intern/gpu_codegen.c	2013-02-26 00:49:42 UTC (rev 54869)
@@ -237,8 +237,6 @@
 	if (!FUNCTION_HASH) {
 		FUNCTION_HASH = BLI_ghash_str_new("GPU_lookup_function gh");
 		gpu_parse_functions_string(FUNCTION_HASH, glsl_material_library);
-		/*FUNCTION_PROTOTYPES = gpu_generate_function_prototyps(FUNCTION_HASH);
-		FUNCTION_LIB = GPU_shader_create_lib(datatoc_gpu_shader_material_glsl);*/
 	}
 
 	return (GPUFunction*)BLI_ghash_lookup(FUNCTION_HASH, (void *)name);
@@ -758,7 +756,7 @@
 		}
 	}
 
-	GPU_shader_unbind(shader);
+	GPU_shader_unbind();
 }
 
 void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
@@ -820,7 +818,7 @@
 			input->tex = NULL;
 	}
 	
-	GPU_shader_unbind(shader);
+	GPU_shader_unbind();
 }
 
 /* Node Link Functions */
@@ -1368,7 +1366,7 @@
 	/* generate code and compile with opengl */
 	fragmentcode = code_generate_fragment(nodes, outlink->output, name);
 	vertexcode = code_generate_vertex(nodes);
-	shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library); /*FUNCTION_LIB);*/
+	shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library, NULL);
 
 	/* failed? */
 	if (!shader) {

Modified: trunk/blender/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2013-02-26 00:49:38 UTC (rev 54868)
+++ trunk/blender/source/blender/gpu/intern/gpu_extensions.c	2013-02-26 00:49:42 UTC (rev 54869)
@@ -205,12 +205,15 @@
 #else
 	GG.os = GPU_OS_UNIX;
 #endif
+
+	GPU_fixed_materials_init();
 }
 
 void GPU_extensions_exit(void)
 {
 	gpu_extensions_init = 0;
 	GPU_codegen_exit();
+	GPU_fixed_materials_exit();
 }
 
 int GPU_glsl_support(void)
@@ -1006,7 +1009,7 @@
 	glTexCoord2d(0, 1); glVertex2f(1, -1);
 	glEnd();
 
-	GPU_shader_unbind(blur_shader);
+	GPU_shader_unbind();
 }
 
 /* GPUOffScreen */
@@ -1124,13 +1127,11 @@
 	fprintf(stderr, "%s\n", log);
 }
 
-GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, /*GPUShader *lib,*/ const char *libcode)
+GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines)
 {
 	GLint status;
 	GLcharARB log[5000];
-	const char *fragsource[2];
 	GLsizei length = 0;
-	GLint count;
 	GPUShader *shader;
 
 	if (!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader)
@@ -1154,8 +1155,14 @@
 	}
 
 	if (vertexcode) {
+		const char *source[2];
+		int num_source = 0;
+
+		if (defines) source[num_source++] = defines;
+		if (vertexcode) source[num_source++] = vertexcode;
+
 		glAttachObjectARB(shader->object, shader->vertex);
-		glShaderSourceARB(shader->vertex, 1, (const char**)&vertexcode, NULL);
+		glShaderSourceARB(shader->vertex, num_source, source, NULL);
 
 		glCompileShaderARB(shader->vertex);
 		glGetObjectParameterivARB(shader->vertex, GL_OBJECT_COMPILE_STATUS_ARB, &status);
@@ -1170,12 +1177,15 @@
 	}
 
 	if (fragcode) {
-		count = 0;
-		if (libcode) fragsource[count++] = libcode;
-		if (fragcode) fragsource[count++] = fragcode;
+		const char *source[3];
+		int num_source = 0;
 
+		if (defines) source[num_source++] = defines;
+		if (libcode) source[num_source++] = libcode;
+		if (fragcode) source[num_source++] = fragcode;
+
 		glAttachObjectARB(shader->object, shader->fragment);
-		glShaderSourceARB(shader->fragment, count, fragsource, NULL);
+		glShaderSourceARB(shader->fragment, num_source, source, NULL);
 
 		glCompileShaderARB(shader->fragment);
 		glGetObjectParameterivARB(shader->fragment, GL_OBJECT_COMPILE_STATUS_ARB, &status);
@@ -1254,7 +1264,7 @@
 	GPU_print_error("Post Shader Bind");
 }
 
-void GPU_shader_unbind(GPUShader *UNUSED(shader))
+void GPU_shader_unbind()
 {
 	GPU_print_error("Pre Shader Unbind");
 	glUseProgramObjectARB(0);
@@ -1296,6 +1306,16 @@
 	GPU_print_error("Post Uniform Vector");
 }
 
+void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value)
+{
+	if (location == -1)
+		return;
+
+	GPU_print_error("Pre Uniform Int");
+	glUniform1iARB(location, value);
+	GPU_print_error("Post Uniform Int");
+}
+
 void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUTexture *tex)
 {
 	GLenum arbnumber;
@@ -1344,12 +1364,12 @@
 	switch (shader) {
 		case GPU_SHADER_VSM_STORE:
 			if (!GG.shaders.vsm_store)
-				GG.shaders.vsm_store = GPU_shader_create(datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl, NULL);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list