[Bf-blender-cvs] [bcc0d2f] master: OpenSubdiv: Fix/workaround bad shading on AMD devices

Sergey Sharybin noreply at git.blender.org
Wed Aug 26 12:10:04 CEST 2015


Commit: bcc0d2fb1d66d5191276dcbe17621d50ae0fab35
Author: Sergey Sharybin
Date:   Wed Aug 26 12:04:25 2015 +0200
Branches: master
https://developer.blender.org/rBbcc0d2fb1d66d5191276dcbe17621d50ae0fab35

OpenSubdiv: Fix/workaround bad shading on AMD devices

Uniform block data layout was different on CPU and GPU which caused wrong
data being used from shader.

In theory using layout(std140) is what we need to do, but for some reason
such layout specifier is being ignored. This is probably caused by the way
how we exploit extensions from older version of glsl.

For until we've upgraded our glsl pipeline used different approach which
is basically about removing unused fields form the struct manual in hope
that it'll keep memory layout consistent for both CPU and GPU.

This seems to work so far for both NVidia GTX580 and AMD FirePro W8000
here in the studio.

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

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 ffc8e3d..f0f0bb7 100644
--- a/intern/opensubdiv/gpu_shader_opensubd_display.glsl
+++ b/intern/opensubdiv/gpu_shader_opensubd_display.glsl
@@ -198,15 +198,17 @@ struct LightSource {
 	vec4 diffuse;
 	vec4 specular;
 	vec4 spotDirection;
+#ifdef SUPPORT_COLOR_MATERIAL
 	float constantAttenuation;
 	float linearAttenuation;
 	float quadraticAttenuation;
 	float spotCutoff;
 	float spotExponent;
 	float spotCosCutoff;
+#endif
 };
 
-uniform Lighting {
+layout(std140) uniform Lighting {
 	LightSource lightSource[MAX_LIGHTS];
 	int num_enabled_lights;
 };
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index 7a57f50..f21a8a5 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -59,19 +59,19 @@ typedef struct Light {
 	float diffuse[4];
 	float specular[4];
 	float spot_direction[4];
+#ifdef SUPPORT_COLOR_MATERIAL
 	float constant_attenuation;
 	float linear_attenuation;
 	float quadratic_attenuation;
 	float spot_cutoff;
 	float spot_exponent;
 	float spot_cos_cutoff;
-	float pad[2];
+#endif
 } Light;
 
 typedef struct Lighting {
 	Light lights[MAX_LIGHTS];
 	int num_enabled;
-	int pad[3];
 } Lighting;
 
 typedef struct Transform {
@@ -444,6 +444,7 @@ void openSubdiv_osdGLMeshDisplayPrepare(int use_osd_glsl,
 		glGetLightfv(GL_LIGHT0 + i,
 		             GL_SPOT_DIRECTION,
 		             g_lighting_data.lights[i].spot_direction);
+#ifdef SUPPORT_COLOR_MATERIAL
 		glGetLightfv(GL_LIGHT0 + i,
 		             GL_CONSTANT_ATTENUATION,
 		             &g_lighting_data.lights[i].constant_attenuation);
@@ -461,6 +462,7 @@ void openSubdiv_osdGLMeshDisplayPrepare(int use_osd_glsl,
 		             &g_lighting_data.lights[i].spot_exponent);
 		g_lighting_data.lights[i].spot_cos_cutoff =
 			cos(g_lighting_data.lights[i].spot_cutoff);
+#endif
 	}
 }




More information about the Bf-blender-cvs mailing list