Started working on modularizing PSC and ABuffer

This commit is contained in:
Jonas Strandstedt
2014-09-26 17:03:59 +02:00
parent c526c0f38d
commit 2d359fd48c
17 changed files with 128 additions and 158 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<Cluster masterAddress="localhost" externalControlPort="20500">
<Settings>
<Display swapInterval="0" />
<Display swapInterval="1" />
</Settings>
<Node address="localhost" port="20401">
<Window fullScreen="false" fxaa="false">
@@ -13,7 +13,7 @@
<!-- <Size x="960" y="540" /> -->
<!-- <Size x="640" y="360" /> -->
<!--<Size x="640" y="310" />-->
<Pos x="640" y="0.0" />
<Pos x="1700" y="50.0" />
<Viewport>
<Pos x="0.0" y="0.0" />
<Size x="1.0" y="1.0" />
+2
View File
@@ -32,6 +32,7 @@
#include <openspace/util/powerscaledscalar.h>
#include <openspace/util/camera.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/opengl/programobject.h>
#include <openspace/properties/propertyowner.h>
#include <openspace/util/runtimedata.h>
@@ -58,6 +59,7 @@ public:
protected:
std::string findPath(const std::string& path);
void setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const psc& position);
private:
properties::BoolProperty _enabled;
+1 -1
View File
@@ -1,5 +1,5 @@
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
openspace.time.setTime("2000-01-01T00:00:00")
openspace.time.setDeltaTime(0.0)
openspace.time.setDeltaTime(1.0)
print(openspace.time.currentTimeUTC())
@@ -0,0 +1,41 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#ifndef POWERSCALING_MATH_HGLSL
#define POWERSCALING_MATH_HGLSL
const float k = 10.0;
vec4 psc_addition(vec4 v1, vec4 v2) {
float ds = v2.w - v1.w;
if(ds >= 0) {
float p = pow(k,-ds);
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
} else {
float p = pow(k,ds);
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
}
}
#endif
+7 -13
View File
@@ -25,18 +25,12 @@
#ifndef POWERSCALING_VS_H_HGLSL
#define POWERSCALING_VS_H_HGLSL
const float k = 10.0;
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
vec4 psc_addition(vec4 v1, vec4 v2) {
float ds = v2.w - v1.w;
if(ds >= 0) {
float p = pow(k,-ds);
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
} else {
float p = pow(k,ds);
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
}
}
#include "powerScalingMath.hglsl"
vec4 psc_to_meter(vec4 v1, vec2 v2) {
float factor = v2.x * pow(k,v2.y + v1.w);
@@ -52,7 +46,7 @@ vec4 psc_scaling(vec4 v1, vec2 v2) {
}
}
vec4 pscTransform(vec4 vertexPosition, vec4 cameraPosition, vec2 scaling, mat4 modelTransform) {
vec4 pscTransform(vec4 vertexPosition, mat4 modelTransform) {
vec3 local_vertex_pos = mat3(modelTransform) * vertexPosition.xyz;
//vec4 lvp = ModelTransform * vertexPosition;
@@ -61,7 +55,7 @@ vec4 pscTransform(vec4 vertexPosition, vec4 cameraPosition, vec2 scaling, mat4 m
//position = psc_addition(lvp,objpos);
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
position = psc_addition(position,vec4(-cameraPosition.xyz,cameraPosition.w));
position = psc_addition(position,vec4(-campos.xyz,campos.w));
// rotate the camera
local_vertex_pos = mat3(camrot) * position.xyz;
+1 -5
View File
@@ -28,10 +28,6 @@ layout(location = 0) in vec4 vertPosition;
uniform mat4 modelViewProjection;
uniform mat4 modelTransform;
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
out vec3 vPosition;
out vec3 worldPosition;
@@ -49,7 +45,7 @@ void main() {
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
//vs_normal = normalize(modelTransform * vec4(in_normal,0));
vec4 position = pscTransform(vertPosition, campos, scaling, modelTransform);
vec4 position = pscTransform(vertPosition, modelTransform);
worldPosition = position.xyz;
s = position.w;
+1 -6
View File
@@ -26,11 +26,6 @@
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
uniform float time;
layout(location = 0) in vec4 in_position;
//in vec3 in_position;
@@ -54,7 +49,7 @@ void main()
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
vec4 position = pscTransform(in_position, campos, scaling, ModelTransform);
vec4 position = pscTransform(in_position, ModelTransform);
vs_position = position.xyz;
s = position.w;
+26 -68
View File
@@ -8,15 +8,20 @@ in vec2 texCoord;
layout(location = 2) in vec3 ge_brightness;
out vec4 diffuse;
//out vec4 diffuse;
const float k = 10.0;
#include "ABuffer/abufferStruct.hglsl"
#include "ABuffer/abufferAddToBuffer.hglsl"
#include "PowerScaling/powerScaling_fs.hglsl"
//---------------------------------------------------------------------------
vec4 bv2rgb(float bv) // RGB <0,1> <- BV <-0.4,+2.0> [-]
{
float t;
vec4 c;
// TODO CHECK: Isn't t uninitialized here?
if (t<-0.4) t=-0.4; if (t> 2.0) t= 2.0;
if ((bv>=-0.40)&&(bv<0.00)) { t=(bv+0.40)/(0.00+0.40); c.r=0.61+(0.11*t)+(0.1*t*t); }
else if ((bv>= 0.00)&&(bv<0.40)) { t=(bv-0.00)/(0.40-0.00); c.r=0.83+(0.17*t) ; }
@@ -33,77 +38,30 @@ vec4 bv2rgb(float bv) // RGB <0,1> <- BV <-0.4,+2.0> [-]
}
//---------------------------------------------------------------------------
vec4 psc_normlization(vec4 invec) {
float xymax = max(invec.x,invec.y);
if(invec.z > 0.0f || invec.z < 0.0f) {
return invec / abs(invec.z);
} else if (xymax != 0.0f) {
return invec / xymax;
} else {
return invec / -.0;
}
}
void main(void)
{
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
float s_far = 27.0; //= gl_DepthRange.far; // 40
float s_farcutoff = 12.0;
float s_nearcutoff = 7.0;
float s_near = 0.0f;// gl_DepthRange.near; // 0.1
float depth;
// the value can be normalized to 1
vec4 p = vs_position;
if(vs_position.w <= 0.5) {
//depth = abs(vs_position.z * pow(10, vs_position.w)) / pow(k,s_far);
depth = (vs_position.w+log(abs(vs_position.z)))/pow(k, vs_position.w);
} else if(vs_position.w < 3.0) {
depth = vs_position.w+log(abs(vs_position.z))/pow(k, vs_position.w);
} else {
depth = vs_position.w+log(abs(vs_position.z));
}
// DEBUG
float depth_orig = depth;
float x = 0.0f;
float cutoffs = 0.0;
float orig_z = vs_position.z;
// calculate a normalized depth [0.0 1.0]
if((depth > s_near && depth <= s_nearcutoff) || (depth > s_farcutoff && depth < s_far)) {
// completely linear interpolation [s_near .. depth .. s_far]
depth = (depth - s_near) / (s_far - s_near);
} else if(depth > s_nearcutoff && depth < s_farcutoff) {
// DEBUG
cutoffs = 1.0;
// interpolate [10^s_nearcutoff .. 10^depth .. 10^s_farcutoff]
// calculate between 0..1 where the depth is
x = (pow(10,depth) - pow(10, s_nearcutoff)) / (pow(10,s_farcutoff) - pow(10, s_nearcutoff));
// remap the depth to the 0..1 depth buffer
depth = s_nearcutoff + x * (s_farcutoff - s_nearcutoff);
depth = (depth - s_near) / (s_far - s_near);
} else {
// where am I?
// do I need to be discarded?
// discard;
}
// set the depth
gl_FragDepth = depth;
// Something in the color calculations need to be changed because before it was dependent
// on the gl blend functions since the abuffer was not involved
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_BLEND);
//glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
vec4 color = bv2rgb(ge_brightness[0])/1.1;
diffuse = texture2D(texture1, texCoord)*color;
//color.rgb = 1/ color.rgb;
color.a = 1-color.a;
vec4 diffuse = texture2D(texture1, texCoord)*color;
///diffuse = vec4(Color, 1.0);
vec4 position = vs_position;
float depth = pscDepth(position);
//ABufferStruct_t frag = createGeometryFragment(vec4(1,0,0,1), position, depth);
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
addToBuffer(frag);
discard;
}
+3 -11
View File
@@ -6,17 +6,9 @@ const vec2 corners[4] = {
vec2(1.0, 1.0),
vec2(1.0, 0.0)
};
float k = 10.f;
vec4 psc_addition(vec4 v1, vec4 v2) {
float ds = v2.w - v1.w;
if(ds >= 0) {
float p = pow(k,-ds);
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
} else {
float p = pow(k,ds);
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
}
}
#include "PowerScaling/powerScalingMath.hglsl"
float log10( float x ){ return log(x) / log(10); }
in vec4 psc_position[];
+17 -6
View File
@@ -1,10 +1,6 @@
#version 440
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
uniform mat4 model;
uniform mat4 view;
@@ -20,7 +16,7 @@ out vec3 vs_brightness;
out vec4 psc_position;
out vec4 cam_position;
/*
const float k = 10.0;
const float dgr_to_rad = 0.0174532925;
@@ -48,12 +44,15 @@ vec4 psc_scaling(vec4 v1, vec2 v2) {
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
}
}
*/
#include "PowerScaling/powerScaling_vs.hglsl"
void main(){
vs_brightness = in_brightness;
psc_position = in_position;
cam_position = campos;
/*
// rotate and scale vertex with model transform and add the translation
vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz;
//vec4 lvp = ModelTransform * in_position;
@@ -85,7 +84,19 @@ void main(){
// project the position to view space
//gl_Position = ViewProjection * vs_position_rescaled;
gl_Position = view * model * vs_position_rescaled;
*/
/*psc_position = view * model * vs_position_rescaled;
gl_Position = psc_position; /// reduntant way but easier to go back. */
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
//vs_normal = normalize(modelTransform * vec4(in_normal,0));
vec4 position = pscTransform(in_position, ModelTransform);
// project the position to view space
//gl_Position = ViewProjection * position;
gl_Position = view * model * position;
}
+2 -2
View File
@@ -363,11 +363,11 @@ void InteractionHandler::keyboardCallback(int key, int action) {
distance(dist);
}
if (key == SGCT_KEY_Y) {
PowerScaledScalar dist(-speed * 100.0 * dt, 2.0);
PowerScaledScalar dist(-speed * 100.0 * dt, 6.0);
distance(dist);
}
if (key == SGCT_KEY_H) {
PowerScaledScalar dist(speed * 100.0 * dt, 2.0);
PowerScaledScalar dist(speed * 100.0 * dt, 6.0);
distance(dist);
}
}
+4 -7
View File
@@ -45,7 +45,7 @@ namespace openspace {
RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
@@ -79,7 +79,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
addPropertySubOwner(_geometry);
addProperty(_colorTexturePath);
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
}
@@ -151,11 +151,8 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run
// setup the data to the shader
_programObject->setUniform("ViewProjection", camera->viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
_programObject->setUniform("campos", campos.vec4());
_programObject->setUniform("objpos", currentPosition.vec4());
_programObject->setUniform("camrot", camrot);
_programObject->setUniform("scaling", scaling.vec2());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, camera, currentPosition);
// Bind texture
ghoul::opengl::TextureUnit unit;
+7
View File
@@ -106,6 +106,13 @@ std::string Renderable::findPath(const std::string& path) {
return "";
}
void Renderable::setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const psc& position) {
program->setUniform("campos", camera->position().vec4());
program->setUniform("objpos", position.vec4());
program->setUniform("camrot", camera->viewRotationMatrix());
program->setUniform("scaling", camera->scaling());
}
bool Renderable::isVisible() const {
return _enabled;
}
+2 -10
View File
@@ -225,20 +225,12 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition,
transform = glm::mat4(1.0);
transform = glm::scale(transform, glm::vec3(0.01));
psc currentPosition = thisPosition;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
PowerScaledScalar scaling = camera->scaling();
// Activate shader
_fieldlinesProgram->activate();
_fieldlinesProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix());
_fieldlinesProgram->setUniform("modelTransform", transform);
_fieldlinesProgram->setUniform("campos", campos.vec4());
_fieldlinesProgram->setUniform("objpos", currentPosition.vec4());
_fieldlinesProgram->setUniform("camrot", camrot);
_fieldlinesProgram->setUniform("scaling", scaling.vec2());
_fieldlinesProgram->setUniform("modelTransform", transform);
setPscUniforms(_fieldlinesProgram, camera, thisPosition);
// ------ FIELDLINES -----------------
glBindVertexArray(_VAO);
+4 -12
View File
@@ -249,25 +249,17 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R
// fetch data
psc currentPosition = thisPosition;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
PowerScaledScalar scaling = camera->scaling();
// psc addon(-1.1,0.0,0.0,0.0);
// currentPosition += addon;
psc addon(_boxOffset/100.0f); // TODO: Proper scaling/units
currentPosition += addon; // Move box to model barycenter
// TODO: Use _id to identify this volume
_boxProgram->activate();
_boxProgram->setUniform(_typeLocation, _id);
_boxProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix());
_boxProgram->setUniform("modelTransform", transform);
_boxProgram->setUniform("campos", campos.vec4());
_boxProgram->setUniform("objpos", currentPosition.vec4());
_boxProgram->setUniform("camrot", camrot);
_boxProgram->setUniform("scaling", scaling.vec2());
_boxProgram->setUniform(_typeLocation, _id);
_boxProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix());
_boxProgram->setUniform("modelTransform", transform);
setPscUniforms(_boxProgram, camera, currentPosition);
// make sure GL_CULL_FACE is enabled (it should be)
glEnable(GL_CULL_FACE);
+7 -14
View File
@@ -313,13 +313,8 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt
_haloProgram->activate();
// fetch data
psc currentPosition = thisPosition;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
PowerScaledScalar scaling = camera->scaling();
glm::mat4 transform = glm::mat4(1);
//scaling = glm::vec2(1, -22);
scaling = glm::vec2(1, -19);
glm::vec2 scaling = glm::vec2(1, -19);
#ifdef TMAT
transform = glm::rotate(transform,
@@ -327,9 +322,9 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt
glm::vec3(0.0f, 1.0f, 0.0f));
#endif
// disable depth test, enable additative blending
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_BLEND);
//glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
#ifdef GLSPRITES
glm::mat4 modelMatrix = camera->modelMatrix();
@@ -342,11 +337,9 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt
_haloProgram->setUniform("projection", projectionMatrix);
//_haloProgram->setUniform("ViewProjection", camera->viewProjectionMatrix());
_haloProgram->setUniform("ModelTransform", transform);
_haloProgram->setUniform("campos", campos.vec4());
_haloProgram->setUniform("objpos", currentPosition.vec4());
_haloProgram->setUniform("camrot", camrot);
_haloProgram->setUniform("scaling", scaling.vec2());
_haloProgram->setUniform("ModelTransform", glm::mat4(1));
setPscUniforms(_haloProgram, camera, thisPosition);
_haloProgram->setUniform("scaling", scaling);
// Bind texure
ghoul::opengl::TextureUnit unit;