[Bf-blender-cvs] [99b3d39] opensubdiv-modifier: Switch to a much more simplified shader

Sergey Sharybin noreply at git.blender.org
Wed Jul 2 19:46:54 CEST 2014


Commit: 99b3d39437a5e63d65584c6a1e52624951610829
Author: Sergey Sharybin
Date:   Wed Jul 2 17:21:00 2014 +0600
https://developer.blender.org/rB99b3d39437a5e63d65584c6a1e52624951610829

Switch to a much more simplified shader

Useful to make it a base point for making stuff working on
the Intel GPU i'm having here.

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

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 0b437ac..b71a113 100644
--- a/intern/opensubdiv/gpu_shader_opensubd_display.glsl
+++ b/intern/opensubdiv/gpu_shader_opensubd_display.glsl
@@ -22,103 +22,25 @@
 //   language governing permissions and limitations under the Apache License.
 //
 
-#if defined(VARYING_COLOR) || defined(FACEVARYING_COLOR)
-#undef OSD_USER_VARYING_DECLARE
-#define OSD_USER_VARYING_DECLARE \
-    vec3 color;
-
-#undef OSD_USER_VARYING_ATTRIBUTE_DECLARE
-#define OSD_USER_VARYING_ATTRIBUTE_DECLARE \
-    layout(location = 1) in vec3 color;
-
-#undef OSD_USER_VARYING_PER_VERTEX
-#define OSD_USER_VARYING_PER_VERTEX() \
-    outpt.color = color
-
-#undef OSD_USER_VARYING_PER_CONTROL_POINT
-#define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN) \
-    outpt[ID_OUT].color = inpt[ID_IN].color
-
-#undef OSD_USER_VARYING_PER_EVAL_POINT
-#define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d) \
-    outpt.color = \
-        mix(mix(inpt[a].color, inpt[b].color, UV.x), \
-            mix(inpt[c].color, inpt[d].color, UV.x), UV.y)
-#else
-#define OSD_USER_VARYING_DECLARE
-#define OSD_USER_VARYING_ATTRIBUTE_DECLARE
-#define OSD_USER_VARYING_PER_VERTEX()
-#define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN)
-#define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d)
-#endif
-
-//--------------------------------------------------------------
-// Uniforms / Uniform Blocks
-//--------------------------------------------------------------
-
-layout(std140) uniform Transform {
-    mat4 ModelViewMatrix;
-    mat4 ProjectionMatrix;
-    mat4 ModelViewProjectionMatrix;
-};
-
-layout(std140) uniform Tessellation {
-    float TessLevel;
-};
-
-uniform int GregoryQuadOffsetBase;
-uniform int PrimitiveIdBase;
-
-//--------------------------------------------------------------
-// Osd external functions
-//--------------------------------------------------------------
-
-mat4 OsdModelViewMatrix()
-{
-    return ModelViewMatrix;
-}
-mat4 OsdProjectionMatrix()
-{
-    return ProjectionMatrix;
-}
-mat4 OsdModelViewProjectionMatrix()
-{
-    return ModelViewProjectionMatrix;
-}
-float OsdTessLevel()
-{
-    return TessLevel;
-}
-int OsdGregoryQuadOffsetBase()
-{
-    return GregoryQuadOffsetBase;
-}
-int OsdPrimitiveIdBase()
-{
-    return PrimitiveIdBase;
-}
-int OsdBaseVertex()
-{
-    return 0;
-}
+//#version 330
 
 //--------------------------------------------------------------
 // Vertex Shader
 //--------------------------------------------------------------
 #ifdef VERTEX_SHADER
 
-layout (location=0) in vec4 position;
-OSD_USER_VARYING_ATTRIBUTE_DECLARE
+layout (location=0) in vec3 position;
+layout (location=1) in vec3 normal;
 
-out block {
-    OutputVertex v;
-    OSD_USER_VARYING_DECLARE
-} outpt;
+out vec3 vPosition;
+out vec3 vNormal;
+out vec4 vColor;
 
 void main()
 {
-    outpt.v.position = ModelViewMatrix * position;
-    OSD_USER_VARYING_PER_VERTEX();
+    vPosition = position;
+    vNormal = normal;
+    vColor = vec4(1, 1, 1, 1);
 }
 
 #endif
@@ -130,157 +52,89 @@ void main()
 
 #ifdef PRIM_QUAD
 
-    layout(lines_adjacency) in;
-
-    #define EDGE_VERTS 4
-
-#endif // PRIM_QUAD
-
-#ifdef  PRIM_TRI
-
-    layout(triangles) in;
+layout(lines_adjacency) in;
 
-    #define EDGE_VERTS 3
+#ifdef GEOMETRY_OUT_FILL
+layout(triangle_strip, max_vertices = 4) out;
+#endif
 
