Skip to content

Commit

Permalink
tell the shader to apply colors per intensity when "Labels" is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
toloudis committed May 25, 2024
1 parent 0633ed7 commit b00ac7f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion agave_app/AppearanceSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,12 +1389,13 @@ QAppearanceSettingsWidget::onNewImage(Scene* scene)
if (name == "Labels") {
if (m_scene) {
m_scene->m_volume->channel((uint32_t)i)->colorize();

m_scene->m_material.m_labels[i] = 1.0;
// m_scene->m_volume->channel((uint32_t)i)->generate_controlPoints(stops);
m_qrendersettings->renderSettings()->m_DirtyFlags.SetFlag(TransferFunctionDirty);
}

} else {
m_scene->m_material.m_labels[i] = 0.0;
auto colormap = builtInGradients[index].second;
// update channel colormap from stops
this->OnUpdateColormap(i, colormap);
Expand Down
2 changes: 2 additions & 0 deletions renderlib/AppScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ VolumeDisplay::VolumeDisplay()

m_opacity[i] = 1.0;
m_roughness[i] = 1.0;

m_labels[i] = 0.0;
}
}

Expand Down
1 change: 1 addition & 0 deletions renderlib/AppScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct VolumeDisplay
float m_roughness[MAX_CPU_CHANNELS];
float m_opacity[MAX_CPU_CHANNELS];
bool m_enabled[MAX_CPU_CHANNELS];
float m_labels[MAX_CPU_CHANNELS];

GradientData m_gradientData[MAX_CPU_CHANNELS];

Expand Down
11 changes: 10 additions & 1 deletion renderlib/graphics/glsl/GLPTVolumeShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ uniform vec4 g_intensityMax;
uniform vec4 g_intensityMin;
uniform vec4 g_lutMax;
uniform vec4 g_lutMin;
uniform vec4 g_labels;
uniform float g_opacity[4];
uniform vec3 g_emissive[4];
uniform vec3 g_diffuse[4];
Expand Down Expand Up @@ -481,9 +482,14 @@ vec3 GetDiffuseN(float NormalizedIntensity, vec3 Pe, int ch)
// return texture(g_colormapTexture[ch], vec2(i, 0.5)).xyz * g_diffuse[ch];
vec4 intensity = UINT16_MAX * texture(volumeTexture, PtoVolumeTex(Pe));
if (g_labels[ch] > 0.0) {
return texelFetch(g_colormapTexture[ch], ivec2(int(intensity[ch]), 0), 0).xyz * g_diffuse[ch];
}
else {
float i = intensity[ch];
i = (i - g_lutMin[ch]) / (g_lutMax[ch] - g_lutMin[ch]);
return texture(g_colormapTexture[ch], vec2(i, 0.5)).xyz * g_diffuse[ch];
}
//return g_diffuse[ch];
Expand Down Expand Up @@ -1416,6 +1422,7 @@ void main()
m_intensityMin = uniformLocation("g_intensityMin");
m_lutMax = uniformLocation("g_lutMax");
m_lutMin = uniformLocation("g_lutMin");
m_labels = uniformLocation("g_labels");
m_opacity = uniformLocation("g_opacity");
m_emissive0 = uniformLocation("g_emissive[0]");
m_emissive1 = uniformLocation("g_emissive[1]");
Expand Down Expand Up @@ -1557,6 +1564,7 @@ GLPTVolumeShader::setShadingUniforms(const Scene* scene,
float intensitymin[4] = { 0, 0, 0, 0 };
float lutmax[4] = { 1, 1, 1, 1 };
float lutmin[4] = { 0, 0, 0, 0 };
float labels[4] = { 0, 0, 0, 0 };
float diffuse[3 * 4] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
float specular[3 * 4] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
float emissive[3 * 4] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Expand Down Expand Up @@ -1587,7 +1595,7 @@ GLPTVolumeShader::setShadingUniforms(const Scene* scene,
scene->m_material.m_gradientData[i].getMinMax(scene->m_volume->channel(i)->m_histogram, &imin16, &imax16);
lutmin[activeChannel] = hasMinMax ? imin16 : intensitymin[activeChannel];
lutmax[activeChannel] = hasMinMax ? imax16 : intensitymax[activeChannel];

labels[activeChannel] = scene->m_material.m_labels[i];
activeChannel++;
}
}
Expand Down Expand Up @@ -1638,6 +1646,7 @@ GLPTVolumeShader::setShadingUniforms(const Scene* scene,
glUniform4fv(m_intensityMin, 1, intensitymin);
glUniform4fv(m_lutMax, 1, lutmax);
glUniform4fv(m_lutMin, 1, lutmin);
glUniform4fv(m_labels, 1, labels);

glUniform1fv(m_opacity, 4, opacity);
glUniform3fv(m_emissive0, 1, emissive + 0);
Expand Down
6 changes: 3 additions & 3 deletions renderlib/graphics/glsl/GLPTVolumeShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class GLPTVolumeShader : public GLShaderProgram
m_light1areaPdf, m_light1color, m_light1colorTop, m_light1colorMiddle, m_light1colorBottom, m_light1T;

int m_lutTexture0, m_lutTexture1, m_lutTexture2, m_lutTexture3, m_colormapTexture0, m_colormapTexture1,
m_colormapTexture2, m_colormapTexture3, m_intensityMax, m_intensityMin, m_lutMax, m_lutMin, m_opacity, m_emissive0,
m_emissive1, m_emissive2, m_emissive3, m_diffuse0, m_diffuse1, m_diffuse2, m_diffuse3, m_specular0, m_specular1,
m_specular2, m_specular3, m_roughness, m_uShowLights;
m_colormapTexture2, m_colormapTexture3, m_intensityMax, m_intensityMin, m_lutMax, m_lutMin, m_labels, m_opacity,
m_emissive0, m_emissive1, m_emissive2, m_emissive3, m_diffuse0, m_diffuse1, m_diffuse2, m_diffuse3, m_specular0,
m_specular1, m_specular2, m_specular3, m_roughness, m_uShowLights;
};

0 comments on commit b00ac7f

Please sign in to comment.