Added ability to disable shading for RenderablePlanet renderables

This commit is contained in:
Alexander Bock
2015-02-16 19:23:23 +01:00
parent 92d5d2ee3c
commit 69e0213e79
5 changed files with 54 additions and 37 deletions

View File

@@ -65,6 +65,7 @@ private:
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
planetgeometry::PlanetGeometry* _geometry;
properties::BoolProperty _performShading;
glm::dmat3 _stateMatrix;

View File

@@ -76,11 +76,6 @@ namespace renderable {
const std::string keyType = "Type";
} // namespace renderable
namespace renderableplanet {
const std::string keyFrame = "Frame";
const std::string keyGeometry = "Geometry";
} // namespace renderableplanet
namespace planetgeometry {
const std::string keyType = "Type";
} // namespace planetgeometry

View File

@@ -28,6 +28,7 @@ uniform vec4 campos;
uniform vec4 objpos;
//uniform vec3 camdir; // add this for specular
uniform bool _performShading = true;
uniform float time;
uniform sampler2D texture1;
@@ -46,33 +47,39 @@ void main()
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse = texture(texture1, vs_st);
// directional lighting
vec3 origin = vec3(0.0);
vec4 spec = vec4(0.0);
vec3 n = normalize(vs_normal.xyz);
//vec3 e = normalize(camdir);
vec3 l_pos = vec3(0.0); // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float intensity = min(max(5*dot(n,l_dir), 0.0), 1);
float shine = 0.0001;
vec4 specular = vec4(0.5);
vec4 ambient = vec4(0.0,0.0,0.0,1);
/*
if(intensity > 0.f){
// halfway vector
vec3 h = normalize(l_dir + e);
// specular factor
float intSpec = max(dot(h,n),0.0);
spec = specular * pow(intSpec, shine);
if (_performShading) {
// directional lighting
vec3 origin = vec3(0.0);
vec4 spec = vec4(0.0);
vec3 n = normalize(vs_normal.xyz);
//vec3 e = normalize(camdir);
vec3 l_pos = vec3(0.0); // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float intensity = min(max(5*dot(n,l_dir), 0.0), 1);
float shine = 0.0001;
vec4 specular = vec4(0.5);
vec4 ambient = vec4(0.0,0.0,0.0,1);
/*
if(intensity > 0.f){
// halfway vector
vec3 h = normalize(l_dir + e);
// specular factor
float intSpec = max(dot(h,n),0.0);
spec = specular * pow(intSpec, shine);
}
*/
diffuse = max(intensity * diffuse, ambient);
//diffuse = vec4(1);
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}
else {
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}
*/
diffuse = max(intensity * diffuse, ambient);
//diffuse = vec4(1);
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}

View File

@@ -40,7 +40,11 @@
#include <sgct.h>
namespace {
const std::string _loggerCat = "RenderablePlanet";
const std::string _loggerCat = "RenderablePlanet";
const std::string keyFrame = "Frame";
const std::string keyGeometry = "Geometry";
const std::string keyShading = "PerformShading";
}
namespace openspace {
@@ -51,6 +55,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
, _programObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
, _performShading("performShading", "Perform Shading", true)
{
std::string name;
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
@@ -63,15 +68,14 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
"RenderablePlanet need the '"<<constants::scenegraph::keyPathModule<<"' be specified");
ghoul::Dictionary geometryDictionary;
success = dictionary.getValue(
constants::renderableplanet::keyGeometry, geometryDictionary);
success = dictionary.getValue(keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
}
dictionary.getValue(constants::renderableplanet::keyFrame, _target);
dictionary.getValue(keyFrame, _target);
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
@@ -84,6 +88,14 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
if (dictionary.hasKeyAndValue<bool>(keyShading)) {
bool shading;
dictionary.getValue(keyShading, shading);
_performShading = shading;
}
addProperty(_performShading);
}
RenderablePlanet::~RenderablePlanet() {
@@ -147,6 +159,8 @@ void RenderablePlanet::render(const RenderData& data)
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, &data.camera, data.position);
_programObject->setUniform("_performShading", _performShading);
// Bind texture
ghoul::opengl::TextureUnit unit;
unit.activate();