[Bf-blender-cvs] [988ec3c] master: OpenSubdiv: Support shadeless shading

Sergey Sharybin noreply at git.blender.org
Mon Jul 25 15:38:41 CEST 2016


Commit: 988ec3c40c44f4454842f35c031cc447c62db255
Author: Sergey Sharybin
Date:   Mon Jul 25 15:38:28 2016 +0200
Branches: master
https://developer.blender.org/rB988ec3c40c44f4454842f35c031cc447c62db255

OpenSubdiv: Support shadeless shading

===================================================================

M	intern/opensubdiv/gpu_shader_opensubd_display.glsl
M	intern/opensubdiv/opensubdiv_gpu_capi.cc

===================================================================

diff --git a/intern/opensubdiv/gpu_shader_opensubd_display.glsl b/intern/opensubdiv/gpu_shader_opensubd_display.glsl
index cc9e05a..5193d3a 100644
--- a/intern/opensubdiv/gpu_shader_opensubd_display.glsl
+++ b/intern/opensubdiv/gpu_shader_opensubd_display.glsl
@@ -242,6 +242,7 @@ void main()
 	vec3 L_diffuse = vec3(0.0);
 	vec3 L_specular = vec3(0.0);
 
+#ifdef USE_LIGHTING
 #ifndef USE_COLOR_MATERIAL
 	/* Assume NUM_SOLID_LIGHTS directional lights. */
 	for (int i = 0; i < NUM_SOLID_LIGHTS; i++) {
@@ -312,6 +313,9 @@ void main()
 		L_specular += light_specular * specular_bsdf * intensity;
 	}
 #endif  /* USE_COLOR_MATERIAL */
+#else  /* USE_LIGHTING */
+	L_diffuse = vec3(1.0);
+#endif
 
 	/* Compute diffuse color. */
 #ifdef USE_TEXTURE_2D
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index 752dce7..0cf6fcf 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -100,6 +100,12 @@ static GLuint g_flat_fill_solid_program = 0;
 static GLuint g_flat_fill_texture2d_program = 0;
 static GLuint g_smooth_fill_solid_program = 0;
 static GLuint g_smooth_fill_texture2d_program = 0;
+
+static GLuint g_flat_fill_solid_shadeless_program = 0;
+static GLuint g_flat_fill_texture2d_shadeless_program = 0;
+static GLuint g_smooth_fill_solid_shadeless_program = 0;
+static GLuint g_smooth_fill_texture2d_shadeless_program = 0;
+
 static GLuint g_wireframe_program = 0;
 
 static GLuint g_lighting_ub = 0;
@@ -425,21 +431,45 @@ bool openSubdiv_osdGLDisplayInit(void)
 		g_flat_fill_solid_program = linkProgram(
 		        version,
 		        "#define USE_COLOR_MATERIAL\n"
+		        "#define USE_LIGHTING\n"
 		        "#define FLAT_SHADING\n");
 		g_flat_fill_texture2d_program = linkProgram(
 		        version,
 		        "#define USE_COLOR_MATERIAL\n"
+		        "#define USE_LIGHTING\n"
 		        "#define USE_TEXTURE_2D\n"
 		        "#define FLAT_SHADING\n");
 		g_smooth_fill_solid_program = linkProgram(
 		        version,
 		        "#define USE_COLOR_MATERIAL\n"
+		        "#define USE_LIGHTING\n"
 		        "#define SMOOTH_SHADING\n");
 		g_smooth_fill_texture2d_program = linkProgram(
 		        version,
 		        "#define USE_COLOR_MATERIAL\n"
+		        "#define USE_LIGHTING\n"
 		        "#define USE_TEXTURE_2D\n"
 		        "#define SMOOTH_SHADING\n");
