Files
OpenSpace/shaders/star_ge_points.glsl
T
2014-11-04 18:17:15 +01:00

102 lines
4.4 KiB
GLSL

/*****************************************************************************************
* *
* 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__
layout(points) in;
layout(points, max_vertices = 1) out; // Draw points
//layout(triangle_strip, max_vertices = 4) out; // Draw quads
layout(location = 2) in vec3 vs_brightness[];
layout(location = 2) out vec3 ge_brightness[];
float spriteSize = 0.1; // set here for now.
out vec2 texCoord;
out float scale;
in vec4 psc_position[];
in vec4 campos[];
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);
}
}
float log10( float x ){ return log(x) / log(10); }
void main(){
ge_brightness[0] = vs_brightness[0];
float distToPoint = 1;
float radius = 2f;
// EMIT POINT
gl_Position = gl_in[0].gl_Position;
// right now only threshing with absolute magnitude.
float absMag = 1.0f;
if(vs_brightness[0].x < 0.0) absMag = 3;
if(vs_brightness[0].x < -3.0) absMag = 6;
if(vs_brightness[0].x < -6.0) absMag = 9;
// float M = vs_brightness[0][0]; // get ABSOLUTE magnitude (x param)
float M = vs_brightness[0][2]; // if NOT running test-target.
vec4 cam = vec4(-campos[0].xyz, campos[0].w); // get negative camera position
// does swizzle work?? FFS! do it manually:
vec4 pos = psc_position[0]; // get OK star position
vec4 result = psc_addition(pos, cam); // compute vec from camera to position
float x, y, z, w;
x = result[0];
y = result[1];
z = result[2];
w = result[3];
// I dont trust the legnth function at this point
vec2 pc = vec2(sqrt(x*x +y*y + z*z), result[3]); // form vec2
pc[0] *= 0.324077929; // convert meters -> parsecs
pc[1] += -18;
float pc_psc = pc[0] * pow(10, pc[1]); // psc scale out
float apparent = (M - 5.0f * (1.f - log10(pc_psc))); // formula, get appMagnitude.
vec4 P = gl_in[0].gl_Position;
float weight = 0.1f; // otherwise this takes over.
float depth = -P.z;
//depth *= pow(apparent,6);
//if(round(apparent) > 10)
scale = -apparent*weight;
gl_PointSize = -apparent*0.3;
EmitVertex();
EndPrimitive();
}