Skip to content

Commit 3960f16

Browse files
author
Brig Bagley
committed
color map parameters work on geometry
1 parent 229f14c commit 3960f16

File tree

4 files changed

+87
-51
lines changed

4 files changed

+87
-51
lines changed

src/Interface/Modules/Render/ES/shaders/ColorMap.fs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,41 @@
2424
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2525
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
DEALINGS IN THE SOFTWARE.
27-
*/
27+
*/
2828
#ifdef OPENGL_ES
29-
#ifdef GL_FRAGMENT_PRECISION_HIGH
30-
// Default precision
31-
precision highp float;
32-
#else
33-
precision mediump float;
34-
#endif
29+
#ifdef GL_FRAGMENT_PRECISION_HIGH
30+
// Default precision
31+
precision highp float;
32+
#else
33+
precision mediump float;
34+
#endif
3535
#endif
3636

3737
uniform sampler1D uTX0;
38-
varying float fFieldData;
38+
uniform float uCMInvert;
39+
uniform float uCMShift;
40+
uniform float uCMResolution;
41+
varying float fFieldData;
3942

4043
// Transparency to use along side the color map.
4144
uniform float uTransparency;
4245

4346
void main()
4447
{
45-
vec4 color = texture1D(uTX0, fFieldData);
46-
color.a = uTransparency;
47-
gl_FragColor = color;
48+
float param = fFieldData;
49+
float shift = uCMShift;
50+
if (uCMInvert != 0.) {
51+
param = 1. - param;
52+
shift = shift * -1.;
53+
}
54+
//apply the resolution
55+
int res = int(uCMResolution);
56+
param = float(int(param * (float(res)))) / float(res - 1);
57+
// the shift is a gamma.
58+
float bp = 1. / tan((3.14159265359 / 2.) * ( 0.5 - shift * 0.5));
59+
param = pow(param,bp);
60+
61+
vec4 color = texture1D( uTX0, param );
62+
color.a = uTransparency;
63+
gl_FragColor = color;
4864
}

src/Interface/Modules/Render/ES/shaders/DirPhongCMap.fs

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,27 @@
2424
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2525
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
DEALINGS IN THE SOFTWARE.
27-
*/
27+
*/
2828
#ifdef OPENGL_ES
29-
#ifdef GL_FRAGMENT_PRECISION_HIGH
30-
// Default precision
31-
precision highp float;
32-
#else
33-
precision mediump float;
34-
#endif
29+
#ifdef GL_FRAGMENT_PRECISION_HIGH
30+
// Default precision
31+
precision highp float;
32+
#else
33+
precision mediump float;
34+
#endif
3535
#endif
3636

3737
uniform vec3 uCamViewVec; // Camera 'at' vector in world space
3838
uniform vec4 uAmbientColor; // Ambient color
39-
uniform vec4 uSpecularColor; // Specular color
39+
uniform vec4 uSpecularColor; // Specular color
4040
uniform vec4 uDiffuseColor; // Diffuse color
4141
uniform float uSpecularPower; // Specular power
4242
uniform vec3 uLightDirWorld; // Directional light (world space).
4343
uniform float uTransparency;
4444
uniform sampler1D uTX0;
45+
uniform float uCMInvert;
46+
uniform float uCMShift;
47+
uniform float uCMResolution;
4548

4649
// Lighting in world space. Generally, it's better to light in eye space if you
4750
// are dealing with point lights. Since we are only dealing with directional
@@ -51,31 +54,43 @@ varying float vFieldData;
5154

