Skip to content

Commit

Permalink
Simple sky: fix the application of diffuse color as radiance in the P…
Browse files Browse the repository at this point in the history
…BR model
  • Loading branch information
gwaldron committed Nov 16, 2023
1 parent 1e714df commit 3694d4c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/osgEarth/ImGui/EnvironmentGUI
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ namespace osgEarth

if (ImGuiLTable::SliderFloat("Ambient max", &_max_ambient_intensity, 0.0f, 1.0f)) dirtySettings();
_skyNode->getOrCreateStateSet()->getOrCreateUniform("oe_sky_maxAmbientIntensity", osg::Uniform::FLOAT)->set(_max_ambient_intensity);

auto diffuse_color = _skyNode->getSunLight()->getDiffuse();
if (ImGuiLTable::ColorEdit3("Diffuse color", &diffuse_color[0], ImGuiColorEditFlags_Float)) {
_skyNode->getSunLight()->setDiffuse(diffuse_color);
dirtySettings();
}
}
else
{
Expand Down Expand Up @@ -301,12 +307,10 @@ namespace osgEarth
ImGuiLTable::Checkbox("Sun", &sun_visible);
_skyNode->setSunVisible(sun_visible);

//ImGui::SameLine();
bool moon_visible = _skyNode->getMoonVisible();
ImGuiLTable::Checkbox("Moon", &moon_visible);
_skyNode->setMoonVisible(moon_visible);

//ImGui::SameLine();
bool stars_visible = _skyNode->getStarsVisible();
ImGuiLTable::Checkbox("Stars", &stars_visible);
_skyNode->setStarsVisible(stars_visible);
Expand Down
18 changes: 18 additions & 0 deletions src/osgEarth/ImGui/ImGui
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,24 @@ namespace ImGuiLTable
return ImGui::InputScalar(s.c_str(), data_type, p_data, p_step, p_step_fast, format, flags);
}

static bool ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flags = 0)
{
ImGui::TableNextColumn();
ImGui::Text(label);
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-1);
return ImGui::ColorEdit3(label, col, flags);
}

static bool ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0)
{
ImGui::TableNextColumn();
ImGui::Text(label);
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(-1);
return ImGui::ColorEdit4(label, col, flags);
}

static void End()
{
ImGui::EndTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ void atmos_fragment_main_pbr(inout vec4 color)
vec3 H = normalize(V + L);
//float distance = length(osg_LightSource[i].position.xyz - atmos_vert);
//float attenuation = 1.0 / (distance * distance);
vec3 radiance = vec3(1.0); // osg_LightSource[i].diffuse.rgb * attenuation;

//radiance *= atmos_atten;
vec3 radiance = osg_LightSource[i].diffuse.rgb; // * attenuation

// cook-torrance BRDF:
float NDF = DistributionGGX(N, H, oe_pbr.roughness);
Expand Down
4 changes: 2 additions & 2 deletions src/osgEarthDrivers/sky_simple/SimpleSkyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ SimpleSkyNode::construct()

_light = new LightGL3(0);
_light->setPosition(osg::Vec4f(0.0f, 0.0f, 1.0f, 0.0f));
_light->setAmbient(osg::Vec4f(0.1f, 0.1f, 0.1f, 1.0f));
_light->setAmbient(osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
_light->setDiffuse(osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
_light->setSpecular(osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
_light->setSpecular(osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); // does nothing in PBR mode

// install the Sun as a lightsource.
osg::LightSource* lightSource = new osg::LightSource();
Expand Down

0 comments on commit 3694d4c

Please sign in to comment.