+
+		g_flat_fill_solid_shadeless_program = linkProgram(
+		        version,
+		        "#define USE_COLOR_MATERIAL\n"
+		        "#define FLAT_SHADING\n");
+		g_flat_fill_texture2d_shadeless_program = linkProgram(
+		        version,
+		        "#define USE_COLOR_MATERIAL\n"
+		        "#define USE_TEXTURE_2D\n"
+		        "#define FLAT_SHADING\n");
+		g_smooth_fill_solid_shadeless_program = linkProgram(
+		        version,
+		        "#define USE_COLOR_MATERIAL\n"
+		        "#define SMOOTH_SHADING\n");
+		g_smooth_fill_texture2d_shadeless_program = linkProgram(
+		        version,
+		        "#define USE_COLOR_MATERIAL\n"
+		        "#define USE_TEXTURE_2D\n"
+		        "#define SMOOTH_SHADING\n");
+
 		g_wireframe_program = linkProgram(
 		        version,
 		        "#define WIREFRAME\n");
@@ -464,21 +494,24 @@ void openSubdiv_osdGLDisplayDeinit(void)
 	if (g_lighting_ub != 0) {
 		glDeleteBuffers(1, &g_lighting_ub);
 	}
-	if (g_flat_fill_solid_program) {
-		glDeleteProgram(g_flat_fill_solid_program);
-	}
-	if (g_flat_fill_texture2d_program) {
-		glDeleteProgram(g_flat_fill_texture2d_program);
-	}
-	if (g_smooth_fill_solid_program) {
-		glDeleteProgram(g_flat_fill_solid_program);
-	}
-	if (g_smooth_fill_texture2d_program) {
-		glDeleteProgram(g_smooth_fill_texture2d_program);
-	}
-	if (g_wireframe_program) {
-		glDeleteProgram(g_wireframe_program);
-	}
+#define SAFE_DELETE_PROGRAM(program) \
+	do { \
+		if (program) { \
+			glDeleteProgram(program); \
+		} \
+	} while (false)
+
+	SAFE_DELETE_PROGRAM(g_flat_fill_solid_program);
+	SAFE_DELETE_PROGRAM(g_flat_fill_texture2d_program);
+	SAFE_DELETE_PROGRAM(g_smooth_fill_solid_program);
+	SAFE_DELETE_PROGRAM(g_smooth_fill_texture2d_program);
+	SAFE_DELETE_PROGRAM(g_flat_fill_solid_shadeless_program);
+	SAFE_DELETE_PROGRAM(g_flat_fill_texture2d_shadeless_program);
+	SAFE_DELETE_PROGRAM(g_smooth_fill_solid_shadeless_program);
+	SAFE_DELETE_PROGRAM(g_smooth_fill_texture2d_shadeless_program);
+	SAFE_DELETE_PROGRAM(g_wireframe_program);
+
+#undef SAFE_DELETE_PROGRAM
 }
 
 void openSubdiv_osdGLMeshDisplayPrepare(int use_osd_glsl,
@@ -599,23 +632,32 @@ static GLuint prepare_patchDraw(OpenSubdiv_GLMesh *gl_mesh,
 
 	if (fill_quads) {
 		int model;
-		GLboolean use_texture_2d;
+		GLboolean use_texture_2d, use_lighting;
 		glGetIntegerv(GL_SHADE_MODEL, &model);
 		glGetBooleanv(GL_TEXTURE_2D, &use_texture_2d);
+		glGetBooleanv(GL_LIGHTING, &use_lighting);
 		if (model == GL_FLAT) {
 			if (use_texture_2d) {
-				program = g_flat_fill_texture2d_program;
+				program = use_lighting
+				                  ? g_flat_fill_texture2d_program
+				                  : g_flat_fill_texture2d_shadeless_program;
 			}
 			else {
-				program = g_flat_fill_solid_program;
+				program = use_lighting
+				                  ? g_flat_fill_solid_program
+				                  : g_flat_fill_solid_shadeless_program;
 			}
 		}
 		else {
 			if (use_texture_2d) {
-				program = g_smooth_fill_texture2d_program;
+				program = use_lighting
+				                  ? g_smooth_fill_texture2d_program
+				                  : g_smooth_fill_texture2d_shadeless_program;
 			}
 			else {
-				program = g_smooth_fill_solid_program;
+				program = use_lighting
+				                  ? g_smooth_fill_solid_program
+				                  : g_smooth_fill_solid_shadeless_program;
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list