pass voxel dimensions from PolyVoxEntityItem to pixel-shader so that the textures line up with the edges

This commit is contained in:
Seth Alves 2015-08-07 14:21:20 -07:00
parent 0a5ed0eb9b
commit 732f9ceca5
2 changed files with 11 additions and 16 deletions

View file

@ -676,17 +676,6 @@ void RenderablePolyVoxEntityItem::getModel() {
sizeof(PolyVox::PositionMaterialNormal),
gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)));
// mesh->addAttribute(gpu::Stream::TEXCOORD,
// gpu::BufferView(vertexBufferPtr,
// sizeof(float) * 2,
// vertexBufferPtr->getSize() - sizeof(float) * 2,
// sizeof(PolyVox::PositionMaterialNormal),
// gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::RAW)));
#ifdef WANT_DEBUG
qDebug() << "---- vecIndices.size() =" << vecIndices.size();
qDebug() << "---- vecVertices.size() =" << vecVertices.size();
@ -709,8 +698,6 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
slotBindings.insert(gpu::Shader::Binding(std::string("xMap"), 0));
slotBindings.insert(gpu::Shader::Binding(std::string("yMap"), 1));
slotBindings.insert(gpu::Shader::Binding(std::string("zMap"), 2));
slotBindings.insert(gpu::Shader::Binding(std::string("polyVoxDimensions"), 3));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vertexShader, pixelShader));
gpu::Shader::makeProgram(*program, slotBindings);
@ -768,6 +755,9 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) {
batch.setResourceTexture(2, DependencyManager::get<TextureCache>()->getWhiteTexture());
}
int voxelVolumeSizeLocation = _pipeline->getProgram()->getUniforms().findLocation("voxelVolumeSize");
batch._glUniform3f(voxelVolumeSizeLocation, _voxelVolumeSize.x, _voxelVolumeSize.y, _voxelVolumeSize.z);
batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0);
RenderableDebugableEntityItem::render(this, args);

View file

@ -26,14 +26,19 @@ in vec4 _inPosition;
uniform sampler2D xMap;
uniform sampler2D yMap;
uniform sampler2D zMap;
uniform vec3 voxelVolumeSize;
void main(void) {
vec3 worldNormal = cross(dFdy(_inPosition.xyz), dFdx(_inPosition.xyz));
worldNormal = normalize(worldNormal);
vec4 xyDiffuse = texture2D(xMap, (_inPosition.xy - vec2(0.5)) / -8.0);
vec4 xzDiffuse = texture2D(yMap, (_inPosition.xz - vec2(0.5)) / -8.0);
vec4 yzDiffuse = texture2D(zMap, (_inPosition.yz - vec2(0.5)) / -8.0);
float inPositionX = (_inPosition.x - 0.5) / voxelVolumeSize.x;
float inPositionY = (_inPosition.y - 0.5) / voxelVolumeSize.y;
float inPositionZ = (_inPosition.z - 0.5) / voxelVolumeSize.z;
vec4 xyDiffuse = texture2D(xMap, vec2(-inPositionX, -inPositionY));
vec4 xzDiffuse = texture2D(yMap, vec2(-inPositionX, inPositionZ));
vec4 yzDiffuse = texture2D(zMap, vec2(inPositionZ, -inPositionY));
vec3 xyDiffuseScaled = xyDiffuse.rgb * abs(worldNormal.z);
vec3 xzDiffuseScaled = xzDiffuse.rgb * abs(worldNormal.y);