Issue #2680 fixed samplers in structs issues with GLSL spec.

Change-Id: I2375e4c273f6cd340f253d71ae7eadc8ed9a38e9

Former-commit-id: 7de6ff30da [formerly 3c1fafe328] [formerly 7822511754] [formerly 7de6ff30da [formerly 3c1fafe328] [formerly 7822511754] [formerly a8a67634f9 [formerly 7822511754 [formerly 4f3635fc682c2a1746e188dac0f371676c9e0be9]]]]
Former-commit-id: a8a67634f9
Former-commit-id: 8ddc6b95e4 [formerly dd872433c7] [formerly a6667b70df86f17d8dea3939535e720a8767c67d [formerly e2e9eaaf35]]
Former-commit-id: 724e3e430da7d1dade1094fde0ea1cb4e6b99344 [formerly 9d6d418d48]
Former-commit-id: 560bc77a16
This commit is contained in:
Max Schenkelberg 2014-02-07 11:00:00 -06:00 committed by Gerrit Code Review
parent f41d73618d
commit 75cde90e40
8 changed files with 117 additions and 90 deletions

View file

@ -6,8 +6,13 @@ const int RED_BAND = 0;
const int GREEN_BAND = 1;
const int BLUE_BAND = 2;
uniform DataTexture rawData;
uniform DataMapping dataMapping;
uniform sampler2D rawDataTex;
uniform DataTextureInfo rawData;
uniform sampler1D dataMappingDataValues;
uniform sampler1D dataMappingColorValues;
uniform int dataMappingValues;
uniform ColorMapping colorMapping;
uniform sampler2D trueColorTexture;
@ -49,7 +54,7 @@ vec4 applyColorBand(int colorband) {
vec2((xy.x / width), (xy.y / height)));
// Lookup raw data value
float dataValue = textureToDataValue(rawData, gl_TexCoord[0].st);
float dataValue = textureToDataValue(rawDataTex, rawData, gl_TexCoord[0].st);
float r = curVal.r;
float g = curVal.g;
@ -58,7 +63,7 @@ vec4 applyColorBand(int colorband) {
if (dataValue != rawData.noDataValue && dataValue == dataValue) {
// Convert dataValue to cmapValue
float cmapValue = dataToColorMapValue(dataValue, dataMapping);
float cmapValue = dataToColorMapValue(dataValue, dataMappingDataValues, dataMappingColorValues, dataMappingValues);
float index = getColorMappingIndex(cmapValue, colorMapping);
int currentMask = toBitMask(a);
@ -86,4 +91,4 @@ void main(void) {
} else {
gl_FragColor = applyColorBand(band);
}
}
}

View file

