Browse Source

Shaders: more shader code cleanup.

Fixed random potential GLSL ES issues, reduced preprocessor madness.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
8c2eaea406
  1. 17
      src/Magnum/Shaders/AbstractVector2D.vert
  2. 17
      src/Magnum/Shaders/AbstractVector3D.vert
  3. 40
      src/Magnum/Shaders/DistanceFieldVector.frag
  4. 16
      src/Magnum/Shaders/Flat2D.vert
  5. 16
      src/Magnum/Shaders/Flat3D.vert
  6. 44
      src/Magnum/Shaders/MeshVisualizer.frag
  7. 5
      src/Magnum/Shaders/MeshVisualizer.geom
  8. 15
      src/Magnum/Shaders/MeshVisualizer.vert
  9. 36
      src/Magnum/Shaders/Phong.vert
  10. 15
      src/Magnum/Shaders/Vector.frag
  11. 23
      src/Magnum/Shaders/VertexColor2D.vert

17
src/Magnum/Shaders/AbstractVector2D.vert

@ -29,20 +29,21 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat3 transformationProjectionMatrix;
#else
uniform highp mat3 transformationProjectionMatrix;
layout(location = 0)
#endif
uniform highp mat3 transformationProjectionMatrix;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec2 position;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoordinates;
#else
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec2 position;
in mediump vec2 textureCoordinates;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
out vec2 fragmentTextureCoordinates;
out mediump vec2 fragmentTextureCoordinates;
void main() {
gl_Position.xywz = vec4(transformationProjectionMatrix*vec3(position, 1.0), 0.0);

17
src/Magnum/Shaders/AbstractVector3D.vert

@ -29,20 +29,21 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat4 transformationProjectionMatrix;
#else
uniform highp mat4 transformationProjectionMatrix;
layout(location = 0)
#endif
uniform highp mat4 transformationProjectionMatrix;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoordinates;
#else
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec4 position;
in mediump vec2 textureCoordinates;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
out vec2 fragmentTextureCoordinates;
out mediump vec2 fragmentTextureCoordinates;
void main() {
gl_Position = transformationProjectionMatrix*position;

40
src/Magnum/Shaders/DistanceFieldVector.frag

@ -29,30 +29,38 @@
#define texture texture2D
#endif
#ifndef GL_ES
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1) uniform lowp vec4 color;
layout(location = 2) uniform lowp vec4 outlineColor;
layout(location = 3) uniform lowp vec2 outlineRange = vec2(0.5, 1.0);
layout(location = 4) uniform lowp float smoothness = 0.04;
#else
uniform lowp vec4 color;
uniform lowp vec4 outlineColor;
uniform lowp vec2 outlineRange = vec2(0.5, 1.0);
uniform lowp float smoothness = 0.04;
layout(location = 1)
#endif
#else
uniform lowp vec4 color;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 2)
#endif
uniform lowp vec4 outlineColor;
uniform lowp vec2 outlineRange;
uniform lowp float smoothness;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 3)
#endif
uniform lowp vec2 outlineRange
#ifndef GL_ES
= vec2(0.5, 1.0)
#endif
;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 4)
#endif
uniform lowp float smoothness
#ifndef GL_ES
= 0.04
#endif
;
#ifdef EXPLICIT_TEXTURE_LAYER
layout(binding = 15) uniform sampler2D vectorTexture;
#else
uniform lowp sampler2D vectorTexture;
layout(binding = 15)
#endif
uniform lowp sampler2D vectorTexture;
in mediump vec2 fragmentTextureCoordinates;

16
src/Magnum/Shaders/Flat2D.vert

@ -29,23 +29,21 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat3 transformationProjectionMatrix;
#else
uniform highp mat3 transformationProjectionMatrix;
layout(location = 0)
#endif
uniform highp mat3 transformationProjectionMatrix;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec2 position;
#else
in highp vec2 position;
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec2 position;
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoordinates;
#else
in mediump vec2 textureCoordinates;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
out mediump vec2 interpolatedTextureCoordinates;
#endif

16
src/Magnum/Shaders/Flat3D.vert

@ -29,23 +29,21 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat4 transformationProjectionMatrix;
#else
uniform highp mat4 transformationProjectionMatrix;
layout(location = 0)
#endif
uniform highp mat4 transformationProjectionMatrix;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
#else
in highp vec4 position;
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec4 position;
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoordinates;
#else
in mediump vec2 textureCoordinates;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
out mediump vec2 interpolatedTextureCoordinates;
#endif

44
src/Magnum/Shaders/MeshVisualizer.frag

