Added properties and tried to use Smoothstep in vertexshader

This commit is contained in:
Christian Adamsson
2020-07-15 17:07:45 +02:00
parent 1c5bd44d21
commit d88cfce24f
4 changed files with 144 additions and 34 deletions

View File

@@ -60,15 +60,48 @@ namespace {
"speed of light",
"The speed of light"
};
constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = {
"lineWidth",
"Line Width",
"This value specifies the line width of the field lines if the "
"selected rendering method includes lines."
};
constexpr openspace::properties::Property::PropertyInfo RenderModeInfo = {
"RenderingMode",
"The draw method",
"Can be used to decide what rendering method to use."
};
constexpr openspace::properties::Property::PropertyInfo LightColorInfo = {
"lightColor",
"The color of the light particle",
"Choose what color to light the particle as it is traversing the line"
};
constexpr openspace::properties::Property::PropertyInfo DefaultcolorInfo = {
"defaultColor",
"The color of the lines",
"Choose what color each line should have as default value"
};
constexpr openspace::properties::Property::PropertyInfo PointSizeInfo = {
"pointSize",
"Size of points",
"Change the size of the points"
};
}
namespace openspace {
using namespace properties;
RenderableLightTravel::RenderableLightTravel(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _lightspeed(LightSpeedInfo, 3000000000)
, _lightspeed(LightSpeedInfo, 299792458.f, 0, 299792458.f)
, _lineWidth(LineWidthInfo, 5, 0, 20)
, _rendermode(RenderModeInfo, OptionProperty::DisplayType::Dropdown)
, _pDefaultColor(DefaultcolorInfo, glm::vec4(0.3, 0.3, 0.3, 0.5),
glm::vec4(0.f),
glm::vec4(1.f))
, _pLightColor(LightColorInfo, glm::vec4(1,1,1,1),
glm::vec4(0.f),
glm::vec4(1.f))
, _pointSize(PointSizeInfo, 2.f, 0, 20)
{
_dictionary = std::make_unique<ghoul::Dictionary>(dictionary);
}
@@ -90,6 +123,7 @@ namespace openspace {
glm::vec3 currentpos = glm::vec3(0.0, 0.0, 0.0);
//positions.push_back(currentpos);
addProperty(_lightspeed);
addProperty(_lineWidth);
//_lightspeed = 300 * 10e6;
_lightspeed = 299792458.f;
SceneGraphNode* earthNode = sceneGraphNode("Earth");
@@ -122,6 +156,15 @@ namespace openspace {
LDEBUG("vi kom in i init");
_rendermode.addOption(static_cast<int>(RenderMethod::LineStrip), "LineStrip");
_rendermode.addOption(static_cast<int>(RenderMethod::Lines), "Lines");
_rendermode.addOption(static_cast<int>(RenderMethod::Points), "Points");
addProperty(_rendermode);
addProperty(_pLightColor);
addProperty(_pDefaultColor);
addProperty(_pointSize);
}
@@ -145,19 +188,19 @@ namespace openspace {
glm::vec3 normalizedVector = glm::normalize(endpos);
_normalizedVector = normalizedVector;
double endtime = starttime;
LDEBUG("distance" + std::to_string(glm::distance(newpos, endpos)));
//LDEBUG("distance" + std::to_string(glm::distance(newpos, endpos)));
int counter = 0;
float lightspeed = 299792458;
positions.clear();
positions.push_back(startpos);
//while (glm::distance(newpos, endpos) > 100000) {
int interval = 10;
while(endtime - starttime < 500){
newpos.x += 20 * lightspeed * normalizedVector.x;
newpos.y += 20 * lightspeed * normalizedVector.y;
newpos.z += 20 * lightspeed * normalizedVector.z;
newpos.x += interval * _lightspeed * normalizedVector.x;
newpos.y += interval * _lightspeed * normalizedVector.y;
newpos.z += interval * _lightspeed * normalizedVector.z;
endtime += 20;
endtime += interval;
++counter;
//LDEBUG("newpos.y" + std::to_string(newpos.y));
//LDEBUG("newpos.x" + std::to_string(newpos.x));
@@ -170,10 +213,11 @@ namespace openspace {
positions.push_back(newpos);
}
positions.push_back(endpos);
LDEBUG("endtime" + std::to_string(endtime));
LDEBUG("newpos.y" + std::to_string(newpos.y));
LDEBUG("newpos.x" + std::to_string(newpos.x));
LDEBUG("position size" + std::to_string(positions.size()));
// LDEBUG("endtime" + std::to_string(endtime));
// LDEBUG("newpos.y" + std::to_string(newpos.y));
//LDEBUG("newpos.x" + std::to_string(newpos.x));
//LDEBUG("position size" + std::to_string(positions.size()));
_needPositionUpdate = true;
return endtime;
}
bool RenderableLightTravel::isReady() const
@@ -218,9 +262,14 @@ namespace openspace {
_shaderProgram->setUniform("in_transmission_time", transmissiontime);
_shaderProgram->setUniform("in_light_travel_time", timeSinceStart);
_shaderProgram->setUniform("normalizedvectorFromSuntoEarth", _normalizedVector);
_shaderProgram->setUniform("renderMode", _rendermode);
_shaderProgram->setUniform("pointSize", _pointSize);
_shaderProgram->setUniform("defaultColor", _pDefaultColor);
_shaderProgram->setUniform("LightColor", _pLightColor);
}
glLineWidth(5.0f);
if(_rendermode == 0){
glLineWidth(_lineWidth);
GLint temp = 0;
glDrawArrays(
GL_LINE_STRIP,
@@ -228,6 +277,26 @@ namespace openspace {
temp,
static_cast<GLsizei>(positions.size())
);
}
else if (_rendermode == 1) {
glLineWidth(_lineWidth);
GLint temp = 0;
glDrawArrays(
GL_LINES,
temp,
static_cast<GLsizei>(positions.size())
);
}
else if (_rendermode == 2) {
GLint temp = 0;
glEnable(GL_PROGRAM_POINT_SIZE);
glDrawArrays(
GL_POINTS,
temp,
static_cast<GLsizei>(positions.size())
);
}
glBindVertexArray(0);
_shaderProgram->deactivate();
@@ -249,7 +318,7 @@ namespace openspace {
}
*/
const double currentTime = data.time.j2000Seconds();
_needPositionUpdate = true;
if (_needPositionUpdate) {
SceneGraphNode* earthNode = sceneGraphNode("Earth");
glm::vec3 earthPos = earthNode->worldPosition();
@@ -259,8 +328,9 @@ namespace openspace {
positions.push_back(earthPos);
_needPositionUpdate = false;
*/
_endTime = calculateEndTime(_triggerTime, currentpos, earthPos);
_needPositionUpdate = false;
_endTime = calculateEndTime(_triggerTime, currentpos, earthPos);
}
if (_triggerTime < currentTime && _endTime > currentTime) {

View File

@@ -66,12 +66,25 @@ namespace openspace {
// OpenGL Vertex Buffer Object containing the index of nodes
GLuint _vertexindexBuffer = 0;
enum class RenderMethod : int {
LineStrip = 0,
Lines = 1,
Points = 2
};
std::vector<glm::vec3> positions;
float _Timesincestart = -1.f;
double _triggerTime;
double _endTime;
bool _needPositionUpdate = true;
properties::FloatProperty _lightspeed;
properties::FloatProperty _lineWidth;
properties::OptionProperty _rendermode;
properties::FloatProperty _pointSize;
// Uniform stream Color
properties::Vec4Property _pDefaultColor;
// Uniform stream Color
properties::Vec4Property _pLightColor;
std::unique_ptr<ghoul::Dictionary> _dictionary;
std::unique_ptr<ghoul::opengl::ProgramObject> _shaderProgram;

View File

@@ -49,11 +49,11 @@ uniform float spacingSizeFactor;
uniform float fadeFactor;
uniform float baseOpacity;
*/
float flowSpeedFactor = 2;
float segmentSizeFactor = 2;
float spacingSizeFactor = 2;
float fadeFactor = 2;
float baseOpacity = 1;
float flowSpeedFactor = 1000000000;
float segmentSizeFactor = 200;
float spacingSizeFactor = 2000;
float fadeFactor = 0.2;
float baseOpacity = 0.5;
float getSegmentOpacity(const float segmentSize,
const float spacing,
@@ -128,13 +128,13 @@ Fragment getFragment() {
Fragment frag;
frag.depth = vs_depth;
/*
// the distance the first signal transmission has travelled
float distLightTravelStart = lightSpeed * timeSinceStart;
// the distance the last signal transmission has travelled
float distLightTravelEnd = lightSpeed * (timeSinceStart-transmissionTime);
float alpha = 1.0f;
float alpha = 0.0f;
if(distanceFromStart < distLightTravelStart && distanceFromStart > distLightTravelEnd){
// calculate how fast the signal segments travel within transmission
float distFlowTravelStart = distLightTravelStart * flowSpeedFactor;
@@ -147,10 +147,10 @@ Fragment getFragment() {
alpha = getSegmentOpacity(signalSegmentSize,spacing, distFlowTravelStart, distLightTravelStart, distLightTravelEnd);
// alpha = 0.5;
}
frag.color = vec4(fragColor.xyz, alpha);
*/
//frag.color = vec4(fragColor.xyz, alpha);
//frag.color = fragColor;
frag.color = fragColor;
// G-Buffer
frag.gPosition = vec4(0.0); //vs_gPosition;
//vec4 depthCorrection = vec4(0.0,0.0,9000,0.0);

View File

@@ -34,6 +34,10 @@ uniform float in_dist_from_start;
uniform float in_transmission_time;
uniform float in_light_travel_time;
uniform vec3 normalizedvectorFromSuntoEarth;
uniform int renderMode;
uniform float pointSize;
uniform vec4 defaultColor;
uniform vec4 LightColor;
/*
layout(location = 1) in float in_dist_from_start;
layout(location = 2) in float in_time_since_start;
@@ -48,16 +52,17 @@ out float lightTravelTime;
out vec4 vs_positionScreenSpace;
out vec4 vs_gPosition;
float maxdistance = 5000000000.f;
const float lightSpeed = 299792458.0;
bool calculateDistance(vec3 inposition) {
vec3 newpos = vec3(0, 0, 0);
//float temptime = 200;
float temptime = in_time_since_start;
newpos.x = normalizedvectorFromSuntoEarth.x * temptime * lightSpeed;
newpos.y = normalizedvectorFromSuntoEarth.y * temptime * lightSpeed;
newpos.z = normalizedvectorFromSuntoEarth.z * temptime * lightSpeed;
if(distance(newpos, inposition) < 5000000000.f){
//float temptime = in_time_since_start;
newpos.x = normalizedvectorFromSuntoEarth.x * in_time_since_start * lightSpeed;
newpos.y = normalizedvectorFromSuntoEarth.y * in_time_since_start * lightSpeed;
newpos.z = normalizedvectorFromSuntoEarth.z * in_time_since_start * lightSpeed;
if(distance(newpos, inposition) < maxdistance){
//if(inposition.x > 50000000000.f){
return true;
}
@@ -65,14 +70,36 @@ bool calculateDistance(vec3 inposition) {
return false;
}
float smoothmotion(){
vec3 newpos = vec3(0,0,0);
newpos.x = normalizedvectorFromSuntoEarth.x * in_time_since_start * lightSpeed;
newpos.y = normalizedvectorFromSuntoEarth.y * in_time_since_start * lightSpeed;
newpos.z = normalizedvectorFromSuntoEarth.z * in_time_since_start * lightSpeed;
float smoothFront = smoothstep(0.0, maxdistance, distance(newpos, in_position));
return smoothFront;
}
void main() {
if(calculateDistance(in_position)){
vs_color = vec4(1.0, 1.0, 1.0, 1.0);
//float smoothFront = smoothstep(0, 199999999999.0f, in_position.x);
// vs_color = vec4(1.0, 1.0, 1.0, 1.0);
vs_color = LightColor;
//vs_color.a = vs_color.a * smoothmotion();
//vs_color = vec4(0.2, 0.3, 0.4, 1.0);
}
else{
vs_color = vec4(0.2, 0.3, 0.4, 1.0);
//float smoothFront = smoothstep(0, 199999999999.0f, in_position.x);
//vs_color = vec4(1.0, 1.0, 1.0, smoothFront*1.0);
//vs_color = vec4(0.2, 0.3, 0.4, 1.0);
//vs_color = vec4(0);
vs_color = defaultColor;
}
if(renderMode == 2){
gl_PointSize = pointSize;
}
//vs_color = vec4(1.0, 1.0, 1.0, 1.0);