diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-08-18 14:05:47 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-08-19 08:12:06 +0300 |
commit | cf95478ea842cd42a8888b0b74de3d0d0d0233ea (patch) | |
tree | 689e38c48cf39ab3907ef46015f8bf26c4040d16 /src/datavisualization/engine | |
parent | 169a4d638c6c1b6634ffcfd19c4fe3cb94cf27d5 (diff) |
Make volume shading sample once per texture layer.
Change-Id: Ia3a13e2cb8d7dcf744a55dcb827f5cb436a043c4
Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/engine')
-rw-r--r-- | src/datavisualization/engine/abstract3drenderer.cpp | 12 | ||||
-rw-r--r-- | src/datavisualization/engine/shaders/texture3d.frag | 24 |
2 files changed, 30 insertions, 6 deletions
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp index cbb90af0..8eb1d2ce 100644 --- a/src/datavisualization/engine/abstract3drenderer.cpp +++ b/src/datavisualization/engine/abstract3drenderer.cpp @@ -1300,6 +1300,18 @@ void Abstract3DRenderer::drawCustomItems(RenderingState state, (float(item->sliceIndexZ()) + 0.5f) / float(item->textureDepth()) * 2.0 - 1.0); shader->setUniformValue(shader->volumeSliceIndices(), slices); + } else { + // Precalculate texture dimensions so we can optimize + // ray stepping to hit every texture layer. + QVector3D textureDimensions(float(item->textureWidth()), + float(item->textureHeight()), + float(item->textureDepth())); + shader->setUniformValue(shader->textureDimensions(), textureDimensions); + + int sampleCount = qMax(item->textureWidth(), item->textureHeight()); + sampleCount = qMax(sampleCount, item->textureDepth()); + shader->setUniformValue(shader->sampleCount(), sampleCount); + } m_drawer->drawObject(shader, item->mesh(), 0, 0, item->texture()); } else diff --git a/src/datavisualization/engine/shaders/texture3d.frag b/src/datavisualization/engine/shaders/texture3d.frag index 054b59cb..b9d87fcc 100644 --- a/src/datavisualization/engine/shaders/texture3d.frag +++ b/src/datavisualization/engine/shaders/texture3d.frag @@ -6,10 +6,11 @@ uniform highp sampler3D textureSampler; uniform highp vec3 cameraPositionRelativeToModel; uniform highp vec4 colorIndex[256]; uniform highp int color8Bit; +uniform highp vec3 textureDimensions; +uniform highp int sampleCount; // This is the maximum sample count -const float maxDist = sqrt(2.0); -const int sampleCount = 1024; const float alphaThreshold = 0.001; + void main() { // Raytrace into volume, need to sample pixels along the eye ray until we hit opacity 1 @@ -35,10 +36,21 @@ void main() { rayStart = 0.5 * (rayStart + 1.0); rayStop = 0.5 * (rayStop + 1.0); - highp vec3 curPos = rayStart; - highp float fullDist = distance(rayStop, rayStart); - highp float stepSize = maxDist / float(sampleCount); // TODO: Stepsize needs to be improved - highp vec3 step = normalize(rayStop - rayStart) * stepSize; + highp vec3 ray = rayStop - rayStart; + highp float fullDist = length(ray); + highp float rayX = abs(ray.x) * textureDimensions.x; + highp float rayY = abs(ray.y) * textureDimensions.y; + highp float rayZ = abs(ray.z) * textureDimensions.z; + + highp float maxRayDim = max(rayX, rayY); + maxRayDim = max(maxRayDim, rayZ); + + highp vec3 step = ray / maxRayDim; + highp float stepSize = abs(fullDist / maxRayDim); + + // Offset a fraction of a step so we are not exactly on a texel boundary. + highp vec3 curPos = rayStart - (0.5 * step); + highp float totalDist = 0.0; highp float totalAlpha = 0.0; highp vec4 destColor = vec4(0, 0, 0, 0); |