Commit 584e1d60 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] some improvements in the colormapping shader

parent 1dee2321
......@@ -39,15 +39,46 @@
* \param color this color gets mixed using alpha value with the new colormap color
* \param sampler the texture sampler to use
* \param coord the coordinate where to get the value
* \param size the size in voxels
* \param minV the minimum of the original value
* \param scaleV the scaler used to downscale the original value to [0-1]
* \param thresholdV a threshold in original space (you need to downscale it to [0-1] if you want to use it to scaled values.
* \param alpha the alpha blending value
* \param cmap the colormap index to use
*/
void colormap( inout vec4 color, in sampler3D sampler, in vec3 coord, float minV, float scaleV, float thresholdV, bool thresholdEnabled, float alpha,
void colormap( inout vec4 color, in sampler3D sampler, in vec3 coord, in vec3 size, float minV, float scaleV, float thresholdV, bool thresholdEnabled, float alpha,
int cmap, bool active )
{
// This implements a manual trilinear interpolation. Include WGETextureutils.glsl to use this
// vec3 vSize = vec3( 1.0 / float( size.x ),
// 1.0 / float( size.y ),
// 1.0 / float( size.z ) );
//
// vec3 discreteCoord = getDiscreteVoxelCoordinate( vSize, coord );
// vec3 voxelSpace = coord / vSize;
// vec3 coordDiff = voxelSpace - vec3( floor( voxelSpace.x ), floor( voxelSpace.y ), floor( voxelSpace.z ) );
//
// vec3 c000 = getNeighbourVoxel( vSize, coord, vec3( 0.0, 0.0, 0.0 ) );
// vec3 c010 = getNeighbourVoxel( vSize, coord, vec3( 0.0, 1.0, 0.0 ) );
// vec3 c001 = getNeighbourVoxel( vSize, coord, vec3( 0.0, 0.0, 1.0 ) );
// vec3 c011 = getNeighbourVoxel( vSize, coord, vec3( 0.0, 1.0, 1.0 ) );
// vec3 c100 = getNeighbourVoxel( vSize, coord, vec3( 1.0, 0.0, 0.0 ) );
// vec3 c110 = getNeighbourVoxel( vSize, coord, vec3( 1.0, 1.0, 0.0 ) );
// vec3 c101 = getNeighbourVoxel( vSize, coord, vec3( 1.0, 0.0, 1.0 ) );
// vec3 c111 = getNeighbourVoxel( vSize, coord, vec3( 1.0, 1.0, 1.0 ) );
//
// vec4 v00 = mix( colormap( texture3D( sampler, c000 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c100 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
// vec4 v10 = mix( colormap( texture3D( sampler, c010 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c110 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
// vec4 v01 = mix( colormap( texture3D( sampler, c001 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c101 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
// vec4 v11 = mix( colormap( texture3D( sampler, c011 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ),
// colormap( texture3D( sampler, c111 ).rgba, minV, scaleV, thresholdV, thresholdEnabled, alpha, cmap, active ), coordDiff.x );
//
// vec4 src = mix( mix( v00, v10, coordDiff.y ),
// mix( v01, v11, coordDiff.y ), coordDiff.z );
// get the value and descale it
vec4 value = texture3D( sampler, coord ).rgba;
......@@ -81,41 +112,49 @@ vec4 colormapping( vec4 texcoord )
// back to front compositing
#ifdef Colormap7Enabled
colormap( finalColor, u_colormap7Sampler, ( gl_TextureMatrix[ Colormap7Unit ] * t ).xyz,
vec3( u_colormap7SizeX, u_colormap7SizeY, u_colormap7SizeZ ),
u_colormap7Min, u_colormap7Scale, u_colormap7Threshold, u_colormap7ThresholdEnabled,
u_colormap7Alpha, u_colormap7Colormap, u_colormap7Active );
#endif
#ifdef Colormap6Enabled
colormap( finalColor, u_colormap6Sampler, ( gl_TextureMatrix[ Colormap6Unit ] * t ).xyz,
vec3( u_colormap6SizeX, u_colormap6SizeY, u_colormap6SizeZ ),
u_colormap6Min, u_colormap6Scale, u_colormap6Threshold, u_colormap6ThresholdEnabled,
u_colormap6Alpha, u_colormap6Colormap, u_colormap6Active );
#endif
#ifdef Colormap5Enabled
colormap( finalColor, u_colormap5Sampler, ( gl_TextureMatrix[ Colormap5Unit ] * t ).xyz,
vec3( u_colormap5SizeX, u_colormap5SizeY, u_colormap5SizeZ ),
u_colormap5Min, u_colormap5Scale, u_colormap5Threshold, u_colormap5ThresholdEnabled,
u_colormap5Alpha, u_colormap5Colormap, u_colormap5Active );
#endif
#ifdef Colormap4Enabled
colormap( finalColor, u_colormap4Sampler, ( gl_TextureMatrix[ Colormap4Unit ] * t ).xyz,
vec3( u_colormap4SizeX, u_colormap4SizeY, u_colormap4SizeZ ),
u_colormap4Min, u_colormap4Scale, u_colormap4Threshold, u_colormap4ThresholdEnabled,
u_colormap4Alpha, u_colormap4Colormap, u_colormap4Active );
#endif
#ifdef Colormap3Enabled
colormap( finalColor, u_colormap3Sampler, ( gl_TextureMatrix[ Colormap3Unit ] * t ).xyz,
vec3( u_colormap3SizeX, u_colormap3SizeY, u_colormap3SizeZ ),
u_colormap3Min, u_colormap3Scale, u_colormap3Threshold, u_colormap3ThresholdEnabled,
u_colormap3Alpha, u_colormap3Colormap, u_colormap3Active );
#endif
#ifdef Colormap2Enabled
colormap( finalColor, u_colormap2Sampler, ( gl_TextureMatrix[ Colormap2Unit ] * t ).xyz,
vec3( u_colormap2SizeX, u_colormap2SizeY, u_colormap2SizeZ ),
u_colormap2Min, u_colormap2Scale, u_colormap2Threshold, u_colormap2ThresholdEnabled,
u_colormap2Alpha, u_colormap2Colormap, u_colormap2Active );
#endif
#ifdef Colormap1Enabled
colormap( finalColor, u_colormap1Sampler, ( gl_TextureMatrix[ Colormap1Unit ] * t ).xyz,
vec3( u_colormap1SizeX, u_colormap1SizeY, u_colormap1SizeZ ),
u_colormap1Min, u_colormap1Scale, u_colormap1Threshold, u_colormap1ThresholdEnabled,
u_colormap1Alpha, u_colormap1Colormap, u_colormap1Active );
#endif
#ifdef Colormap0Enabled
colormap( finalColor, u_colormap0Sampler, ( gl_TextureMatrix[ Colormap0Unit ] * t ).xyz,
vec3( u_colormap0SizeX, u_colormap0SizeY, u_colormap0SizeZ ),
u_colormap0Min, u_colormap0Scale, u_colormap0Threshold, u_colormap0ThresholdEnabled,
u_colormap0Alpha, u_colormap0Colormap, u_colormap0Active );
#endif
......@@ -137,36 +176,52 @@ vec4 colormapping()
// back to front compositing
#ifdef Colormap7Enabled
colormap( finalColor, u_colormap7Sampler, v_colormap7TexCoord.xyz, u_colormap7Min, u_colormap7Scale, u_colormap7Threshold,
u_colormap7ThresholdEnabled, u_colormap7Alpha, u_colormap7Colormap, u_colormap7Active );
colormap( finalColor, u_colormap7Sampler, v_colormap7TexCoord.xyz,
vec3( u_colormap7SizeX, u_colormap7SizeY, u_colormap7SizeZ ),
u_colormap7Min, u_colormap7Scale, u_colormap7Threshold,
u_colormap7ThresholdEnabled, u_colormap7Alpha, u_colormap7Colormap, u_colormap7Active );
#endif
#ifdef Colormap6Enabled
colormap( finalColor, u_colormap6Sampler, v_colormap6TexCoord.xyz, u_colormap6Min, u_colormap6Scale, u_colormap6Threshold,
u_colormap6ThresholdEnabled, u_colormap6Alpha, u_colormap6Colormap, u_colormap6Active );
colormap( finalColor, u_colormap6Sampler, v_colormap6TexCoord.xyz,
vec3( u_colormap6SizeX, u_colormap6SizeY, u_colormap6SizeZ ),
u_colormap6Min, u_colormap6Scale, u_colormap6Threshold,
u_colormap6ThresholdEnabled, u_colormap6Alpha, u_colormap6Colormap, u_colormap6Active );
#endif
#ifdef Colormap5Enabled
colormap( finalColor, u_colormap5Sampler, v_colormap5TexCoord.xyz, u_colormap5Min, u_colormap5Scale, u_colormap5Threshold,
u_colormap5ThresholdEnabled, u_colormap5Alpha, u_colormap5Colormap, u_colormap5Active );
colormap( finalColor, u_colormap5Sampler, v_colormap5TexCoord.xyz,
vec3( u_colormap5SizeX, u_colormap5SizeY, u_colormap5SizeZ ),
u_colormap5Min, u_colormap5Scale, u_colormap5Threshold,
u_colormap5ThresholdEnabled, u_colormap5Alpha, u_colormap5Colormap, u_colormap5Active );
#endif
#ifdef Colormap4Enabled
colormap( finalColor, u_colormap4Sampler, v_colormap4TexCoord.xyz, u_colormap4Min, u_colormap4Scale, u_colormap4Threshold,
u_colormap4ThresholdEnabled, u_colormap4Alpha, u_colormap4Colormap, u_colormap4Active );
colormap( finalColor, u_colormap4Sampler, v_colormap4TexCoord.xyz,
vec3( u_colormap4SizeX, u_colormap4SizeY, u_colormap4SizeZ ),
u_colormap4Min, u_colormap4Scale, u_colormap4Threshold,
u_colormap4ThresholdEnabled, u_colormap4Alpha, u_colormap4Colormap, u_colormap4Active );
#endif
#ifdef Colormap3Enabled
colormap( finalColor, u_colormap3Sampler, v_colormap3TexCoord.xyz, u_colormap3Min, u_colormap3Scale, u_colormap3Threshold,
u_colormap3ThresholdEnabled, u_colormap3Alpha, u_colormap3Colormap, u_colormap3Active );
colormap( finalColor, u_colormap3Sampler, v_colormap3TexCoord.xyz,
vec3( u_colormap3SizeX, u_colormap3SizeY, u_colormap3SizeZ ),
u_colormap3Min, u_colormap3Scale, u_colormap3Threshold,
u_colormap3ThresholdEnabled, u_colormap3Alpha, u_colormap3Colormap, u_colormap3Active );
#endif
#ifdef Colormap2Enabled
colormap( finalColor, u_colormap2Sampler, v_colormap2TexCoord.xyz, u_colormap2Min, u_colormap2Scale, u_colormap2Threshold,
u_colormap2ThresholdEnabled, u_colormap2Alpha, u_colormap2Colormap, u_colormap2Active );
colormap( finalColor, u_colormap2Sampler, v_colormap2TexCoord.xyz,
vec3( u_colormap2SizeX, u_colormap2SizeY, u_colormap2SizeZ ),
u_colormap2Min, u_colormap2Scale, u_colormap2Threshold,
u_colormap2ThresholdEnabled, u_colormap2Alpha, u_colormap2Colormap, u_colormap2Active );
#endif
#ifdef Colormap1Enabled
colormap( finalColor, u_colormap1Sampler, v_colormap1TexCoord.xyz, u_colormap1Min, u_colormap1Scale, u_colormap1Threshold,
u_colormap1ThresholdEnabled, u_colormap1Alpha, u_colormap1Colormap, u_colormap1Active );
colormap( finalColor, u_colormap1Sampler, v_colormap1TexCoord.xyz,
vec3( u_colormap1SizeX, u_colormap1SizeY, u_colormap1SizeZ ),
u_colormap1Min, u_colormap1Scale, u_colormap1Threshold,
u_colormap1ThresholdEnabled, u_colormap1Alpha, u_colormap1Colormap, u_colormap1Active );
#endif
#ifdef Colormap0Enabled
colormap( finalColor, u_colormap0Sampler, v_colormap0TexCoord.xyz, u_colormap0Min, u_colormap0Scale, u_colormap0Threshold,
u_colormap0ThresholdEnabled, u_colormap0Alpha, u_colormap0Colormap, u_colormap0Active );
colormap( finalColor, u_colormap0Sampler, v_colormap0TexCoord.xyz,
vec3( u_colormap0SizeX, u_colormap0SizeY, u_colormap0SizeZ ),
u_colormap0Min, u_colormap0Scale, u_colormap0Threshold,
u_colormap0ThresholdEnabled, u_colormap0Alpha, u_colormap0Colormap, u_colormap0Active );
#endif
return finalColor;
......
......@@ -29,6 +29,7 @@
// All the uniforms needed. These uniforms get set by the WGEColormapping class for your Node.
/////////////////////////////////////////////////////////////////////////////
// Colormap 0
/////////////////////////////////////////////////////////////////////////////
......@@ -57,6 +58,11 @@ uniform bool u_colormap0Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap0Sampler;
//!< The size in voxel dimensions
uniform int u_colormap0SizeX;
uniform int u_colormap0SizeY;
uniform int u_colormap0SizeZ;
/////////////////////////////////////////////////////////////////////////////
// Colormap 1
/////////////////////////////////////////////////////////////////////////////
......@@ -85,6 +91,11 @@ uniform bool u_colormap1Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap1Sampler;
//!< The size in voxel dimensions
uniform int u_colormap1SizeX;
uniform int u_colormap1SizeY;
uniform int u_colormap1SizeZ;
/////////////////////////////////////////////////////////////////////////////
// Colormap 2
/////////////////////////////////////////////////////////////////////////////
......@@ -113,6 +124,11 @@ uniform bool u_colormap2Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap2Sampler;
//!< The size in voxel dimensions
uniform int u_colormap2SizeX;
uniform int u_colormap2SizeY;
uniform int u_colormap2SizeZ;
/////////////////////////////////////////////////////////////////////////////
// Colormap 3
/////////////////////////////////////////////////////////////////////////////
......@@ -141,6 +157,11 @@ uniform bool u_colormap3Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap3Sampler;
//!< The size in voxel dimensions
uniform int u_colormap3SizeX;
uniform int u_colormap3SizeY;
uniform int u_colormap3SizeZ;
/////////////////////////////////////////////////////////////////////////////
// Colormap 4
/////////////////////////////////////////////////////////////////////////////
......@@ -169,6 +190,11 @@ uniform bool u_colormap4Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap4Sampler;
//!< The size in voxel dimensions
uniform int u_colormap4SizeX;
uniform int u_colormap4SizeY;
uniform int u_colormap4SizeZ;
/////////////////////////////////////////////////////////////////////////////
// Colormap 5
/////////////////////////////////////////////////////////////////////////////
......@@ -197,6 +223,11 @@ uniform bool u_colormap5Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap5Sampler;
//!< The size in voxel dimensions
uniform int u_colormap5SizeX;
uniform int u_colormap5SizeY;
uniform int u_colormap5SizeZ;
/////////////////////////////////////////////////////////////////////////////
// Colormap 6
/////////////////////////////////////////////////////////////////////////////
......@@ -225,6 +256,11 @@ uniform bool u_colormap6Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap6Sampler;
//!< The size in voxel dimensions
uniform int u_colormap6SizeX;
uniform int u_colormap6SizeY;
uniform int u_colormap6SizeZ;
/////////////////////////////////////////////////////////////////////////////
// Colormap 7
/////////////////////////////////////////////////////////////////////////////
......@@ -253,5 +289,10 @@ uniform bool u_colormap7Active;
//!< The sampler for texture access.
uniform sampler3D u_colormap7Sampler;
//!< The size in voxel dimensions
uniform int u_colormap7SizeX;
uniform int u_colormap7SizeY;
uniform int u_colormap7SizeZ;
#endif // WGECOLORMAPPING_UNIFORMS_GLSL
......@@ -31,14 +31,14 @@
/**
* Grabs and unscales the value inside the texture and returns it.
*
*
* \param texture the texture unit to use
* \param point the texture coordinates
* \param minimum the minumum value of all values inside the texture
* \param scale the scaling value for all values inside the texture
*
* \note The minimum and scale values are normally transferred to the shader using uniforms, as the CPU scales the textures
*
*
* \return the value at the given point
*/
vec4 texture3DUnscaled( sampler3D texture, vec3 point, float minimum, float scale )
......@@ -48,14 +48,14 @@ vec4 texture3DUnscaled( sampler3D texture, vec3 point, float minimum, float scal
/**
* Grabs and unscales the value inside the texture and returns it.
*
*
* \param texture the texture unit to use
* \param point the texture coordinates
* \param minimum the minumum value of all values inside the texture
* \param scale the scaling value for all values inside the texture
*
* \note The minimum and scale values are normally transferred to the shader using uniforms, as the CPU scales the textures
*
*
* \return the value at the given point
*/
vec4 texture2DUnscaled( sampler2D texture, vec2 point, float minimum, float scale )
......@@ -83,9 +83,9 @@ vec4 texture1DUnscaled( sampler1D texture, float point, float minimum, float sca
/**
* This method normalizes a given point/vector in a special way. It scales it so that the largest component is exactly 1.
* This way the other components can profit from the whole precision in textures (where all values are clamped if >1).
*
*
* \param point the point to scale
*
*
* \return the scaled point, where max( { point.x, point.y, point.z, point.w } ) = 1
*/
vec4 textureNormalize( vec4 point )
......@@ -96,9 +96,9 @@ vec4 textureNormalize( vec4 point )
/**
* This method normalizes a given point/vector in a special way. It scales it so that the largest component is exactly 1.
* This way the other components can profit from the whole precision in textures (where all values are clamped if >1).
*
*
* \param point the point to scale
*
*
* \return the scaled point, where max( { point.x, point.y, point.z } ) = 1
*/
vec3 textureNormalize( vec3 point )
......@@ -109,9 +109,9 @@ vec3 textureNormalize( vec3 point )
/**
* This method normalizes a given point/vector in a special way. It scales it so that the largest component is exactly 1.
* This way the other components can profit from the whole precision in textures (where all values are clamped if >1).
*
*
* \param point the point to scale
*
*
* \return the scaled point, where max( { point.x, point.y, point.z } ) = 1
*/
vec2 textureNormalize( vec2 point )
......@@ -119,5 +119,45 @@ vec2 textureNormalize( vec2 point )
return 0.5 + ( 0.5 * scaleMaxToOne( point ) );
}
/**
* Returns the discrete voxel coordinate in texture space. This is useful to get the nearest pixel/voxel for a given coordinate in [0,1].
*
* \param vSize the normalized size of the texture (usually this is a vec3( 1.0 / sizeX, 1.0 / sizeY, 1.0 / sizeZ ).
* \param coord the coordinate to get the discrete coordinate for
*
* \return the coordinate
*/
vec3 getDiscreteVoxelCoordinate( in vec3 vSize, in vec3 coord )
{
coord.x -= mod( coord.x, vSize.x );
coord.y -= mod( coord.y, vSize.y );
coord.z -= mod( coord.z, vSize.z );
coord.x += 0.5 * vSize.x;
coord.y += 0.5 * vSize.y;
coord.z += 0.5 * vSize.z;
return coord;
}
/**
* Get the discrete coordinate of a neighbour coordinate relative to the given one. Useful for manual implementations of interpolation
* algorithms.
*
* \param vSize the normalized size of the texture (usually this is a vec3( 1.0 / sizeX, 1.0 / sizeY, 1.0 / sizeZ ).
* \param coord the coordinate to which the neighbour is relative
* \param direction the direction. vec3( 1.0, 0.0, 0.0 ) returns the right neighbour.
*
* \return the neighbour coordinate.
*/
vec3 getNeighbourVoxel( in vec3 vSize, in vec3 coord, in vec3 direction )
{
vec3 me = getDiscreteVoxelCoordinate( vSize, coord );
return me + vec3( direction.x * vSize.x,
direction.y * vSize.y,
direction.z * vSize.z
);
}
#endif // WGETEXTURETOOLS_GLSL
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment