From 5a23299634ae9c01414f3ad87e16c711494fdc28 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 26 May 2014 21:14:54 +0200 Subject: [PATCH] More tidying shader code. --- examples/OpenGL/main.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index f57b661e..7e2451e1 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -103,16 +103,19 @@ int main(int argc, char *argv[]) out vec4 worldPosition; //This is being passed to the fragment shader to calculate the normals out vec3 normalFromVS; - flat out ivec2 outMaterial; + flat out ivec2 materialFromVS; void main() { - worldPosition = modelToWorldMatrix * position; - vec4 cameraPosition = worldToCameraMatrix * worldPosition; - gl_Position = cameraToClipMatrix * cameraPosition; + // Compute the usual OpenGL transformation to clip space. + gl_Position = cameraToClipMatrix * worldToCameraMatrix * modelToWorldMatrix * position; + // This example is demonstrating the marching cubes mesh, which does have per-vertex normals. We can + // just pass them through, though real code might want to deal with transforming normals appropriatly. normalFromVS = normal.xyz; - outMaterial = ivec2(material.x, material.y); + + // Nothing special here, we just pass the material through to the fragment shader. + materialFromVS = material; } )")) { @@ -125,7 +128,7 @@ int main(int argc, char *argv[]) in vec4 worldPosition; //Passed in from the vertex shader in vec3 normalFromVS; - flat in ivec2 outMaterial; + flat in ivec2 materialFromVS; out vec4 outputColor; @@ -134,7 +137,7 @@ int main(int argc, char *argv[]) // The first byte of our voxel data is the material. // We use this to decide how to color the fragment. vec4 surfaceColor; - switch(outMaterial.x) + switch(materialFromVS.x) { case 1: surfaceColor = vec4(1.0, 0.0, 0.0, 1.0);