-#endif // PRIM_TRI
+#ifdef GEOMETRY_OUT_LINE
+layout(line_strip, max_vertices = 5) out;
+#endif
 
+in vec3 vPosition[4];
+in vec3 vNormal[4];
 
-layout(triangle_strip, max_vertices = EDGE_VERTS) out;
-in block {
-    OutputVertex v;
-    OSD_USER_VARYING_DECLARE
-} inpt[EDGE_VERTS];
+#else // PRIM_TRI
 
-out block {
-    OutputVertex v;
-    noperspective out vec4 edgeDistance;
-    OSD_USER_VARYING_DECLARE
-} outpt;
+layout(triangles) in;
 
-void emit(int index, vec3 normal)
-{
-    outpt.v.position = inpt[index].v.position;
-#ifdef SMOOTH_NORMALS
-    outpt.v.normal = inpt[index].v.normal;
-#else
-    outpt.v.normal = normal;
+#ifdef GEOMETRY_OUT_FILL
+layout(triangle_strip, max_vertices = 3) out;
 #endif
 
-#ifdef VARYING_COLOR
-    outpt.color = inpt[index].color;
+#ifdef GEOMETRY_OUT_LINE
+layout(line_strip, max_vertices = 4) out;
 #endif
 
-#ifdef FACEVARYING_COLOR
-#ifdef LOOP  // ----- scheme : LOOP
-    vec2 uv;
-    OSD_COMPUTE_FACE_VARYING_TRI_2(uv, /*fvarOffste=*/0, index);
+in vec3 vPosition[3];
+in vec3 vNormal[3];
 
-#else        // ----- scheme : CATMARK / BILINEAR
-
-#ifdef UNIFORM_SUBDIVISION
-    vec2 quadst[4] = vec2[](vec2(0,0), vec2(1,0), vec2(1,1), vec2(0,1));
-    vec2 st = quadst[index];
-#else
-    vec2 st = inpt[index].v.tessCoord;
-#endif
-    vec2 uv;
-    OSD_COMPUTE_FACE_VARYING_2(uv, /*fvarOffset=*/0, st);
-#endif      // ------ scheme
-    outpt.color = vec3(uv.s, uv.t, 0);
-#endif
+#endif // PRIM_TRI/QUAD
 
-    gl_Position = ProjectionMatrix * inpt[index].v.position;
-    EmitVertex();
-}
 
-#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
-const float VIEWPORT_SCALE = 1024.0; // XXXdyu
+uniform mat4 objectToClipMatrix;
+uniform mat4 objectToEyeMatrix;
 
-float edgeDistance(vec4 p, vec4 p0, vec4 p1)
-{
-    return VIEWPORT_SCALE *
-        abs((p.x - p0.x) * (p1.y - p0.y) -
-            (p.y - p0.y) * (p1.x - p0.x)) / length(p1.xy - p0.xy);
-}
+flat out vec3 gFacetNormal;
+out vec3 Peye;
+out vec3 Neye;
+out vec4 Cout;
 
-void emit(int index, vec3 normal, vec4 edgeVerts[EDGE_VERTS])
+void emit(int index)
 {
-    outpt.edgeDistance[0] =
-        edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]);
-    outpt.edgeDistance[1] =
-        edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]);
-#ifdef PRIM_TRI
-    outpt.edgeDistance[2] =
-        edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]);
-#endif
-#ifdef PRIM_QUAD
-    outpt.edgeDistance[2] =
-        edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]);
-    outpt.edgeDistance[3] =
-        edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]);
-#endif
-
-    emit(index, normal);
+    Peye = vPosition[index];
+    gl_Position = objectToClipMatrix * vec4(vPosition[index], 1);
+    Neye = (objectToEyeMatrix * vec4(vNormal[index], 0)).xyz;
+    EmitVertex();
 }
