Visual artifact fixes for Erekir core units + orbit rendering tweaks
|
Before Width: | Height: | Size: 840 B After Width: | Height: | Size: 856 B |
|
Before Width: | Height: | Size: 517 B After Width: | Height: | Size: 498 B |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 848 B After Width: | Height: | Size: 863 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@@ -10,6 +10,7 @@ varying vec2 v_texCoords;
|
||||
|
||||
const float mscl = 40.0;
|
||||
const float mth = 7.0;
|
||||
const float aa = 1.0;
|
||||
|
||||
void main(){
|
||||
|
||||
@@ -22,16 +23,21 @@ void main(){
|
||||
vec4 sampled = texture2D(u_texture, c + vec2(sin(stime/3.0 + coords.y/0.75) * v.x, 0.0));
|
||||
vec3 color = sampled.rgb * vec3(0.9, 0.9, 1);
|
||||
|
||||
float tester = mod((coords.x + coords.y*1.1 + sin(stime / 8.0 + coords.x/5.0 - coords.y/100.0)*2.0) +
|
||||
sin(stime / 20.0 + coords.y/3.0) * 1.0 +
|
||||
sin(stime / 10.0 - coords.y/2.0) * 2.0 +
|
||||
sin(stime / 7.0 + coords.y/1.0) * 0.5 +
|
||||
sin(coords.x / 3.0 + coords.y / 2.0) +
|
||||
sin(stime / 20.0 + coords.x/4.0) * 1.0, mscl);
|
||||
float t = (coords.x + coords.y*1.1 + sin(stime / 8.0 + coords.x/5.0 - coords.y/100.0)*2.0) +
|
||||
sin(stime / 20.0 + coords.y/3.0) * 1.0 +
|
||||
sin(stime / 10.0 - coords.y/2.0) * 2.0 +
|
||||
sin(stime / 7.0 + coords.y/1.0) * 0.5 +
|
||||
sin(coords.x / 3.0 + coords.y / 2.0) +
|
||||
sin(stime / 20.0 + coords.x/4.0) * 1.0;
|
||||
|
||||
if(tester < mth){
|
||||
color *= 1.2;
|
||||
}
|
||||
// signed distance to the middle of the band, wrapped into [-mscl/2, mscl/2)
|
||||
float d = mod(t - mth * 0.5 + mscl * 0.5, mscl) - mscl * 0.5;
|
||||
|
||||
// half-width of the ramp in tester units = half of aa pixels
|
||||
float w = max(fwidth(t) * aa * 0.5, 1e-4);
|
||||
|
||||
float lit = 1.0 - smoothstep(mth * 0.5 - w, mth * 0.5 + w, abs(d));
|
||||
color *= mix(1.0, 1.2, lit);
|
||||
|
||||
gl_FragColor = vec4(color.rgb, min(sampled.a * 100.0, 1.0));
|
||||
}
|
||||
|
||||
@@ -41,6 +41,9 @@ public class PlanetRenderer implements Disposable{
|
||||
|
||||
private final FrameBuffer framebuffer = new FrameBuffer(Format.defaultColorDepth);
|
||||
|
||||
/** Distance from the orbiting planet's surface (in world units) over which the orbit ring fades in, so it doesn't cut harshly into the planet. */
|
||||
public float orbitFadeDistance = 1.1f;
|
||||
|
||||
public PlanetRenderer(){
|
||||
projector.setScaling(1f / 150f);
|
||||
cam.fov = 60f;
|
||||
@@ -192,11 +195,25 @@ public class PlanetRenderer implements Disposable{
|
||||
|
||||
Vec3 center = planet.parent.position;
|
||||
float radius = planet.orbitRadius;
|
||||
int points = (int)(radius * 10);
|
||||
Angles.circleVectors(points, radius, (cx, cy) -> batch.vertex(Tmp.v32.set(center).add(cx, 0, cy), Pal.gray.write(Tmp.c1).a(params.uiAlpha)));
|
||||
//a line loop can't be split across flushes, so cap the point count at the batch size
|
||||
int points = Math.min((int)(radius * 10), batch.getMaxVertices());
|
||||
|
||||
for(int i = 0; i < points; i++){
|
||||
float angle = i / (float)points * Mathf.PI2;
|
||||
float x = center.x + Mathf.cos(angle) * radius, z = center.z + Mathf.sin(angle) * radius;
|
||||
|
||||
batch.vertex(x, center.y, z, orbitColor(planet, x, center.y, z, params.uiAlpha));
|
||||
}
|
||||
|
||||
batch.flush(Gl.lineLoop);
|
||||
}
|
||||
|
||||
/** @return packed color bits for an orbit vertex at the specified position. Fades to nothing at the surface of the orbiting planet, reaching full alpha {@link #orbitFadeDistance} away from it. */
|
||||
private float orbitColor(Planet planet, float x, float y, float z, float alpha){
|
||||
float fade = Mathf.clamp((planet.position.dst(x, y, z) - (planet.radius + 0.85f)) / Math.max(orbitFadeDistance, 0.0001f));
|
||||
return Color.toFloatBits(Pal.gray.r, Pal.gray.g, Pal.gray.b, alpha * fade);
|
||||
}
|
||||
|
||||
public void renderSectors(Planet planet, PlanetParams params){
|
||||
if(params.uiAlpha <= 0.02f) return;
|
||||
planet.renderSectors(batch, cam, params);
|
||||
@@ -297,4 +314,4 @@ public class PlanetRenderer implements Disposable{
|
||||
void renderProjections(Planet planet);
|
||||
default void renderOverProjections(Planet planet){}
|
||||
}
|
||||
}
|
||||
}
|
||||