@ -44,22 +44,42 @@
#extension GL_NV_shader_noperspective_interpolation: require
#endif
#ifndef GL_ES
layout(location = 2) uniform vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
#else
uniform lowp vec4 color;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 2)
#endif
uniform lowp vec4 color
#ifndef GL_ES
= vec4(1.0, 1.0, 1.0, 1.0)
#endif
;
#ifdef WIREFRAME_RENDERING
#ifndef GL_ES
layout(location = 3) uniform vec4 wireframeColor = vec4(0.0, 0.0, 0.0, 1.0);
layout(location = 4) uniform float wireframeWidth = 1.0;
layout(location = 5) uniform float smoothness = 2.0;
#else
uniform lowp vec4 wireframeColor;
uniform lowp float wireframeWidth;
uniform lowp float smoothness;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 3)
#endif
uniform lowp vec4 wireframeColor
#ifndef GL_ES
= vec4(0.0, 0.0, 0.0, 1.0)
#endif
;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 4)
#endif
uniform lowp float wireframeWidth
#ifndef GL_ES
= 1.0
#endif
;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 5)
#endif
uniform lowp float smoothness
#ifndef GL_ES
= 2.0
#endif
;
#ifndef NO_GEOMETRY_SHADER
#ifdef GL_NV_shader_noperspective_interpolation

5
src/Magnum/Shaders/MeshVisualizer.geom

@ -35,10 +35,9 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1) uniform vec2 viewportSize;
#else
uniform vec2 viewportSize;
layout(location = 1)
#endif
uniform lowp vec2 viewportSize;
layout(triangles) in;

15
src/Magnum/Shaders/MeshVisualizer.vert

@ -29,24 +29,21 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat4 transformationProjectionMatrix;
#else
uniform highp mat4 transformationProjectionMatrix;
layout(location = 0)
#endif
uniform highp mat4 transformationProjectionMatrix;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
#else
in highp vec4 position;
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
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 = 3) in lowp float vertexIndex;
#else
in lowp float vertexIndex;
layout(location = 3)
#endif
in lowp float vertexIndex;
#define gl_VertexID int(vertexIndex)
#endif

36
src/Magnum/Shaders/Phong.vert

@ -29,31 +29,41 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat4 transformationMatrix;
layout(location = 1) uniform mat4 projectionMatrix;
layout(location = 2) uniform mat3 normalMatrix;
layout(location = 3) uniform vec3 light;
#else
layout(location = 0)
#endif
uniform highp mat4 transformationMatrix;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1)
#endif
uniform highp mat4 projectionMatrix;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 2)
#endif
uniform mediump mat3 normalMatrix;
uniform highp vec3 light;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 3)
#endif
uniform highp vec3 light;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec4 position;
layout(location = NORMAL_ATTRIBUTE_LOCATION) in mediump vec3 normal;
#else
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec4 position;
in mediump vec3 normal;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = NORMAL_ATTRIBUTE_LOCATION)
#endif
in mediump vec3 normal;
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION) in mediump vec2 textureCoords;
#else
in mediump vec2 textureCoords;
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoords;
out mediump vec2 interpolatedTextureCoords;
#endif

15
src/Magnum/Shaders/Vector.frag

@ -30,18 +30,19 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1) uniform vec4 backgroundColor;
layout(location = 2) uniform vec4 color;
#else
layout(location = 1)
#endif
uniform lowp vec4 backgroundColor;
uniform lowp vec4 color;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 2)
#endif
uniform lowp vec4 color;
#ifdef EXPLICIT_TEXTURE_LAYER
layout(binding = 15) uniform sampler2D vectorTexture;
#else
uniform lowp sampler2D vectorTexture;
layout(binding = 15)
#endif
uniform lowp sampler2D vectorTexture;
in mediump vec2 fragmentTextureCoordinates;

23
src/Magnum/Shaders/VertexColor2D.vert

@ -28,23 +28,24 @@
#define out varying
#endif
#ifndef GL_ES
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 0) uniform mat3 transformationProjectionMatrix = mat3(1.0);
#else
uniform mat3 transformationProjectionMatrix = mat3(1.0);
#endif
#else
uniform highp mat3 transformationProjectionMatrix;
layout(location = 0)
#endif
uniform highp mat3 transformationProjectionMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = POSITION_ATTRIBUTE_LOCATION) in highp vec2 position;
layout(location = 3) in lowp vec3 color;
#else
layout(location = POSITION_ATTRIBUTE_LOCATION)
#endif
in highp vec2 position;
in lowp vec3 color;
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 3)
#endif
in lowp vec3 color;
out lowp vec3 interpolatedColor;

Loading…
Cancel
Save