Hey, nearly all the compile warnings are gone!
Nice!
A single one remains that is in PolyVox\library\PolyVoxCore\include\CubicSurfaceExtractor.inl at line 34. It's about initialization order of member variables. You have to change the constructor from
Code:
:m_volData(volData)
,m_sampVolume(volData)
,m_regSizeInVoxels(region)
,m_meshCurrent(result)
to
Code:
:m_volData(volData)
,m_sampVolume(volData)
,m_meshCurrent(result)
,m_regSizeInVoxels(region)
One question I've come up with is what PolyVox regions actually do. My idea is that in Thermite you have one big volume and when you need to change it you don't regenerate the whole mesh, you just take a smaller region out of the volume and update it to reduce processing time. Is that right? The problem is the Doxygen generated help page of the region class has absolutely no description in it so I can only assume what it does... But if I want to create a "streaming" world I would be better off using multiple volumes I think as it would be easier to manage.
edit:
I'm currently trying to get the texture atlas shader to work. I've already accomplished a few things but now I'm stuck. I want to store the voxel material in the vertex colour and use this in the shader to calculate the pixels. However it seems whatever value I store in the vertex colour will be changed although my code doesn't do it. Here's part of my C++ code:
Code:
const std::vector<PolyVox::SurfaceVertex>& vVertices = mesh.getVertices();
for (unsigned int i=0; i<noVertices; i++) {
// position
const PolyVox::Vector3DFloat& pos = vVertices[i].getPosition();
PVWorld->position(pos.getX(), pos.getY(), pos.getZ());
// normal
const PolyVox::Vector3DFloat& normal = vVertices[i].getNormal();
PVWorld->normal(normal.getX(), normal.getY(), normal.getZ());
// colour/material
Ogre::ColourValue val;
uint8_t material = vVertices[i].getMaterial() + 0.5;
val.r = 0.453f;
val.g = 0.0f;
val.b = 0.0f;
val.a = 1.0f;
PVWorld->colour(val);
}
My shader code:
Code:
#define VOXELSCALE 100.0
#define VOXELCENTEROFFSET 0.5
// pixel size of tex atlas
#define TEXATLASSIZE 256
// pixel per single texture
#define TEXATLAS_TEXSIZE 16
// number of textures per row
#define TEXATLAS_NUMTEX (TEXATLASSIZE / TEXATLAS_TEXSIZE)
// size of a single texture in 0.0 - 1.0 values
#define TEXATLAS_TEXSIZE_NORMALIZED ((float)TEXATLAS_TEXSIZE / (float)TEXATLASSIZE)
void ColouredCubicVoxelVP(
float4 inPosition : POSITION,
float4 inNormal : NORMAL,
float4 inColor : COLOR,
out float4 outClipPosition : POSITION,
out float4 outWorldPosition : TEXCOORD0,
out float4 outWorldNormal : TEXCOORD1,
out float4 outColor : TEXCOORD2,
uniform float4x4 world,
uniform float4x4 viewProj
)
{
//Compute the world space position
outWorldPosition = mul(world, inPosition);
//Just pass though the normals without transforming them in any way. No rotation occurs.
outWorldNormal = inNormal;
//Compute the clip space position
outClipPosition = mul(viewProj, outWorldPosition);
outColor = inColor;
}
void ColouredCubicVoxelFP(
float4 inPosition : POSITION,
float4 inWorldPosition : TEXCOORD0,
float4 inWorldNormal : TEXCOORD1,
float4 inColor : TEXCOORD2,
uniform sampler2D texAtlas : TEXUNIT0,
out float4 result : COLOR)
{
inWorldNormal = normalize(inWorldNormal);
float3 col;
//World position is used as texture coordinates. Choose which
//two components of world position to use based on normal. Could
//optionally use a different texture for each face here as well.
float2 pos;
if(inWorldNormal. x > 0.5)
{
col = tex2D(texAtlas, (inWorldPosition.yz / VOXELSCALE) + VOXELCENTEROFFSET);
}
if(inWorldNormal. x < -0.5)
{
col = tex2D(texAtlas, (inWorldPosition.yz / VOXELSCALE) + VOXELCENTEROFFSET);
}
// top
if(inWorldNormal. y > 0.5)
{
pos = ((inWorldPosition.xz / VOXELSCALE) + VOXELCENTEROFFSET) / TEXATLAS_NUMTEX;
if ( inColor[0] == 0.453 ) {
col=0;
}
else {
col = tex2D(texAtlas, pos);
}
}
// bottom
if(inWorldNormal. y < -0.5)
{
col = tex2D(texAtlas, (inWorldPosition.xz / VOXELSCALE) + VOXELCENTEROFFSET);
}
if(inWorldNormal. z > 0.5)
{
col = tex2D(texAtlas, (inWorldPosition.xy / VOXELSCALE) + VOXELCENTEROFFSET);
}
if(inWorldNormal. z < -0.5)
{
col = tex2D(texAtlas, (inWorldPosition.xy / VOXELSCALE) + VOXELCENTEROFFSET);
}
result = float4(col, 1.0);
}
I only changed the code for the top voxel face. It checks if the incoming colour value is the same as the one I stored in the vertex. However the faces are NOT black, so the values differ...
BTW, is there a program to debug shaders? Maybe I should start looking for one