mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Fixed Ephimeris rendering to use PSC correctly
This commit is contained in:
@@ -7,95 +7,37 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
|
||||
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 400 core
|
||||
#version 430
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
//uniform vec4 etColor;
|
||||
|
||||
in vec4 vs_point_position;
|
||||
in vec4 vs_point_velocity;
|
||||
|
||||
|
||||
out vec4 diffuse;
|
||||
//out vec4 diffuse;
|
||||
|
||||
const float k = 10.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;
|
||||
}
|
||||
}
|
||||
#include "ABuffer/abufferStruct.hglsl"
|
||||
#include "ABuffer/abufferAddToBuffer.hglsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
|
||||
float s_far = 40.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_point_position;
|
||||
if(vs_point_position.w <= 0.5) {
|
||||
//depth = abs(vs_point_position.z * pow(10, vs_point_position.w)) / pow(k,s_far);
|
||||
depth = (vs_point_position.w+log(abs(vs_point_position.z)))/pow(k, vs_point_position.w);
|
||||
} else if(vs_point_position.w < 3.0) {
|
||||
depth = vs_point_position.w+log(abs(vs_point_position.z))/pow(k, vs_point_position.w);
|
||||
} else {
|
||||
depth = vs_point_position.w+log(abs(vs_point_position.z));
|
||||
}
|
||||
|
||||
|
||||
// DEBUG
|
||||
float depth_orig = depth;
|
||||
float x = 0.0f;
|
||||
float cutoffs = 0.0;
|
||||
float orig_z = vs_point_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;
|
||||
}
|
||||
|
||||
vec4 position = vs_point_position;
|
||||
float depth = pscDepth(position);
|
||||
|
||||
// set the depth
|
||||
gl_FragDepth = depth;
|
||||
//gl_FragDepth = depth;
|
||||
|
||||
//float l = length(vs_point_velocity);
|
||||
|
||||
diffuse = vs_point_velocity;
|
||||
vec4 diffuse = vs_point_velocity;
|
||||
|
||||
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
|
||||
addToBuffer(frag);
|
||||
|
||||
discard;
|
||||
|
||||
}
|
||||
@@ -19,14 +19,10 @@ 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 400 core
|
||||
#version 430
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 campos;
|
||||
uniform mat4 camrot;
|
||||
uniform vec2 scaling;
|
||||
uniform vec4 objpos;
|
||||
//uniform vec4 etColor;
|
||||
uniform vec4 objectVelocity;
|
||||
|
||||
@@ -38,52 +34,18 @@ layout(location = 2) in vec2 in_point_timeindex;
|
||||
out vec4 vs_point_position;
|
||||
out vec4 vs_point_velocity;
|
||||
|
||||
const float k = 10.0;
|
||||
const float dgr_to_rad = 0.0174532925;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
vec4 psc_to_meter(vec4 v1, vec2 v2) {
|
||||
float factor = v2.x * pow(k,v2.y + v1.w);
|
||||
return vec4(v1.xyz * factor, 1.0);
|
||||
}
|
||||
|
||||
vec4 psc_scaling(vec4 v1, vec2 v2) {
|
||||
float ds = v2.y - v1.w;
|
||||
if(ds >= 0) {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
|
||||
} else {
|
||||
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
|
||||
}
|
||||
}
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
//vs_stp = in_point_position.xyz;
|
||||
//vs_normal = normalize(ModelTransform*vec4(1)); // <-- not really using right now. change later.
|
||||
|
||||
// add life back to the thing.
|
||||
/*
|
||||
vec3 vel_1 = psc_to_meter(in_point_velocity, vec2(3)).xyz;
|
||||
vec3 vel_2 = psc_to_meter(objectVelocity, vec2(3)).xyz;
|
||||
float a = 0;
|
||||
|
||||
vec3 dist = (objpos-in_point_position).xyz;
|
||||
|
||||
if( dot(dist, vel_2) > 0.f){
|
||||
a = 2.f*dot(vel_1,vel_2)/(length(vel_1)*length(vel_2));
|
||||
}*/
|
||||
vs_point_velocity = in_point_velocity;
|
||||
|
||||
vec4 tmp = in_point_position;
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_point_position = tmp;
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
/*
|
||||
//vs_point_position = objpos;
|
||||
|
||||
// rotate and scale vertex with model transform and add the translation
|
||||
@@ -109,4 +71,5 @@ void main()
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = ViewProjection * vs_point_position_rescaled;
|
||||
*/
|
||||
}
|
||||
@@ -201,24 +201,13 @@ void RenderableEphemeris::render(const RenderData& data){
|
||||
assert(_programObject);
|
||||
_programObject->activate();
|
||||
|
||||
// fetch data
|
||||
psc currentPosition = data.position;
|
||||
psc campos = data.camera.position();
|
||||
glm::mat4 camrot = data.camera.viewRotationMatrix();
|
||||
// PowerScaledScalar scaling = camera->scaling();
|
||||
PowerScaledScalar scaling = glm::vec2(1, -6);
|
||||
|
||||
glm::mat4 transform = glm::mat4(1);
|
||||
|
||||
// setup the data to the shader
|
||||
//_programObject->setUniform("objectVelocity", pscvel.vec4());
|
||||
|
||||
_programObject->setUniform("ViewProjection", data.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", glm::mat4(1));
|
||||
setPscUniforms(_programObject, &data.camera, data.position);
|
||||
|
||||
nextIndex();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user