use of gaiasky.render.IRenderable in project gaiasky by langurmonkey.
the class LightPositionUpdater method run.
@Override
public void run(AbstractRenderSystem renderSystem, Array<IRenderable> renderables, ICamera camera) {
synchronized (lock) {
int size = renderables.size;
if (PostProcessorFactory.instance.getPostProcessor().isLightScatterEnabled()) {
Settings settings = Settings.settings;
// Compute light positions for light scattering or light
// glow
int lightIndex = 0;
float angleEdgeDeg = camera.getAngleEdge() * MathUtils.radDeg;
for (int i = size - 1; i >= 0; i--) {
IRenderable s = renderables.get(i);
if (s instanceof Star) {
Star p = (Star) s;
double angle = GaiaSky.instance.cameraManager.getDirection().angle(p.translation);
if (lightIndex < nLights && (settings.program.modeCubemap.active || settings.runtime.openVr || angle < angleEdgeDeg)) {
Vector3d pos3d = p.translation.put(auxD);
// Aberration
GlobalResources.applyRelativisticAberration(pos3d, camera);
// GravWaves
RelativisticEffectsManager.getInstance().gravitationalWavePos(pos3d);
Vector3 pos3 = pos3d.put(auxV);
float w = settings.graphics.resolution[0];
float h = settings.graphics.resolution[1];
camera.getCamera().project(pos3, 0, 0, w, h);
// Here we **need** to use
// Gdx.graphics.getWidth/Height() because we use
// camera.project() which uses screen
// coordinates only
positions[lightIndex * 2] = auxV.x / w;
positions[lightIndex * 2 + 1] = auxV.y / h;
viewAngles[lightIndex] = (float) p.viewAngleApparent;
colors[lightIndex * 3] = p.cc[0];
colors[lightIndex * 3 + 1] = p.cc[1];
colors[lightIndex * 3 + 2] = p.cc[2];
lightIndex++;
}
}
}
EventManager.publish(Event.LIGHT_POS_2D_UPDATE, this, lightIndex, positions, viewAngles, colors, glowTex);
} else {
EventManager.publish(Event.LIGHT_POS_2D_UPDATE, this, 0, positions, viewAngles, colors, glowTex);
}
}
}
use of gaiasky.render.IRenderable in project gaiasky by langurmonkey.
the class OrbitalElementsGroupRenderSystem method renderStud.
@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
for (IRenderable renderable : renderables) {
OrbitalElementsGroup oeg = (OrbitalElementsGroup) renderable;
if (!inGpu(oeg)) {
int n = oeg.children.size;
int offset = addMeshData(n * 4, n * 6);
setOffset(oeg, offset);
curr = meshes.get(offset);
ensureTempVertsSize(n * 4 * curr.vertexSize);
ensureTempIndicesSize(n * 6);
AtomicInteger numVerticesAdded = new AtomicInteger(0);
AtomicInteger numParticlesAdded = new AtomicInteger(0);
CatalogInfo ci = oeg.getCatalogInfo();
Array<SceneGraphNode> children = oeg.children;
children.forEach(child -> {
Orbit orbit = (Orbit) child;
OrbitComponent oc = orbit.oc;
// 4 vertices per particle
for (int vert = 0; vert < 4; vert++) {
// Vertex POSITION
tempVerts[curr.vertexIdx + posOffset] = vertPos[vert].getFirst();
tempVerts[curr.vertexIdx + posOffset + 1] = vertPos[vert].getSecond();
// UV coordinates
tempVerts[curr.vertexIdx + uvOffset] = vertUV[vert].getFirst();
tempVerts[curr.vertexIdx + uvOffset + 1] = vertUV[vert].getSecond();
// COLOR
float[] c = oeg.isHighlighted() && ci != null ? ci.getHlColor() : orbit.pointColor;
tempVerts[curr.vertexIdx + curr.colorOffset] = Color.toFloatBits(c[0], c[1], c[2], c[3]);
// ORBIT ELEMENTS 01
tempVerts[curr.vertexIdx + elems01Offset] = (float) Math.sqrt(oc.mu / Math.pow(oc.semimajoraxis * 1000d, 3d));
tempVerts[curr.vertexIdx + elems01Offset + 1] = (float) oc.epoch;
// In metres
tempVerts[curr.vertexIdx + elems01Offset + 2] = (float) (oc.semimajoraxis * 1000d);
tempVerts[curr.vertexIdx + elems01Offset + 3] = (float) oc.e;
// ORBIT ELEMENTS 02
tempVerts[curr.vertexIdx + elems02Offset] = (float) (oc.i * MathUtilsd.degRad);
tempVerts[curr.vertexIdx + elems02Offset + 1] = (float) (oc.ascendingnode * MathUtilsd.degRad);
tempVerts[curr.vertexIdx + elems02Offset + 2] = (float) (oc.argofpericenter * MathUtilsd.degRad);
tempVerts[curr.vertexIdx + elems02Offset + 3] = (float) (oc.meananomaly * MathUtilsd.degRad);
// SIZE
tempVerts[curr.vertexIdx + sizeOffset] = orbit.pointSize * (oeg.isHighlighted() && ci != null ? ci.hlSizeFactor : 1);
curr.vertexIdx += curr.vertexSize;
curr.numVertices++;
numVerticesAdded.incrementAndGet();
}
// Indices
quadIndices(curr);
numParticlesAdded.incrementAndGet();
setInGpu(orbit, true);
});
int count = numVerticesAdded.get() * curr.vertexSize;
setCount(oeg, count);
curr.mesh.setVertices(tempVerts, 0, count);
curr.mesh.setIndices(tempIndices, 0, numParticlesAdded.get() * 6);
setInGpu(oeg, true);
}
curr = meshes.get(getOffset(renderable));
if (curr != null) {
ExtShaderProgram shaderProgram = getShaderProgram();
shaderProgram.begin();
shaderProgram.setUniformMatrix("u_projView", camera.getCamera().combined);
shaderProgram.setUniformf("u_camPos", camera.getPos().put(aux1));
shaderProgram.setUniformf("u_alpha", alphas[renderable.getComponentType().getFirstOrdinal()] * renderable.getOpacity());
shaderProgram.setUniformf("u_falloff", 2.5f);
shaderProgram.setUniformf("u_sizeFactor", Settings.settings.scene.star.pointSize * 0.08f * oeg.getPointscaling());
shaderProgram.setUniformf("u_sizeLimits", (float) (particleSizeLimits[0]), (float) (particleSizeLimits[1]));
// VR scale
shaderProgram.setUniformf("u_vrScale", (float) Constants.DISTANCE_SCALE_FACTOR);
// Emulate double, for compatibility
double curRt = AstroUtils.getJulianDate(GaiaSky.instance.time.getTime());
float curRt1 = (float) curRt;
float curRt2 = (float) (curRt - (double) curRt1);
shaderProgram.setUniformf("u_t", curRt1, curRt2);
shaderProgram.setUniformMatrix("u_eclToEq", maux.setToRotation(0, 1, 0, -90).mul(Coordinates.equatorialToEclipticF()));
// Relativistic effects
addEffectsUniforms(shaderProgram, camera);
try {
curr.mesh.render(shaderProgram, GL20.GL_TRIANGLES);
} catch (IllegalArgumentException e) {
logger.error(e, "Render exception");
}
shaderProgram.end();
}
}
}
use of gaiasky.render.IRenderable in project gaiasky by langurmonkey.
the class ParticleGroupPointRenderSystem method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
if (event == Event.GPU_DISPOSE_PARTICLE_GROUP) {
IRenderable renderable = (IRenderable) source;
int offset = getOffset(renderable);
clearMeshData(offset);
inGpu.remove(renderable);
}
}
use of gaiasky.render.IRenderable in project gaiasky by langurmonkey.
the class ParticleGroupRenderSystem method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
if (event == Event.GPU_DISPOSE_PARTICLE_GROUP) {
IRenderable renderable = (IRenderable) source;
int offset = getOffset(renderable);
clearMeshData(offset);
inGpu.remove(renderable);
}
}
use of gaiasky.render.IRenderable in project gaiasky by langurmonkey.
the class ParticleGroupInstRenderSystem method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
if (event == Event.GPU_DISPOSE_PARTICLE_GROUP) {
IRenderable renderable = (IRenderable) source;
int offset = getOffset(renderable);
clearMeshData(offset);
if (inGpu != null)
inGpu.remove(renderable);
}
}
Aggregations