diff --git a/examples/OpenGL/Shapes.cpp b/examples/OpenGL/Shapes.cpp index 558530ba..7a66b988 100644 --- a/examples/OpenGL/Shapes.cpp +++ b/examples/OpenGL/Shapes.cpp @@ -27,7 +27,7 @@ freely, subject to the following restrictions: using namespace PolyVox; -void createSphereInVolume(LargeVolume& volData, float fRadius, uint8_t uValue) +void createSphereInVolume(LargeVolume& volData, float fRadius, uint8_t uValue) { //This vector hold the position of the center of the volume Vector3DInt32 v3dVolCenter = (volData.getEnclosingRegion().getUpperCorner() - volData.getEnclosingRegion().getLowerCorner()) / static_cast(2); @@ -48,17 +48,17 @@ void createSphereInVolume(LargeVolume& volData, float fRa //then we make it solid, otherwise we make it empty space. if(fDistToCenter <= fRadius) { - volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? MaterialDensityPair44::getMaxDensity() : MaterialDensityPair44::getMinDensity())); + volData.setVoxelAt(x,y,z, MaterialDensityPair88(uValue, uValue > 0 ? MaterialDensityPair88::getMaxDensity() : MaterialDensityPair88::getMinDensity())); } } } } } -void createCubeInVolume(LargeVolume& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue) +void createCubeInVolume(LargeVolume& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue) { - uint8_t maxDen = MaterialDensityPair44::getMaxDensity(); - uint8_t minDen = MaterialDensityPair44::getMinDensity(); + uint8_t maxDen = MaterialDensityPair88::getMaxDensity(); + uint8_t minDen = MaterialDensityPair88::getMinDensity(); //This three-level for loop iterates over every voxel between the specified corners for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++) { @@ -66,7 +66,7 @@ void createCubeInVolume(LargeVolume& volData, Vector3DInt { for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++) { - volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? maxDen : minDen)); + volData.setVoxelAt(x,y,z, MaterialDensityPair88(uValue, uValue > 0 ? maxDen : minDen)); } } } diff --git a/examples/OpenGL/Shapes.h b/examples/OpenGL/Shapes.h index 93f047fd..712558fd 100644 --- a/examples/OpenGL/Shapes.h +++ b/examples/OpenGL/Shapes.h @@ -27,7 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/LargeVolume.h" #include "PolyVoxCore/MaterialDensityPair.h" -void createSphereInVolume(PolyVox::LargeVolume& volData, float fRadius, uint8_t uValue); -void createCubeInVolume(PolyVox::LargeVolume& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue); +void createSphereInVolume(PolyVox::LargeVolume& volData, float fRadius, uint8_t uValue); +void createCubeInVolume(PolyVox::LargeVolume& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue); #endif //__OpenGLExample_Shapes_H__ \ No newline at end of file diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index b52b4860..03014c72 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -51,9 +51,9 @@ const int32_t g_uVolumeSideLength = 128; int main(int argc, char *argv[]) { - RLEBlockCompressor* compressor = new RLEBlockCompressor(); - FilePager* pager = new FilePager("./"); - LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, pager); + RLEBlockCompressor* compressor = new RLEBlockCompressor(); + FilePager* pager = new FilePager("./"); + LargeVolume volData(PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(g_uVolumeSideLength - 1, g_uVolumeSideLength - 1, g_uVolumeSideLength - 1)), compressor, pager); //Make our volume contain a sphere in the center. int32_t minPos = 0; @@ -95,6 +95,7 @@ int main(int argc, char *argv[]) in vec4 position; // This will be the position of the vertex in model-space in vec4 normal; // The normal data may not have been set + in vec2 material; uniform mat4 cameraToClipMatrix; uniform mat4 worldToCameraMatrix; @@ -102,11 +103,14 @@ int main(int argc, char *argv[]) out vec4 worldPosition; //This is being passed to the fragment shader to calculate the normals out vec4 worldNormal; + out vec2 outMaterial; void main() { + //material = vec2( worldPosition = modelToWorldMatrix * position; worldNormal = normal; + outMaterial = vec2(material.x, material.y); vec4 cameraPosition = worldToCameraMatrix * worldPosition; gl_Position = cameraToClipMatrix * cameraPosition; } @@ -121,6 +125,7 @@ int main(int argc, char *argv[]) in vec4 worldPosition; //Passed in from the vertex shader in vec4 worldNormal; + in vec2 outMaterial; out vec4 outputColor; @@ -130,7 +135,22 @@ int main(int argc, char *argv[]) vec3 normal = worldNormal.xyz; - outputColor = vec4(normalize(normal.xyz), 1.0); + if(outMaterial.x < 1.5) + { + outputColor = vec4(1.0, 0.0, 0.0, 1.0); + } + else if(outMaterial.x < 2.5) + { + outputColor = vec4(0.0, 1.0, 0.0, 1.0); + } + else if(outMaterial.x < 3.5) + { + outputColor = vec4(0.0, 0.0, 1.0, 1.0); + } + else + { + outputColor = vec4(1.0, 1.0, 0.0, 1.0); + } //float color = clamp(abs(dot(normalize(normal.xyz), vec3(0.9,0.1,0.5))), 0, 1); //outputColor = vec4(1.0, 0.5, color, 1.0); diff --git a/examples/common/OpenGLWidget.cpp b/examples/common/OpenGLWidget.cpp index 93d1a369..1777ba54 100644 --- a/examples/common/OpenGLWidget.cpp +++ b/examples/common/OpenGLWidget.cpp @@ -99,6 +99,7 @@ void OpenGLWidget::initializeGL() shader->bindAttributeLocation("position", 0); shader->bindAttributeLocation("normal", 1); + shader->bindAttributeLocation("material", 2); if (!shader->link()) { diff --git a/examples/common/OpenGLWidget.h b/examples/common/OpenGLWidget.h index eff6366a..521f239e 100644 --- a/examples/common/OpenGLWidget.h +++ b/examples/common/OpenGLWidget.h @@ -91,6 +91,9 @@ public: glEnableVertexAttribArray(1); //We're talking about shader attribute '1' glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(MeshType::VertexType), (GLvoid*)(offsetof(MeshType::VertexType, normal))); + glEnableVertexAttribArray(2); //We're talking about shader attribute '2' + glVertexAttribPointer(2, 2, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(MeshType::VertexType), (GLvoid*)(offsetof(MeshType::VertexType, material))); + glBindVertexArray(0); meshData.noOfIndices = vecIndices.size(); //Save this for the call to glDrawElements later