Added support for variable transparency in RenderableSphere

Created own shaders for RenderableSphere
This commit is contained in:
Alexander Bock
2015-02-16 23:16:06 +01:00
parent bb5f6e1bca
commit 98aeeda24d
5 changed files with 149 additions and 6 deletions
@@ -60,6 +60,8 @@ private:
properties::Vec2Property _size;
properties::IntProperty _segments;
properties::FloatProperty _transparency;
ghoul::opengl::ProgramObject* _shader;
ghoul::opengl::Texture* _texture;
+74
View File
@@ -0,0 +1,74 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform float time;
uniform sampler2D texture1;
uniform float alpha;
in vec2 vs_st;
in vec4 vs_position;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
void main()
{
vec4 position = vs_position;
// This has to be fixed with the ScaleGraph in place (precision deficiency in depth buffer) ---abock
// float depth = pscDepth(position);
float depth = 1000.0;
vec4 diffuse;
// if(gl_FrontFacing)
diffuse = texture(texture1, vs_st);
// else
// diffuse = texture(texture1, vec2(1-vs_st.s,vs_st.t));
diffuse.a *= alpha;
//vec4 diffuse = vec4(1,vs_st,1);
//vec4 diffuse = vec4(1,0,0,1);
// if(position.w > 9.0) {
// diffuse = vec4(1,0,0,1);
// }
// #if 0
// diffuse = vec4(vs_position.xyz / 10, 1.0);
// #else
// // if (abs(vs_st.r - 0.75) <= 0.01 && abs(vs_st.g - 0.5) <= 0.01)
// if (abs(vs_st.g - 0.5) <= 0.01)
// diffuse = vec4(vec2(vs_st), 0.0, 1.0);
// else
// diffuse = vec4(0.0);
// #endif
// diffuse = vec4(1.0, 0.0, 0.0, 1.0);
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
}
+57
View File
@@ -0,0 +1,57 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
layout(location = 0) in vec4 in_position;
layout(location = 1) in vec2 in_st;
out vec2 vs_st;
out vec4 vs_position;
out float s;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vec4 tmp = in_position;
mat4 mt = ModelTransform;
mt = mat4(0, -1, 0, 0,
1, 0, 0, 0,
0, 0, -1, 0,
0, 0, 0, 1) * mt;
vec4 position = pscTransform(tmp, mt);
vs_position = in_position;
vs_st = in_st;
position = ViewProjection * position;
gl_Position = z_normalization(position);
}
+15 -5
View File
@@ -42,8 +42,8 @@ namespace {
const std::string keyOrientation = "Orientation";
enum Orientation {
Outside = 0,
Inside
Outside = 1,
Inside = 2
};
}
@@ -55,6 +55,7 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
, _orientation("orientation", "Orientation")
, _size("size", "Size", glm::vec2(1.f, 1.f), glm::vec2(0.f), glm::vec2(100.f))
, _segments("segments", "Segments", 8, 4, 100)
, _transparency("transparency", "Transparency", 1.f, 0.f, 1.f)
, _shader(nullptr)
, _texture(nullptr)
, _sphere(nullptr)
@@ -105,6 +106,8 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
addProperty(_segments);
_segments.onChange([this](){ _sphereIsDirty = true; });
addProperty(_transparency);
addProperty(_texturePath);
_texturePath.onChange(std::bind(&RenderableSphere::loadTexture, this));
}
@@ -121,9 +124,9 @@ bool RenderableSphere::initialize() {
_sphere->initialize();
// pscstandard
_shader = ghoul::opengl::ProgramObject::Build("pscstandard",
"${SHADERS}/plane_vs.glsl",
"${SHADERS}/plane_fs.glsl");
_shader = ghoul::opengl::ProgramObject::Build("Sphere",
"${SHADERS}/modules/sphere/sphere_vs.glsl",
"${SHADERS}/modules/sphere/sphere_fs.glsl");
if (!_shader)
return false;
_shader->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*){ _programIsDirty = true; });
@@ -143,13 +146,19 @@ void RenderableSphere::render(const RenderData& data) {
glm::mat4 transform = glm::mat4(1.0);
transform = glm::rotate(transform, 90.f, glm::vec3(1, 0, 0));
// Activate shader
_shader->activate();
_shader->setIgnoreUniformLocationError(true);
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_shader->setUniform("ModelTransform", transform);
setPscUniforms(_shader, &data.camera, data.position);
_shader->setUniform("alpha", _transparency);
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
@@ -157,6 +166,7 @@ void RenderableSphere::render(const RenderData& data) {
_sphere->render();
_shader->setIgnoreUniformLocationError(false);
_shader->deactivate();
}