Search in sources :

Example 1 with ExtShaderProgram

use of gaiasky.util.gdx.shader.ExtShaderProgram in project gaiasky by langurmonkey.

the class FontRenderSystem method renderStud.

@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
    renderables.sort(comp);
    batch.begin();
    int size = renderables.size;
    ExtShaderProgram program = programs[0];
    if (program == null) {
        for (int i = 0; i < size; i++) {
            IAnnotationsRenderable s = (IAnnotationsRenderable) renderables.get(i);
            // Render sprite
            s.render(batch, camera, font2d, getAlpha(s));
        }
    } else {
        renderFont3D(renderables, program, camera, alphas[ComponentType.Labels.ordinal()]);
    }
    batch.end();
}
Also used : ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram) IAnnotationsRenderable(gaiasky.render.IAnnotationsRenderable)

Example 2 with ExtShaderProgram

use of gaiasky.util.gdx.shader.ExtShaderProgram in project gaiasky by langurmonkey.

the class InstancedRenderSystem method renderStud.

@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
    if (renderables.size > 0) {
        ExtShaderProgram shaderProgram = getShaderProgram();
        shaderProgram.begin();
        // Pre-render
        preRenderObjects(shaderProgram, camera);
        // Render
        renderables.forEach((r) -> renderObject(shaderProgram, r));
        // Post-render
        postRenderObjects(shaderProgram, camera);
        shaderProgram.end();
    }
}
Also used : ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram)

Example 3 with ExtShaderProgram

use of gaiasky.util.gdx.shader.ExtShaderProgram 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();
        }
    }
}
Also used : OrbitalElementsGroup(gaiasky.scenegraph.OrbitalElementsGroup) IRenderable(gaiasky.render.IRenderable) Orbit(gaiasky.scenegraph.Orbit) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram) OrbitComponent(gaiasky.scenegraph.component.OrbitComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CatalogInfo(gaiasky.util.CatalogInfo)

Example 4 with ExtShaderProgram

use of gaiasky.util.gdx.shader.ExtShaderProgram in project gaiasky by langurmonkey.

the class OrbitalElementsParticlesRenderSystem method renderStud.

@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
    int n = renderables.size;
    if (n > 0 && renderables.get(0).getOpacity() > 0) {
        Orbit first = (Orbit) renderables.get(0);
        if (forceAdd || !inGpu(first)) {
            forceAdd = false;
            curr = meshes.get(addMeshData(n * 4, n * 6));
            ensureTempVertsSize(n * 4 * curr.vertexSize);
            ensureTempIndicesSize(n * 6);
            AtomicInteger numVerticesAdded = new AtomicInteger(0);
            AtomicInteger numParticlesAdded = new AtomicInteger(0);
            renderables.forEach(renderable -> {
                Orbit orbitElems = (Orbit) renderable;
                if (!inGpu(orbitElems)) {
                    OrbitComponent oc = orbitElems.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
                        tempVerts[curr.vertexIdx + curr.colorOffset] = Color.toFloatBits(orbitElems.pointColor[0], orbitElems.pointColor[1], orbitElems.pointColor[2], orbitElems.pointColor[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] = orbitElems.pointSize;
                        curr.vertexIdx += curr.vertexSize;
                        curr.numVertices++;
                        numVerticesAdded.incrementAndGet();
                    }
                    // Indices
                    quadIndices(curr);
                    numParticlesAdded.incrementAndGet();
                    setInGpu(orbitElems, true);
                }
            });
            int count = numVerticesAdded.get() * curr.vertexSize;
            curr.mesh.setVertices(tempVerts, 0, count);
            curr.mesh.setIndices(tempIndices, 0, numParticlesAdded.get() * 6);
        }
        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[first.ct.getFirstOrdinal()] * first.getOpacity());
            shaderProgram.setUniformf("u_falloff", 2.5f);
            shaderProgram.setUniformf("u_sizeFactor", Settings.settings.scene.star.pointSize * 0.08f);
            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();
        }
    }
}
Also used : OrbitComponent(gaiasky.scenegraph.component.OrbitComponent) Orbit(gaiasky.scenegraph.Orbit) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram)

Example 5 with ExtShaderProgram

use of gaiasky.util.gdx.shader.ExtShaderProgram in project gaiasky by langurmonkey.

the class ParticleEffectsRenderSystem method renderStud.

@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
    float alpha = getAlpha(ct);
    if (alpha > 0) {
        updatePositions(camera);
        // Regular
        Gdx.gl.glLineWidth(2f);
        if (curr != null) {
            curr.vertexIdx = 0;
            curr.numVertices = N_PARTICLES * 2;
            for (int i = 0; i < N_PARTICLES * 2; i++) {
                // COLOR
                curr.vertices[curr.vertexIdx + curr.colorOffset] = additional[i].x;
                // SIZE
                curr.vertices[curr.vertexIdx + sizeOffset] = additional[i].y;
                // T
                curr.vertices[curr.vertexIdx + tOffset] = additional[i].z;
                // POSITION
                curr.vertices[curr.vertexIdx] = positions[i].x;
                curr.vertices[curr.vertexIdx + 1] = positions[i].y;
                curr.vertices[curr.vertexIdx + 2] = positions[i].z;
                curr.vertexIdx += curr.vertexSize;
            }
            // RENDER
            ExtShaderProgram shaderProgram = getShaderProgram();
            shaderProgram.begin();
            shaderProgram.setUniformMatrix("u_projView", camera.getCamera().combined);
            shaderProgram.setUniformf("u_camPos", camera.getCurrent().getPos().put(aux1f));
            shaderProgram.setUniformf("u_alpha", alpha * 0.6f);
            shaderProgram.setUniformf("u_sizeFactor", rc.scaleFactor);
            shaderProgram.setUniformf("u_t", getT());
            shaderProgram.setUniformf("u_ttl", 0.5f);
            // Relativistic effects
            addEffectsUniforms(shaderProgram, camera);
            curr.mesh.setVertices(curr.vertices, 0, N_PARTICLES * 2 * curr.vertexSize);
            curr.mesh.render(shaderProgram, GL20.GL_LINES);
            shaderProgram.end();
        }
    }
}
Also used : ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram)

Aggregations

ExtShaderProgram (gaiasky.util.gdx.shader.ExtShaderProgram)12 Orbit (gaiasky.scenegraph.Orbit)3 IQuadRenderable (gaiasky.render.IQuadRenderable)2 OrbitComponent (gaiasky.scenegraph.component.OrbitComponent)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PointCloudData (gaiasky.data.util.PointCloudData)1 IAnnotationsRenderable (gaiasky.render.IAnnotationsRenderable)1 ILineRenderable (gaiasky.render.ILineRenderable)1 IPointRenderable (gaiasky.render.IPointRenderable)1 IRenderable (gaiasky.render.IRenderable)1 OrbitalElementsGroup (gaiasky.scenegraph.OrbitalElementsGroup)1 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)1 CatalogInfo (gaiasky.util.CatalogInfo)1 Vector3d (gaiasky.util.math.Vector3d)1