Initial tests for performance improvements.

This commit is contained in:
Jonathas Costa
2019-10-11 18:11:22 -04:00
parent 992a618e86
commit b591af3c2a
2 changed files with 23 additions and 22 deletions

View File

@@ -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});
}