[Bf-blender-cvs] [37a48d8] opensubdiv-modifier: OpenSubdiv: Quick tests for GLSL shaded mode

Sergey Sharybin noreply at git.blender.org
Thu Jul 17 20:11:43 CEST 2014


Commit: 37a48d82c11313273769db356599eabafba56b18
Author: Sergey Sharybin
Date:   Thu Jul 17 23:06:00 2014 +0600
https://developer.blender.org/rB37a48d82c11313273769db356599eabafba56b18

OpenSubdiv: Quick tests for GLSL shaded mode

It all seems to rather work now, apart from the UVs which are
not hooked up yet. For some reason generated coordinates doesn't
work as well, not sure about this yet,

Using sphere/tangent/etc mapping seems to give proper results,
for example http://www.pasteall.org/pic/show.php?id=74096

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

M	intern/opensubdiv/opensubdiv_gpu_capi.cc
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_material.c
M	source/blender/gpu/shaders/gpu_shader_geometry.glsl

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

diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index ca08bda..fe1e99d 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -432,7 +432,7 @@ static GLuint preapre_patchDraw(PartitionedGLMeshInterface *mesh,
 				glUniform1i(location, model == GL_FLAT);
 			}
 		}
-		return 0;
+		return program;
 	}
 
 	GLuint program = 0;
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 4453b47..535a143 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -2065,11 +2065,11 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
 				new_shademodel = (lnors || (faceFlags[index].flag & ME_SMOOTH))
 					? GL_SMOOTH
 					: GL_FLAT;
-				new_matnr = faceFlags[index].mat_nr;
+				new_matnr = faceFlags[index].mat_nr + 1;
 			}
 			else {
 				new_shademodel = GL_SMOOTH;
-				new_matnr = 0;
+				new_matnr = 1;
 			}
 
 			if (new_shademodel != shademodel) {
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index a169f6d..8dcb9db 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -606,14 +606,6 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
 	BLI_dynstr_append(ds, ";\n");
 }
 
-static char *code_generate_geometry(bool use_opensubdiv)
-{
-	if (use_opensubdiv) {
-		return datatoc_gpu_shader_geometry_glsl;
-	}
-	return NULL;
-}
-
 static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, const char *UNUSED(name))
 {
 	DynStr *ds = BLI_dynstr_new();
@@ -649,6 +641,14 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output, const ch
 	return code;
 }
 
+static char *code_generate_geometry(bool use_opensubdiv)
+{
+	if (use_opensubdiv) {
+		return datatoc_gpu_shader_geometry_glsl;
+	}
+	return NULL;
+}
+
 static char *code_generate_vertex(ListBase *nodes)
 {
 	DynStr *ds = BLI_dynstr_new();
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 5797d1d..137e2bf 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -1627,6 +1627,7 @@ GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma, bool use_open
 	/* allocate material */
 	mat = GPU_material_construct_begin(ma);
 	mat->scene = scene;
+	mat->is_opensubdiv = use_opensubdiv;
 
 	/* render pipeline option */
 	if (ma->mode & MA_TRANSP)
diff --git a/source/blender/gpu/shaders/gpu_shader_geometry.glsl b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
index 098e11a..544eca9 100644
--- a/source/blender/gpu/shaders/gpu_shader_geometry.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
@@ -1,5 +1,7 @@
-/* uniform int PrimitiveIdBase; */
-const int PrimitiveIdBase = 0;
+uniform int PrimitiveIdBase;
+
+varying vec3 varnormal;
+varying vec3 varposition;
 
 in block {
 	VertexData v;
@@ -32,6 +34,10 @@ void emit_flat(int index, vec3 normal)
 	outpt.v.position = inpt[index].v.position;
 	outpt.v.normal = normal;
 
+	/* Compatibility */
+	varnormal = outpt.v.normal;
+	varposition = outpt.v.position.xyz;
+
 	/* TODO(sergey): Only uniform subdivisions atm. */
 	vec2 quadst[4] = vec2[](vec2(0,0), vec2(1,0), vec2(1,1), vec2(0,1));
 	vec2 st = quadst[index];
@@ -47,6 +53,10 @@ void emit_smooth(int index)
 	outpt.v.position = inpt[index].v.position;
 	outpt.v.normal = inpt[index].v.normal;
 
+	/* Compatibility */
+	varnormal = outpt.v.normal;
+	varposition = outpt.v.position.xyz;
+
 	/* TODO(sergey): Only uniform subdivisions atm. */
 	vec2 quadst[4] = vec2[](vec2(0,0), vec2(1,0), vec2(1,1), vec2(0,1));
 	vec2 st = quadst[index];




More information about the Bf-blender-cvs mailing list