-#endif
 
 void main()
 {
     gl_PrimitiveID = gl_PrimitiveIDIn;
-
+    
 #ifdef PRIM_QUAD
-    vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz;
-    vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz;
-    vec3 C = (inpt[2].v.position - inpt[1].v.position).xyz;
-    vec3 n0 = normalize(cross(B, A));
-
-#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
-    vec4 edgeVerts[EDGE_VERTS];
-    edgeVerts[0] = ProjectionMatrix * inpt[0].v.position;
-    edgeVerts[1] = ProjectionMatrix * inpt[1].v.position;
-    edgeVerts[2] = ProjectionMatrix * inpt[2].v.position;
-    edgeVerts[3] = ProjectionMatrix * inpt[3].v.position;
-
-    edgeVerts[0].xy /= edgeVerts[0].w;
-    edgeVerts[1].xy /= edgeVerts[1].w;
-    edgeVerts[2].xy /= edgeVerts[2].w;
-    edgeVerts[3].xy /= edgeVerts[3].w;
-
-    emit(0, n0, edgeVerts);
-    emit(1, n0, edgeVerts);
-    emit(3, n0, edgeVerts);
-    emit(2, n0, edgeVerts);
-#else
-    emit(0, n0);
-    emit(1, n0);
-    emit(3, n0);
-    emit(2, n0);
+#ifdef GEOMETRY_OUT_FILL
+    vec3 A = vPosition[0] - vPosition[1];
+    vec3 B = vPosition[3] - vPosition[1];
+    vec3 C = vPosition[2] - vPosition[1];
+
+    gFacetNormal = (objectToEyeMatrix*vec4(normalize(cross(B, A)), 0)).xyz;
+    emit(0);
+    emit(1);
+    emit(3);
+//    gFacetNormal = (objectToEyeMatrix*vec4(normalize(cross(C, B)), 0)).xyz;
+    emit(2);
+#else  // GEOMETRY_OUT_LINE
+    emit(0);
+    emit(1);
+    emit(2);
+    emit(3);
+    emit(0);
 #endif
 #endif // PRIM_QUAD
 
 #ifdef PRIM_TRI
-    vec3 A = (inpt[1].v.position - inpt[0].v.position).xyz;
-    vec3 B = (inpt[2].v.position - inpt[0].v.position).xyz;
-    vec3 n0 = normalize(cross(B, A));
-
-#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
-    vec4 edgeVerts[EDGE_VERTS];
-    edgeVerts[0] = ProjectionMatrix * inpt[0].v.position;
-    edgeVerts[1] = ProjectionMatrix * inpt[1].v.position;
-    edgeVerts[2] = ProjectionMatrix * inpt[2].v.position;
-
-    edgeVerts[0].xy /= edgeVerts[0].w;
-    edgeVerts[1].xy /= edgeVerts[1].w;
-    edgeVerts[2].xy /= edgeVerts[2].w;
-
-    emit(0, n0, edgeVerts);
-    emit(1, n0, edgeVerts);
-    emit(2, n0, edgeVerts);
-#else
-    emit(0, n0);
-    emit(1, n0);
-    emit(2, n0);
-#endif
+    vec3 A = vPosition[1] - vPosition[0];
+    vec3 B = vPosition[2] - vPosition[0];
+    gFacetNormal = (objectToEyeMatrix*vec4(normalize(cross(B, A)), 0)).xyz;
+
+    emit(0);
+    emit(1);
+    emit(2);
+#ifdef GEOMETRY_OUT_LINE
+    emit(0);
+#endif //GEOMETRY_OUT_LINE
 #endif // PRIM_TRI
 
     EndPrimitive();
@@ -293,13 +147,11 @@ void main()
 //--------------------------------------------------------------
 #ifdef FRAGMENT_SHADER
 
-in block {
-    OutputVertex v;
-    noperspective in vec4 edgeDistance;
-    OSD_USER_VARYING_DECLARE
-} inpt;
-
-out vec4 outColor;
+layout (location=0) out vec4 FragColor;
+flat in vec3 gFacetNormal;
+in vec3 Neye;
+in vec3 Peye;
+in vec4 Cout;
 
 #define NUM_LIGHTS 2
 
@@ -310,17 +162,13 @@ struct LightSource {
     vec4 specular;
 };
 
-layout(std140) uniform Lighting {
-    LightSource lightSource[NUM_LIGHTS];
-};
-
-uniform vec4 diffuseColor = vec4(1);
-uniform vec4 ambientColor = vec4(1);
+uniform LightSource lightSource[NUM_LIGHTS];
 
 vec4
-lighting(vec4 diffuse, vec3 Peye, vec3 Neye)
+lighting(vec3 Peye, vec3 Neye)
 {
     vec4 color = vec4(0);
+    vec4 material = vec4(0.4, 0.4, 0.8, 1);
 
     for (int i = 0; i < NUM_LIGHTS; ++i) {
 
@@ -335,8 +183,8 @@ lighting(vec4 diffuse, vec3 Peye, vec3 Neye)
         float d = max(0.0, dot(n, l));
         float s = pow(max(0.0, dot(n, h)), 500.0f);
 
-        color += lightSource[i].ambient * ambientColor
-            + d * lightSource[i].diffuse * diffuse
+        color += lightSource[i].ambient * material
+            + d * lightSource[i].diffuse * material
             + s * lightSource[i].specular;
     }
 
@@ -344,55 +192,22 @@ lighting(vec4 diffuse, vec3 Peye, vec3 Neye)
     return color;
 }
 
-vec4
-edgeColor(vec

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list