Skip to content

Commit 5a64912

Browse files
committed
Improve quality of planetary ring edges
1 parent a195de0 commit 5a64912

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

data/shaders/planet.frag

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,24 @@ void main()
349349
//apply texture-colored rimlight
350350
//litColor.xyz = clamp( litColor.xyz + vec3(outgas), 0.0, 1.0);
351351

352-
lowp vec4 texColor = texture2D(tex, texc);
352+
lowp vec4 texColor;
353+
#ifdef RINGS_SUPPORT
354+
if(isRing)
355+
{
356+
float radius = length(texc);
357+
float s = (radius - innerRadius) / (outerRadius - innerRadius);
358+
vec2 texCoord = vec2(s, 0.5);
359+
texColor = texture2D(tex, texCoord);
360+
// Guard against poor quality mipmap filtering (e.g. Mesa with NPOT textures).
361+
if(radius > outerRadius)
362+
texColor = vec4(0);
363+
}
364+
else
365+
#endif
366+
{
367+
texColor = texture2D(tex, texc);
368+
}
369+
353370
#ifdef IS_MOON
354371
// Undo the extraneous gamma encoded in the texture.
355372
// FIXME: ideally, we want all the calculations to be done in linear scale,

src/core/modules/Planet.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,13 +3754,12 @@ void sRing(Ring3DModel* model, const float rMin, const float rMax, unsigned shor
37543754
float r = rMin;
37553755
for (unsigned short int i=0; i<=stacks; ++i)
37563756
{
3757-
const float tex_r0 = (r-rMin)/(rMax-rMin);
37583757
unsigned short int j;
37593758
for (j=0,cos_sin_theta_p=cos_sin_theta; j<=slices; ++j,cos_sin_theta_p+=2)
37603759
{
37613760
x = r*cos_sin_theta_p[0];
37623761
y = r*cos_sin_theta_p[1];
3763-
model->texCoordArr << tex_r0 << 0.5f;
3762+
model->texCoordArr << x << y;
37643763
model->vertexArr << x << y << 0.f;
37653764
}
37663765
r+=dr;
@@ -4125,6 +4124,8 @@ void Planet::drawSphere(StelPainter* painter, float screenRd, bool drawOnlyRing)
41254124
GL(ringPlanetShaderProgram->setUniformValue(ringPlanetShaderVars.isRing, true));
41264125
GL(ringPlanetShaderProgram->setUniformValue(ringPlanetShaderVars.tex, 2));
41274126
GL(ringPlanetShaderProgram->setUniformValue(ringPlanetShaderVars.ringS, 1));
4127+
GL(ringPlanetShaderProgram->setUniformValue(ringPlanetShaderVars.outerRadius, rings->radiusMax));
4128+
GL(ringPlanetShaderProgram->setUniformValue(ringPlanetShaderVars.innerRadius, rings->radiusMin));
41284129

41294130
QMatrix4x4 shadowCandidatesData;
41304131
const Vec4d position = rData.mTarget * rData.modelMatrix.getColumn(3);

0 commit comments

Comments
 (0)