Browse Source

Shaders: really ported MeshVisualizer to ES.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
20fd1f7afc
  1. 13
      src/Shaders/MeshVisualizer.cpp
  2. 15
      src/Shaders/MeshVisualizer.frag
  3. 6
      src/Shaders/MeshVisualizer.vert

13
src/Shaders/MeshVisualizer.cpp

@ -36,6 +36,9 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP
#ifndef MAGNUM_TARGET_GLES
if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader))
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::geometry_shader4);
#elif defined(MAGNUM_TARGET_GLES2)
if(flags & Flag::Wireframe)
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::OES::standard_derivatives);
#endif
Utility::Resource rs("MagnumShaders");
@ -109,6 +112,16 @@ MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationP
viewportSizeUniform = uniformLocation("viewportSize");
}
}
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
#ifdef MAGNUM_TARGET_GLES
setColor(Color3<>(1.0f));
if(flags & Flag::Wireframe) {
setWireframeColor(Color3<>(0.0f));
setWireframeWidth(1.0f);
setSmoothness(2.0f);
}
#endif
}
}}

15
src/Shaders/MeshVisualizer.frag

@ -25,6 +25,7 @@
#ifndef NEW_GLSL
#define in varying
#define fragmentColor gl_FragColor
#define const
#endif
#ifndef EXPLICIT_UNIFORM_LOCATION
@ -49,15 +50,17 @@ uniform lowp float smoothness;
#endif
#ifndef NO_GEOMETRY_SHADER
noperspective in vec3 dist;
noperspective in lowp vec3 dist;
#else
in vec3 barycentric;
in lowp vec3 barycentric;
#endif
#endif
#ifdef NEW_GLSL
out vec4 fragmentColor;
#endif
#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER) && defined(GL_ES)
#if defined(WIREFRAME_RENDERING) && defined(GL_ES) && __VERSION__ < 300
#extension GL_OES_standard_derivatives : enable
#endif
@ -70,9 +73,9 @@ void main() {
/* Smooth step between face color and wireframe color based on distance */
fragmentColor = mix(wireframeColor, color, smoothstep(wireframeWidth-smoothness, wireframeWidth+smoothness, nearest));
#else
const vec3 d = fwidth(barycentric);
const vec3 factor = smoothstep(vec3(0.0), d*1.5, barycentric);
const float nearest = min(min(factor.x, factor.y), factor.z);
const lowp vec3 d = fwidth(barycentric);
const lowp vec3 factor = smoothstep(vec3(0.0), d*1.5, barycentric);
const lowp float nearest = min(min(factor.x, factor.y), factor.z);
fragmentColor = mix(wireframeColor, color, nearest);
#endif

6
src/Shaders/MeshVisualizer.vert

@ -42,7 +42,7 @@ in highp vec4 position;
#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER)
#if (!defined(GL_ES) && __VERSION__ < 140) || (defined(GL_ES) && __VERSION__ < 300)
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 1) highp in float vertexIndex;
layout(location = 1) in lowp float vertexIndex;
#else
in lowp float vertexIndex;
#endif
@ -57,6 +57,10 @@ void main() {
#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER)
barycentric = vec3(0.0);
#ifndef NEW_GLSL
barycentric[int(mod(vertexIndex, 3.0))] = 1.0;
#else
barycentric[gl_VertexID % 3] = 1.0;
#endif
#endif
}

Loading…
Cancel
Save