@ -3,7 +3,10 @@
#include <mapping>
#include <coloring>
uniform sampler1D colorMappingColorMap;
uniform sampler1D colorMappingAlphaMask;
uniform ColorMapping colorMapping;
uniform ColorModifiers modifiers;
uniform float bkgrndRed;
@ -19,12 +22,12 @@ void main(void){
if ( logFactor > 0.0 ) {
index = getLogFactorIndex(index, logFactor);
}
vec4 color = texture1D(colorMapping.colorMap, index).rgba;
vec4 color = texture1D(colorMappingColorMap, index).rgba;
// Apply alpha mask if set
float alpha = color.a;
if ( applyMask == 1 ) {
if ( texture1D(colorMapping.alphaMask , index ).r != 0.0 ) {
if ( texture1D(colorMappingAlphaMask , index ).r != 0.0 ) {
color = vec4(bkgrndRed, bkgrndGreen, bkgrndBlue, alpha);
}
}

View file

@ -1,13 +1,21 @@
#include <mapping>
#include <coloring>
uniform DataTexture rawData;
uniform DataMapping dataMapping;
uniform sampler2D rawDataTex;
uniform DataTextureInfo rawData;
uniform sampler1D dataMappingDataValues;
uniform sampler1D dataMappingColorValues;
uniform int dataMappingValues;
uniform sampler1D colorMappingColorMap;
uniform sampler1D colorMappingAlphaMask;
uniform ColorMapping colorMapping;
uniform ColorModifiers modifiers;
void main(void) {
float dataValue = textureToDataValue(rawData, gl_TexCoord[0].st);
float dataValue = textureToDataValue(rawDataTex, rawData, gl_TexCoord[0].st);
// No data check/special NaN check
if (dataValue == rawData.noDataValue || dataValue != dataValue) {
@ -16,9 +24,9 @@ void main(void) {
}
// Convert dataValue to cmapValue
float cmapValue = dataToColorMapValue(dataValue, dataMapping);
float cmapValue = dataToColorMapValue(dataValue, dataMappingDataValues, dataMappingColorValues, dataMappingValues);
// Get color for colormapping, given value
vec4 textureColor = getColorByValue(cmapValue, colorMapping);
vec4 textureColor = getColorByValue(cmapValue, colorMapping, colorMappingColorMap, colorMappingAlphaMask);
// Apply the color modifiers into gl_FragColor
gl_FragColor = applyColorModifiers(textureColor, modifiers);
}

View file

@ -8,8 +8,7 @@
* implied data will range 0-1 and need scaling to get raw value
* where scaleMin maps to 0 and scaleMax maps to 1.
*/
struct DataTexture {
sampler2D rawTex;
struct DataTextureInfo {
float noDataValue;
int isScaled;
float scaleMin;
@ -18,23 +17,9 @@ struct DataTexture {
float height;
};
/**
* Fields used for converting from image data values to
* colormapping data values. Done to avoid conversions in
* application code. dmv[i] -> cmv[i]. Linear interpolation
* is done where non-exact matches are found. Mappings should
* be uploaded as floats so no scaling is needed
*/
struct DataMapping {
sampler1D dataMappingValues;
sampler1D colorMappingValues;
int numMappingValues;
};
struct ColorMapping {
/** Fields for color map and size. colorMap contains colors to
* use for mapping. cmapMin/Max is range colormap is applied over */
sampler1D colorMap;
float cmapMin;
float cmapMax;
@ -42,7 +27,6 @@ struct ColorMapping {
* same size as colorMap and contains 0s and 1s, 1 indicating alpha
* should be set to completely transparent */
int applyMask;
sampler1D alphaMask;
/** Fields for logarithmic and mirrored indexing into the colorMap */
int isMirrored;
@ -51,28 +35,28 @@ struct ColorMapping {
};
/**
* Returns the data value for the DataTexture at location.
* Returns the data value for the DataTextureInfo at location.
*/
float textureToDataValue(DataTexture texture, vec2 location) {
vec4 textureValue = texture2D(texture.rawTex, location);
float textureToDataValue(sampler2D texture, DataTextureInfo info, vec2 location) {
vec4 textureValue = texture2D(texture, location);
float dataValue = textureValue.r;
if (texture.isScaled == 1) {
if (info.isScaled == 1) {
// Convert to non-scaled value
dataValue = ((dataValue * (texture.scaleMax - texture.scaleMin))
+ texture.scaleMin);
dataValue = ((dataValue * (info.scaleMax - info.scaleMin))
+ info.scaleMin);
}
return dataValue;
}
/**
* Returns the data value for the DataTexture at location.
* Returns the data value for the DataTextureInfo at location.
*/
float dataToTextureValue(DataTexture texture, float dataValue) {
float dataToTextureValue(DataTextureInfo info, float dataValue) {
float textureValue = dataValue;
if (texture.isScaled == 1) {
textureValue = (dataValue - texture.scaleMin)
/ (texture.scaleMax - texture.scaleMin);
if (info.isScaled == 1) {
textureValue = (dataValue - info.scaleMin)
/ (info.scaleMax - info.scaleMin);
}
return textureValue;
}
@ -86,10 +70,9 @@ float lookupMappingValue(sampler1D mappingTex, int index,
}
/**
* Converts a data value into a colorMap value given the DataMapping
* Converts a data value into a colorMap value given the data mapping info
*/
float dataToColorMapValue(float dataValue, DataMapping mapping) {
int numMappingValues = mapping.numMappingValues;
float dataToColorMapValue(float dataValue, sampler1D dataMappingDataValues, sampler1D dataMappingColorValues, int numMappingValues) {
if (numMappingValues == 0) {
// Short circuit if no mapping is needed
return dataValue;
@ -99,9 +82,9 @@ float dataToColorMapValue(float dataValue, DataMapping mapping) {
int lowIndex = 0;
int highIndex = numMappingValues - 1;
float lowValue = lookupMappingValue(mapping.dataMappingValues, lowIndex,
float lowValue = lookupMappingValue(dataMappingDataValues, lowIndex,
numMappingValues);
float highValue = lookupMappingValue(mapping.dataMappingValues, highIndex,
float highValue = lookupMappingValue(dataMappingDataValues, highIndex,
numMappingValues);
int reversed = 0;
if (lowValue > highValue) {
@ -117,7 +100,7 @@ float dataToColorMapValue(float dataValue, DataMapping mapping) {
int nextIndex = lowIndex + ((highIndex - lowIndex) / 2);
if (nextIndex > lowIndex && nextIndex < highIndex) {
// Look up next value and determine if it is a high or low
float nextValue = lookupMappingValue(mapping.dataMappingValues,
float nextValue = lookupMappingValue(dataMappingDataValues,
nextIndex, numMappingValues);
if (nextValue < dataValue) {
if (reversed == 0) {
@ -146,9 +129,9 @@ float dataToColorMapValue(float dataValue, DataMapping mapping) {
factor = 1.0 - factor;
}
float lowCmapValue = lookupMappingValue(mapping.colorMappingValues,
float lowCmapValue = lookupMappingValue(dataMappingColorValues,
lowIndex, numMappingValues);
float highCmapValue = lookupMappingValue(mapping.colorMappingValues,
float highCmapValue = lookupMappingValue(dataMappingColorValues,
highIndex, numMappingValues);
return lowCmapValue + (highCmapValue - lowCmapValue) * factor;
@ -180,16 +163,16 @@ float getLinearIndex(float cmapValue, float cmapMin, float cmapMax) {
*/
float valueToLogIndex(float value, float rangeMin, float rangeMax) {
// Account for 0 min index
if (rangeMin == 0) {
if (rangeMin == 0.0) {
rangeMin = 0.0000001;
if (rangeMax < 0) {
if (rangeMax < 0.0) {
rangeMin = -rangeMin;
}
}
int reverse = 0;
if ((value < rangeMin && rangeMin > 0)
|| (value > rangeMin && rangeMin < 0)) {
if ((value < rangeMin && rangeMin > 0.0)
|| (value > rangeMin && rangeMin < 0.0)) {
reverse = 1;
}
@ -200,7 +183,7 @@ float valueToLogIndex(float value, float rangeMin, float rangeMax) {
// Check uncomputable index value, everything between this range is 0,
// rangeMin->rangeMax 0 -> 1, -rangeMin->-rangeMax 0 -> -1
if (value <= rangeMin && value >= -rangeMin) {
return 0;
return 0.0;
}
float index = (log(value) - log(rangeMin))
@ -232,12 +215,12 @@ float getLogIndex(float cmapValue, float cmapMin, float cmapMax, int mirror) {
float index = 0.0;
// Flag if min/max values are on opposite sides of zero
int minMaxOpposite = 0;
if ((cmapMin < 0 && cmapMax > 0) || (cmapMin > 0 && cmapMax < 0)) {
if ((cmapMin < 0.0 && cmapMax > 0.0) || (cmapMin > 0.0 && cmapMax < 0.0)) {
minMaxOpposite = 1;
}
if (mirror != 0 || minMaxOpposite != 0) {
if (cmapMax < 0) {
if (cmapMax < 0.0) {
// Invert colormapping if negative range was given
cmapValue = -cmapValue;
}
@ -261,9 +244,9 @@ float getLogIndex(float cmapValue, float cmapMin, float cmapMax, int mirror) {
float logPosCmapMax = absLogZeroVal + log(posCmapMax);
// Calculate index which zeroVal is at based on neg max and pos max
float zeroValIndex = logNegCmapMax / (logNegCmapMax + logPosCmapMax);
if (cmapValue > 0) {
if (cmapValue > 0.0) {
index = valueToLogIndex(rangeValue, zeroVal, posCmapMax);
index = zeroValIndex + (1 - zeroValIndex) * index;
index = zeroValIndex + (1.0 - zeroValIndex) * index;
} else {
index = valueToLogIndex(rangeValue, zeroVal, negCmapMax);
index = zeroValIndex - zeroValIndex * index;
@ -277,8 +260,8 @@ float getLogIndex(float cmapValue, float cmapMin, float cmapMax, int mirror) {
if (inverted == 1) {
index = 1.0 - index;
}
if (cmapMin > 0 && cmapValue < rangeMin
|| (cmapMin < 0 && cmapValue > -rangeMin)) {
if (cmapMin > 0.0 && cmapValue < rangeMin
|| (cmapMin < 0.0 && cmapValue > -rangeMin)) {
index = -index;
}
}
@ -333,13 +316,13 @@ float getColorMappingIndex(float cmapValue, ColorMapping colorMapping) {
/**
* Returns a color for the index based on the ColorMapping
*/
vec4 getColorByIndex(float index, ColorMapping colorMapping) {
vec4 getColorByIndex(float index, sampler1D colorMap, sampler1D alphaMask, int applyMask) {
// Lookup color in colorMap for index
vec4 textureColor = texture1D(colorMapping.colorMap, index).rgba;
vec4 textureColor = texture1D(colorMap, index).rgba;
// Apply alpha mask
if (colorMapping.applyMask == 1) {
if (texture1D(colorMapping.alphaMask, index).r != 0.0) {
if (applyMask == 1) {
if (texture1D(alphaMask, index).r != 0.0) {
textureColor = vec4(textureColor.rgb, 0.0);
}
}
@ -349,7 +332,7 @@ vec4 getColorByIndex(float index, ColorMapping colorMapping) {
/**
* Returns a color for the cmapValue based on the ColorMapping
*/
vec4 getColorByValue(float cmapValue, ColorMapping colorMapping) {
return getColorByIndex(getColorMappingIndex(cmapValue, colorMapping),
colorMapping);
vec4 getColorByValue(float cmapValue, ColorMapping colorMapping, sampler1D colorMap, sampler1D alphaMask) {
float index = getColorMappingIndex(cmapValue, colorMapping);
return getColorByIndex(index, colorMap, alphaMask, colorMapping.applyMask);
}

View file

@ -3,21 +3,27 @@
#include <mapping>
uniform DataTexture imageData;
uniform DataMapping imageToMosaic;
uniform DataTexture mosaicData;
uniform sampler2D imageDataTex;
uniform DataTextureInfo imageData;
uniform sampler1D imageToMosaicDataValues;
uniform sampler1D imageToMosaicColorValues;
uniform int imageToMosaicValues;
uniform sampler2D mosaicDataTex;
uniform DataTextureInfo mosaicData;
void main(void) {
float imageValue = textureToDataValue(imageData, gl_TexCoord[0].st);
float imageValue = textureToDataValue(imageDataTex, imageData, gl_TexCoord[0].st);
vec2 frag_xy = gl_FragCoord.xy;
float mosaicValue = textureToDataValue(mosaicData,
float mosaicValue = textureToDataValue(mosaicDataTex, mosaicData,
vec2(frag_xy.x / mosaicData.width, frag_xy.y / mosaicData.height));
float newValue = mosaicValue;
// No data check/special NaN check
if (imageValue != imageData.noDataValue && imageValue == imageValue) {
// Convert image value to mosaic value
imageValue = dataToColorMapValue(imageValue, imageToMosaic);
imageValue = dataToColorMapValue(imageValue, imageToMosaicDataValues, imageToMosaicColorValues, imageToMosaicValues);
if (imageValue > mosaicValue) {
newValue = imageValue;
}

View file

@ -3,14 +3,20 @@
#include <mapping>
uniform DataTexture imageData;
uniform DataMapping imageToMosaic;
uniform DataTexture mosaicData;
uniform sampler2D imageDataTex;
uniform DataTextureInfo imageData;
uniform sampler1D imageToMosaicDataValues;
uniform sampler1D imageToMosaicColorValues;
uniform int imageToMosaicValues;
uniform sampler2D mosaicDataTex;
uniform DataTextureInfo mosaicData;
void main(void) {
float imageValue = textureToDataValue(imageData, gl_TexCoord[0].st);
float imageValue = textureToDataValue(imageDataTex, imageData, gl_TexCoord[0].st);
vec2 frag_xy = gl_FragCoord.xy;
float mosaicValue = textureToDataValue(mosaicData,
float mosaicValue = textureToDataValue(mosaicDataTex, mosaicData,
vec2(frag_xy.x / mosaicData.width, frag_xy.y / mosaicData.height));
float newValue;
@ -19,7 +25,7 @@ void main(void) {
// Use existing value
newValue = mosaicValue;
} else {
newValue = dataToColorMapValue(imageValue, imageToMosaic);
newValue = dataToColorMapValue(imageValue, imageToMosaicDataValues, imageToMosaicColorValues, imageToMosaicValues);
}
gl_FragColor = vec4(dataToTextureValue(mosaicData, newValue), 0.0, 0.0,
1.0);

View file

@ -56,7 +56,9 @@ public class GLSLStructFactory {
int texBinding, AbstractGLColormappedImage image) {
ColorMapParameters parameters = image.getColorMapParameters();
AbstractGLColorMapDataFormat dataFormat = image.getDataFormat();
setFieldUniform(program, name, "rawTex", texBinding);
// Set the texture outside the struct
setFieldUniform(program, name + "Tex", texBinding);
// Set struct fields
setFieldUniform(program, name, "noDataValue",
parameters.getNoDataValue());
setFieldUniform(program, name, "isScaled", dataFormat.isScaled());
@ -82,11 +84,9 @@ public class GLSLStructFactory {
public static void createDataMapping(GLShaderProgram program, String name,
int dataMappingTexBinding, int colorMappingTexBinding,
int numMappingValues) {
setFieldUniform(program, name, "dataMappingValues",
dataMappingTexBinding);
setFieldUniform(program, name, "colorMappingValues",
colorMappingTexBinding);
setFieldUniform(program, name, "numMappingValues", numMappingValues);
setFieldUniform(program, name + "DataValues", dataMappingTexBinding);
setFieldUniform(program, name + "ColorValues", colorMappingTexBinding);
setFieldUniform(program, name + "Values", numMappingValues);
}
/**
@ -101,12 +101,12 @@ public class GLSLStructFactory {
public static void createColorMapping(GLShaderProgram program, String name,
int colorMapTexBinding, int alphaMaskTexBinding,
ColorMapParameters parameters) {
setFieldUniform(program, name, "colorMap", colorMapTexBinding);
setFieldUniform(program, name + "ColorMap", colorMapTexBinding);
setFieldUniform(program, name, "cmapMin", parameters.getColorMapMin());
setFieldUniform(program, name, "cmapMax", parameters.getColorMapMax());
setFieldUniform(program, name, "applyMask", parameters.isUseMask());
setFieldUniform(program, name, "alphaMask", alphaMaskTexBinding);
setFieldUniform(program, name + "AlphaMask", alphaMaskTexBinding);
setFieldUniform(program, name, "isMirrored", parameters.isMirror());
setFieldUniform(program, name, "isLogarithmic",
@ -132,6 +132,13 @@ public class GLSLStructFactory {
private static void setFieldUniform(GLShaderProgram program,
String structName, String fieldName, Object fieldValue) {
program.setUniform(structName + FIELD_SEPERATOR + fieldName, fieldValue);
setFieldUniform(program, structName + FIELD_SEPERATOR + fieldName,
fieldValue);
}
private static void setFieldUniform(GLShaderProgram program,
String fieldName, Object fieldValue) {
program.setUniform(fieldName, fieldValue);
}
}

View file

@ -1706,8 +1706,9 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
endAzm += 360.0;
}
double totalAzimuth = (endAzm - startAzm);
boolean includeSides = circle.includeSides && !fill
&& ((endAzm - startAzm) < 360.0);
&& (totalAzimuth < 360.0);
if (fill) {
gl.glBegin(GL.GL_TRIANGLE_FAN);
@ -1720,8 +1721,16 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
}
}
double step = (endAzm - startAzm) / (circle.numberOfPoints);
for (double azm = startAzm; azm <= endAzm; azm += step) {
// Get the number of unique points in the circle
int points = circle.numberOfPoints;
if (totalAzimuth >= 360) {
// If angle is meant to be complete circle, add extra point
// to ensure circle is touching
points += 1;
}
double step = totalAzimuth / (points - 1);
for (int i = 0; i < points; ++i) {
double azm = startAzm + (i * step);
double[] pointOnCircle = getPointOnCircle(x, y, z, radius,
azm);
gl.glVertex3d(pointOnCircle[0], pointOnCircle[1],