Changed OpenGLExample to use MaterialDensityPair88 instead of MaterialDensityPair44.

Added material to shaders.
This commit is contained in:
David Williams 2014-05-24 21:09:26 +02:00
parent aace1f2e36
commit 07b9cf05fa
5 changed files with 36 additions and 12 deletions

View File

@ -27,7 +27,7 @@ freely, subject to the following restrictions:
using namespace PolyVox;
void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRadius, uint8_t uValue)
void createSphereInVolume(LargeVolume<MaterialDensityPair88>& 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<int32_t>(2);
@ -48,17 +48,17 @@ void createSphereInVolume(LargeVolume<MaterialDensityPair44>& 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<MaterialDensityPair44>& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue)
void createCubeInVolume(LargeVolume<MaterialDensityPair88>& 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<MaterialDensityPair44>& 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));
}
}
}

View File

@ -27,7 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/LargeVolume.h"
#include "PolyVoxCore/MaterialDensityPair.h"
void createSphereInVolume(PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>& volData, float fRadius, uint8_t uValue);
void createCubeInVolume(PolyVox::LargeVolume<PolyVox::MaterialDensityPair44>& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue);
void createSphereInVolume(PolyVox::LargeVolume<PolyVox::MaterialDensityPair88>& volData, float fRadius, uint8_t uValue);
void createCubeInVolume(PolyVox::LargeVolume<PolyVox::MaterialDensityPair88>& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue);
#endif //__OpenGLExample_Shapes_H__

View File

@ -51,9 +51,9 @@ const int32_t g_uVolumeSideLength = 128;
int main(int argc, char *argv[])
{
RLEBlockCompressor<MaterialDensityPair44>* compressor = new RLEBlockCompressor<MaterialDensityPair44>();
FilePager<MaterialDensityPair44>* pager = new FilePager<MaterialDensityPair44>("./");
LargeVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, pager);
RLEBlockCompressor<MaterialDensityPair88>* compressor = new RLEBlockCompressor<MaterialDensityPair88>();
FilePager<MaterialDensityPair88>* pager = new FilePager<MaterialDensityPair88>("./");
LargeVolume<MaterialDensityPair88> 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);

View File

@ -99,6 +99,7 @@ void OpenGLWidget::initializeGL()
shader->bindAttributeLocation("position", 0);
shader->bindAttributeLocation("normal", 1);
shader->bindAttributeLocation("material", 2);
if (!shader->link())
{

View File

@ -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