Search in sources :

Example 1 with AtmosphereAttribute

use of gaiasky.util.gdx.shader.attribute.AtmosphereAttribute in project gaiasky by langurmonkey.

the class AtmosphereComponent method setUpAtmosphericScatteringMaterial.

/**
 * Sets up the atmospheric scattering parameters to the given material
 *
 * @param mat The material to set up.
 */
public void setUpAtmosphericScatteringMaterial(Material mat) {
    float camHeight = 1f;
    float m_Kr4PI = m_Kr * 4.0f * (float) Math.PI;
    float m_Km4PI = m_Km * 4.0f * (float) Math.PI;
    // Sun brightness (almost) constant
    float m_ESun = m_eSun;
    // The Mie phase asymmetry factor
    float m_g = 0.97f;
    m_fInnerRadius = planetSize / 2f;
    m_fOuterRadius = this.size;
    m_fAtmosphereHeight = m_fOuterRadius - m_fInnerRadius;
    float m_fScaleDepth = .20f;
    float m_fScale = 1.0f / (m_fAtmosphereHeight);
    float m_fScaleOverScaleDepth = m_fScale / m_fScaleDepth;
    int m_nSamples = 11;
    double[] m_fWavelength = wavelengths;
    float[] m_fWavelength4 = new float[3];
    m_fWavelength4[0] = (float) Math.pow(m_fWavelength[0], 4.0);
    m_fWavelength4[1] = (float) Math.pow(m_fWavelength[1], 4.0);
    m_fWavelength4[2] = (float) Math.pow(m_fWavelength[2], 4.0);
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.Alpha, 1f));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.ColorOpacity, 1f));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.CameraHeight, camHeight));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.OuterRadius, m_fOuterRadius));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.InnerRadius, m_fInnerRadius));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.KrESun, m_Kr * m_ESun));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.KmESun, m_Km * m_ESun));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.Kr4PI, m_Kr4PI));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.Km4PI, m_Km4PI));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.Scale, m_fScale));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.ScaleDepth, m_fScaleDepth));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.ScaleOverScaleDepth, m_fScaleOverScaleDepth));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.nSamples, m_nSamples));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.FogDensity, fogDensity));
    mat.set(new Vector3Attribute(Vector3Attribute.FogColor, fogColor));
    mat.set(new AtmosphereAttribute(AtmosphereAttribute.G, m_g));
    mat.set(new Vector3Attribute(Vector3Attribute.PlanetPos, new Vector3()));
    mat.set(new Vector3Attribute(Vector3Attribute.CameraPos, new Vector3()));
    mat.set(new Vector3Attribute(Vector3Attribute.LightPos, new Vector3()));
    mat.set(new Vector3Attribute(Vector3Attribute.InvWavelength, new Vector3(1.0f / m_fWavelength4[0], 1.0f / m_fWavelength4[1], 1.0f / m_fWavelength4[2])));
}
Also used : Vector3Attribute(gaiasky.util.gdx.shader.attribute.Vector3Attribute) Vector3(com.badlogic.gdx.math.Vector3) AtmosphereAttribute(gaiasky.util.gdx.shader.attribute.AtmosphereAttribute)

Example 2 with AtmosphereAttribute

use of gaiasky.util.gdx.shader.attribute.AtmosphereAttribute in project gaiasky by langurmonkey.

the class AtmosphereComponent method updateAtmosphericScatteringParams.

/**
 * Updates the atmospheric scattering shader parameters
 *
 * @param mat    The material to update.
 * @param alpha  The opacity value.
 * @param ground Whether it is the ground shader or the atmosphere.
 * @param planet The planet itself, holder of this atmosphere
 */
public void updateAtmosphericScatteringParams(Material mat, float alpha, boolean ground, Planet planet, Vector3d vrOffset) {
    Vector3b transform = planet.translation;
    RotationComponent rc = planet.rc;
    SceneGraphNode sol = planet.parent;
    transform.put(aux3);
    if (vrOffset != null) {
        aux1.set(vrOffset).scl(1 / Constants.M_TO_U);
        aux3.sub(aux1);
    }
    // Distance to planet
    float camHeight = (float) (aux3.len());
    float m_ESun = m_eSun;
    float camHeightGr = camHeight - m_fInnerRadius;
    float atmFactor = (m_fAtmosphereHeight - camHeightGr) / m_fAtmosphereHeight;
    if (!ground && camHeightGr < m_fAtmosphereHeight) {
        // Camera inside atmosphere
        m_ESun += atmFactor * 100f;
    }
    // These are here to get the desired effect inside the atmosphere
    if (mat.has(AtmosphereAttribute.KrESun))
        ((AtmosphereAttribute) mat.get(AtmosphereAttribute.KrESun)).value = m_Kr * m_ESun;
    else
        mat.set(new AtmosphereAttribute(AtmosphereAttribute.KrESun, m_Kr * m_ESun));
    if (mat.has(AtmosphereAttribute.KmESun))
        ((AtmosphereAttribute) mat.get(AtmosphereAttribute.KmESun)).value = m_Km * m_ESun;
    else
        mat.set(new AtmosphereAttribute(AtmosphereAttribute.KmESun, m_Km * m_ESun));
    // Camera height
    if (mat.has(AtmosphereAttribute.CameraHeight))
        ((AtmosphereAttribute) mat.get(AtmosphereAttribute.CameraHeight)).value = camHeight;
    else
        mat.set(new AtmosphereAttribute(AtmosphereAttribute.CameraHeight, camHeight));
    // Planet position
    if (ground) {
        // Camera position must be corrected using the rotation angle of the planet
        aux3.mul(Coordinates.getTransformD(planet.inverseRefPlaneTransform)).rotate(rc.ascendingNode, 0, 1, 0).rotate(-rc.inclination - rc.axialTilt, 0, 0, 1).rotate(-rc.angle, 0, 1, 0);
    }
    ((Vector3Attribute) mat.get(Vector3Attribute.PlanetPos)).value.set(aux3.put(aux));
    // CameraPos = -PlanetPos
    aux3.scl(-1f);
    ((Vector3Attribute) mat.get(Vector3Attribute.CameraPos)).value.set(aux3.put(aux));
    // Light position respect the earth: LightPos = SunPos - EarthPos
    aux3.add(sol.translation).nor();
    if (ground) {
        // Camera position must be corrected using the rotation angle of the planet
        aux3.mul(Coordinates.getTransformD(planet.inverseRefPlaneTransform)).rotate(rc.ascendingNode, 0, 1, 0).rotate(-rc.inclination - rc.axialTilt, 0, 0, 1).rotate(-rc.angle, 0, 1, 0);
    }
    ((Vector3Attribute) mat.get(Vector3Attribute.LightPos)).value.set(aux3.put(aux));
    // Alpha value
    ((AtmosphereAttribute) mat.get(AtmosphereAttribute.Alpha)).value = alpha;
}
Also used : Vector3b(gaiasky.util.math.Vector3b) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) AtmosphereAttribute(gaiasky.util.gdx.shader.attribute.AtmosphereAttribute)

Aggregations

AtmosphereAttribute (gaiasky.util.gdx.shader.attribute.AtmosphereAttribute)2 Vector3 (com.badlogic.gdx.math.Vector3)1 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)1 Vector3Attribute (gaiasky.util.gdx.shader.attribute.Vector3Attribute)1 Vector3b (gaiasky.util.math.Vector3b)1