5255
void main()
5356
{
54-
// Remember to always negate the light direction for these lighting
55-
// calculations. The dot product takes on its greatest values when the angle
56-
// between the two vectors diminishes.
57-
vec3 invLightDir = -uLightDirWorld;
58-
vec3 normal = normalize(vNormal);
59-
float diffuse = max(0.0, dot(normal, invLightDir));
60-
61-
// Note, the following is a hack due to legacy meshes still being supported.
62-
// We light the object as if it was double sided. We choose the normal based
63-
// on the normal that yields the largest diffuse component.
64-
float diffuseInv = max(0.0, dot(-normal, invLightDir));
65-
66-
if (diffuse < diffuseInv)
67-
{
68-
diffuse = diffuseInv;
69-
normal = -normal;
70-
}
71-
72-
vec3 reflection = reflect(invLightDir, normal);
73-
float spec = max(0.0, dot(reflection, uCamViewVec));
74-
75-
vec4 diffuseColor = texture1D( uTX0, vFieldData );
76-
//diffuseColor.a = uTransparency;
77-
78-
spec = pow(spec, uSpecularPower);
79-
gl_FragColor = vec4((diffuse * spec * uSpecularColor + diffuse * diffuseColor + uAmbientColor).rgb, uTransparency);
57+
// Remember to always negate the light direction for these lighting
58+
// calculations. The dot product takes on its greatest values when the angle
59+
// between the two vectors diminishes.
60+
vec3 invLightDir = -uLightDirWorld;
61+
vec3 normal = normalize(vNormal);
62+
float diffuse = max(0.0, dot(normal, invLightDir));
63+
64+
// Note, the following is a hack due to legacy meshes still being supported.
65+
// We light the object as if it was double sided. We choose the normal based
66+
// on the normal that yields the largest diffuse component.
67+
float diffuseInv = max(0.0, dot(-normal, invLightDir));
68+
69+
if (diffuse < diffuseInv)
70+
{
71+
diffuse = diffuseInv;
72+
normal = -normal;
73+
}
74+
75+
vec3 reflection = reflect(invLightDir, normal);
76+
float spec = max(0.0, dot(reflection, uCamViewVec));
77+
78+
float param = vFieldData;
79+
float shift = uCMShift;
80+
if (uCMInvert != 0.) {
81+
param = 1. - param;
82+
shift = shift * -1.;
83+
}
84+
//apply the resolution
85+
int res = int(uCMResolution);
86+
param = float(int(param * (float(res)))) / float(res - 1);
87+
// the shift is a gamma.
88+
float bp = 1. / tan((3.14159265359 / 2.) * ( 0.5 - shift * 0.5));
89+
param = pow(param,bp);
90+
91+
vec4 diffuseColor = texture1D( uTX0, param );
92+
93+
spec = pow(spec, uSpecularPower);
94+
gl_FragColor = vec4((diffuse * spec * uSpecularColor + diffuse * diffuseColor + uAmbientColor).rgb, uTransparency);
8095
}
8196

src/Interface/Modules/Render/ES/shaders/DirPhongCMap.vs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2525
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
DEALINGS IN THE SOFTWARE.
27-
*/
27+
*/
2828

2929
// Uniforms
3030
uniform mat4 uProjIVObject; // Projection transform * Inverse View
@@ -43,9 +43,9 @@ varying float vFieldData;
4343

4444
void main( void )
4545
{
46-
// Todo: Add gamma correction factor of 2.2. For textures, we assume that it
47-
// was generated in gamma space, and we need to convert it to linear space.
48-
vNormal = vec3(uObject * vec4(aNormal, 0.0));
49-
vFieldData = (aFieldData - uMinVal) / (uMaxVal - uMinVal);
50-
gl_Position = uProjIVObject * vec4(aPos, 1.0);
46+
// Todo: Add gamma correction factor of 2.2. For textures, we assume that it
47+
// was generated in gamma space, and we need to convert it to linear space.
48+
vNormal = vec3(uObject * vec4(aNormal, 0.0));
49+
vFieldData = (aFieldData - uMinVal) / (uMaxVal - uMinVal);
50+
gl_Position = uProjIVObject * vec4(aPos, 1.0);
5151
}

src/Modules/Visualization/ShowField.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,11 @@ void ShowFieldModule::renderEdges(
14361436
if (colorScheme == GeometryObject::COLOR_MAP) {
14371437
shader = state.get(RenderState::USE_CYLINDER) ? "Shaders/DirPhongCMap" : "Shaders/ColorMap";
14381438
attribs.push_back(GeometryObject::SpireVBO::AttributeData("aFieldData", 1 * sizeof(float)));
1439+
//push the color map parameters
1440+
ColorMap * map = colorMap.get().get();
1441+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uCMInvert",map->getColorMapInvert()?1.f:0.f));
1442+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uCMShift",static_cast<float>(map->getColorMapShift())));
1443+
uniforms.push_back(GeometryObject::SpireSubPass::Uniform("uCMResolution",static_cast<float>(map->getColorMapResolution())));
14391444
}
14401445
else if (colorScheme == GeometryObject::COLOR_IN_SITU) {
14411446
if (state.get(RenderState::USE_CYLINDER)) {

0 commit comments

Comments
 (0)