mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-03 18:19:38 -06:00
Initial tests for performance improvements.
This commit is contained in:
@@ -29,17 +29,18 @@ uniform float absorptionMultiply#{id} = 50.0;
|
||||
uniform float emissionMultiply#{id} = 1500.0;
|
||||
uniform sampler3D galaxyTexture#{id};
|
||||
|
||||
void sample#{id}(vec3 samplePos,
|
||||
void sample#{id}(
|
||||
vec3 samplePos,
|
||||
vec3 dir,
|
||||
inout vec3 accumulatedColor,
|
||||
inout vec3 accumulatedAlpha,
|
||||
inout float stepSize)
|
||||
{
|
||||
inout float stepSize
|
||||
) {
|
||||
vec3 aspect = aspect#{id};
|
||||
stepSize = maxStepSize#{id} / length(dir / aspect);
|
||||
|
||||
//Early ray termination on black parts of the data
|
||||
vec3 normalizedPos = samplePos*2.0 - 1.0;
|
||||
vec3 normalizedPos = samplePos * 2.f - 1.f;
|
||||
if (normalizedPos.x * normalizedPos.x + normalizedPos.y * normalizedPos.y > 0.7) {
|
||||
return;
|
||||
}
|
||||
@@ -51,12 +52,12 @@ void sample#{id}(vec3 samplePos,
|
||||
sampledColor = sampledColor*sampledColor;
|
||||
|
||||
// Fudge for the dust "spreading"
|
||||
sampledColor.a = clamp(sampledColor.a, 0.0, 1.0);
|
||||
sampledColor.a = pow(sampledColor.a, 0.7);
|
||||
sampledColor.a = clamp(sampledColor.a, 0.f, 1.f);
|
||||
sampledColor.a = pow(sampledColor.a, 0.7f);
|
||||
|
||||
// Absorption probability
|
||||
float scaledDensity = sampledColor.a * stepSize * absorptionMultiply#{id};
|
||||
vec3 alphaTint = vec3(0.3, 0.54, 0.85);
|
||||
vec3 alphaTint = vec3(0.3f, 0.54f, 0.85f);
|
||||
vec3 absorption = alphaTint * scaledDensity;
|
||||
|
||||
// Extinction
|
||||
@@ -67,10 +68,10 @@ void sample#{id}(vec3 samplePos,
|
||||
accumulatedColor.rgb +=
|
||||
sampledColor.rgb * stepSize * emissionMultiply#{id} * opacityCoefficient#{id};
|
||||
|
||||
vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha;
|
||||
vec3 oneMinusFrontAlpha = vec3(1.f) - accumulatedAlpha;
|
||||
accumulatedAlpha += oneMinusFrontAlpha * sampledColor.rgb * opacityCoefficient#{id};
|
||||
}
|
||||
|
||||
float stepSize#{id}(vec3 samplePos, vec3 dir) {
|
||||
return maxStepSize#{id} * length(dir * 1.0 / aspect#{id});
|
||||
return maxStepSize#{id} * length(dir * 1.f / aspect#{id});
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ uniform vec2 windowSize;
|
||||
out vec4 finalColor;
|
||||
|
||||
#define ALPHA_LIMIT 0.99
|
||||
#define RAYCAST_MAX_STEPS 1000
|
||||
#define RAYCAST_MAX_STEPS 480
|
||||
|
||||
#include <#{getEntryPath}>
|
||||
|
||||
@@ -55,7 +55,7 @@ void main() {
|
||||
vec4 exitColorTexture = texture(exitColorTexture, texCoord);
|
||||
|
||||
// If we don't have an exit, discard the ray
|
||||
if (exitColorTexture.a < 1.0 || exitColorTexture.rgb == vec3(0.0)) {
|
||||
if (exitColorTexture.a < 1.f || exitColorTexture.rgb == vec3(0.f)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
@@ -63,13 +63,13 @@ void main() {
|
||||
vec3 exitPos = exitColorTexture.rgb;
|
||||
float exitDepth = denormalizeFloat(texture(exitDepthTexture, texCoord).x);
|
||||
|
||||
float jitterFactor = 0.5 + 0.5 * rand(gl_FragCoord.xy); // should be between 0.5 and 1.0
|
||||
float jitterFactor = 0.5f + 0.5f * rand(gl_FragCoord.xy); // should be between 0.5 and 1.0
|
||||
|
||||
vec3 entryPos;
|
||||
float entryDepth;
|
||||
getEntry(entryPos, entryDepth);
|
||||
// If we don't have an entry, discard the ray
|
||||
if (entryPos == vec3(0.0)) {
|
||||
if (entryPos == vec3(0.f)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
@@ -80,21 +80,21 @@ void main() {
|
||||
float raycastDepth = length(diff);
|
||||
|
||||
float geoDepth = denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), 0).x);
|
||||
float geoRatio = clamp((geoDepth - entryDepth) / (exitDepth - entryDepth), 0.0, 1.0);
|
||||
float geoRatio = clamp((geoDepth - entryDepth) / (exitDepth - entryDepth), 0.f, 1.f);
|
||||
raycastDepth = geoRatio * raycastDepth;
|
||||
|
||||
float currentDepth = 0.0;
|
||||
float currentDepth = 0.f;
|
||||
float nextStepSize = stepSize#{id}(position, direction);
|
||||
float currentStepSize;
|
||||
float previousJitterDistance = 0.0;
|
||||
float previousJitterDistance = 0.f;
|
||||
|
||||
int nSteps = 0;
|
||||
|
||||
int sampleIndex = 0;
|
||||
float opacityDecay = 1.0;
|
||||
float opacityDecay = 1.f;
|
||||
|
||||
vec3 accumulatedColor = vec3(0.0);
|
||||
vec3 accumulatedAlpha = vec3(0.0);
|
||||
vec3 accumulatedColor = vec3(0.f);
|
||||
vec3 accumulatedAlpha = vec3(0.f);
|
||||
|
||||
|
||||
for (nSteps = 0;
|
||||
@@ -102,7 +102,7 @@ void main() {
|
||||
accumulatedAlpha.b < ALPHA_LIMIT) && nSteps < RAYCAST_MAX_STEPS;
|
||||
++nSteps)
|
||||
{
|
||||
if (nextStepSize < raycastDepth / 10000000000.0) {
|
||||
if (nextStepSize < raycastDepth / 10000000000.f) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ void main() {
|
||||
currentDepth += currentStepSize;
|
||||
|
||||
float jitteredStepSize = currentStepSize * jitterFactor;
|
||||
vec3 jitteredPosition = position + direction*jitteredStepSize;
|
||||
vec3 jitteredPosition = position + direction * jitteredStepSize;
|
||||
position += direction * currentStepSize;
|
||||
|
||||
sample#{id}(jitteredPosition, direction, accumulatedColor, accumulatedAlpha, nextStepSize);
|
||||
@@ -122,7 +122,7 @@ void main() {
|
||||
nextStepSize = min(nextStepSize, maxStepSize);
|
||||
}
|
||||
|
||||
finalColor = vec4(accumulatedColor, (accumulatedAlpha.r + accumulatedAlpha.g + accumulatedAlpha.b) / 3);
|
||||
finalColor = vec4(accumulatedColor, (accumulatedAlpha.r + accumulatedAlpha.g + accumulatedAlpha.b) / 3.f);
|
||||
|
||||
finalColor.rgb /= finalColor.a ;
|
||||
gl_FragDepth = normalizeFloat(entryDepth);
|
||||
|
||||
Reference in New Issue
Block a user