Another fix for RenderableStars; to be replaced when the ScaleGraph is in place

This commit is contained in:
Alexander Bock
2015-02-16 19:04:42 +01:00
parent 3c4aec0082
commit 6791fe52f7
4 changed files with 131 additions and 28 deletions

View File

@@ -71,11 +71,28 @@ void main() {
break;
}
vec4 fullColor = texture(psfTexture, texCoord) * color;
// This check can be removed once we get a better star psf texture ---abock
if (fullColor.a <= 0.1)
// These can be removed once we get a better star psf texture ---abock
vec4 textureColor = texture(psfTexture, texCoord);
textureColor.a = (textureColor.a - 0.25) / (0.75);
vec4 fullColor = textureColor * color;
if (fullColor.a <= 0.125)
discard;
float M = ge_brightness.z;
// if (M > 10)
// discard;
float targetM = 6.0;
float maxM = 12.0;
if (M > targetM) {
float alpha = (M - targetM) / (maxM - targetM);
fullColor.a *= alpha;
}
// if (ge_brightness.z > 7.0)
// discard;
vec4 position = vs_position;
// This has to be fixed when the scale graph is in place ---abock
float depth = pscDepth(position) + 1000;

View File

@@ -49,13 +49,41 @@ layout(location = 2) out vec3 ge_velocity;
layout(location = 3) out float ge_speed;
layout(location = 4) out vec2 texCoord;
// layout(location = 5) out vec4 p;
uniform mat4 projection; // we do this after distance computation.
uniform mat4 projection;
uniform float spriteBaseSize;
uniform float spriteResponseSize;
// As soon as the scalegraph is in place, replace this by a dynamic calculation
// of apparent magnitude in relation to the camera position ---abock
void main() {
// Skip the Sun
if (psc_position[0].x == 0.0 && psc_position[0].y == 0.0 && psc_position[0].z == 0.0) {
return;
}
ge_brightness = vs_brightness[0];
ge_velocity = vs_velocity[0];
ge_speed = vs_speed[0];
float M = vs_brightness[0].z;
M = clamp(M, 1.0, 5.0);
float modifiedSpriteSize = exp((-18 - M) * 0.871) * 200000 ;
for(int i = 0; i < 4; i++){
vec4 p1 = gl_in[0].gl_Position;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
vs_position = p1;
gl_Position = projection * p1;
// gl_Position = z_normalization(projection * p1);
texCoord = corners[i];
EmitVertex();
}
EndPrimitive();
}
// Old method, still in the code for reference ---abock
#if 0
void main() {
ge_brightness = vs_brightness[0];
ge_velocity = vs_velocity[0];
@@ -66,19 +94,20 @@ void main() {
// We are using a fixed position until the scalegraph is implemented ---abock
// vec4 cam = vec4(-cam_position[0].xyz, cam_position[0].w); // get negative camera position
vec4 cam = vec4(0.0);
// vec4 cam = vec4(0.0);
vec4 pos = psc_position[0]; // get OK star position
vec4 result = psc_addition(pos, cam); // compute vec from camera to position
// vec4 result = psc_addition(pos, cam); // compute vec from camera to position
vec4 result = pos;
vec2 pc = vec2(
length(result.xyz),
result.w
);
// convert meters into parsecs
pc[0] *= 0.324077929f;
pc[1] -= 18.0f;
// pc[0] *= 0.324077929f;
// pc[1] -= 18.0f;
float distLog = log10(pc[0]) + pc[1];
float apparent = (M - 5.f * (1.f - distLog));
@@ -93,15 +122,48 @@ void main() {
double modifiedSpriteSize = (spriteBaseSize * 0.0005f) + (depth*weight);
modifiedSpriteSize *= spriteResponseSize;
// // modifiedSpriteSize = min(modifiedSpriteSize, -0.0025f);
// {
// vec4 p = gl_in[0].gl_Position;
// p.xy += vec2(modifiedSpriteSize * (corners[1] - vec2(0.5)));
// p = projection * p;
// vec4 q = gl_in[0].gl_Position;
// q.xy += vec2(modifiedSpriteSize * (corners[2] - vec2(0.5)));
// q = projection * q;
// if (length(p.xyz-q.xyz) < 0.025)
// return;
// // if (sin(dot(p,q)) < 0.1)
// // return;
// }
// if (depth < -0.00000001)
// return;
// float distLy = vs_brightness[0].w;
// float distParsec = distLy * 0.306594845;
// if (distParsec > 200 && -apparent > 1.0)
// return;
for(int i = 0; i < 4; i++){
vec4 p1 = gl_in[0].gl_Position;
vec4 p1 = gl_in[0].gl_Position;
// vec4 p1 = psc_position[0];
p1.w = 1.0;
// p1.w = 1.0;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
vs_position = p1;
gl_Position = projection * p1;
// gl_Position = z_normalization(projection * p1);
texCoord = corners[i];
// p = psc_position[0];
// gl_Position = p1;
// if (modifiedSpriteSize > -0.001f)
// texCoord = vec2(0.5);
// else
texCoord = corners[i];
EmitVertex();
}
EndPrimitive();
}
}
#endif

View File

@@ -42,13 +42,14 @@ layout(location = 4) out vec4 cam_position;
#include "PowerScaling/powerScaling_vs.hglsl"
void main() {
psc_position = in_position;
vec4 p = in_position;
psc_position = p;
vs_brightness = in_brightness;
vs_velocity = in_velocity;
vs_speed = in_speed;
cam_position = campos;
vec4 tmp = in_position;
vec4 tmp = p;
vec4 position = pscTransform(tmp, mat4(1.0));
// vec4 position = pscTransform(tmp, model);
// psc_position = tmp;

View File

@@ -476,18 +476,40 @@ bool RenderableStars::saveCachedFile(const std::string& file) const {
void RenderableStars::createDataSlice(ColorOption option) {
_slicedData.clear();
// This is only temporary until the scalegraph is in place ---abock
float minDistance = std::numeric_limits<float>::max();
float maxDistance = -std::numeric_limits<float>::max();
for (size_t i = 0; i < _fullData.size(); i+=_nValuesPerStar) {
float distLy = _fullData[i + 6];
//if (distLy < 20.f) {
minDistance = std::min(minDistance, distLy);
maxDistance = std::max(maxDistance, distLy);
//}
}
for (size_t i = 0; i < _fullData.size(); i+=_nValuesPerStar) {
psc position = PowerScaledCoordinate::CreatePowerScaledCoordinate(
_fullData[i + 0],
_fullData[i + 1],
_fullData[i + 2]
);
// This is only temporary until the scalegraph is in place. It places all stars
// on a sphere with a small variation in the distance to account for blending
// issues ---abock
glm::vec3 p = glm::vec3(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2]);
if (p != glm::vec3(0.f))
p = glm::normalize(p);
float distLy = _fullData[i + 6];
float normalizedDist = (distLy - minDistance) / (maxDistance - minDistance);
float distance = 18.f - normalizedDist / 2.f ;
psc position = psc(glm::vec4(p, distance));
// Convert parsecs -> meter
PowerScaledScalar parsecsToMetersFactor = PowerScaledScalar(0.308567758f, 17.f);
position[0] *= parsecsToMetersFactor[0];
position[1] *= parsecsToMetersFactor[0];
position[2] *= parsecsToMetersFactor[0];
position[3] += parsecsToMetersFactor[1];
//PowerScaledScalar parsecsToMetersFactor = PowerScaledScalar(0.308567758f, 17.f);
//position[0] *= parsecsToMetersFactor[0];
//position[1] *= parsecsToMetersFactor[0];
//position[2] *= parsecsToMetersFactor[0];
//position[3] += parsecsToMetersFactor[1];
switch (option) {
case ColorOption::Color:
@@ -503,7 +525,8 @@ void RenderableStars::createDataSlice(ColorOption option) {
layout.value.bvColor = _fullData[i + 3];
layout.value.luminance = _fullData[i + 4];
layout.value.absoluteMagnitude = _fullData[i + 5];
//layout.value.absoluteMagnitude = _fullData[i + 5];
layout.value.absoluteMagnitude = _fullData[i + 6];
_slicedData.insert(_slicedData.end(),
layout.data.begin(),