Search in sources :

Example 16 with Material

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

the class AtmosphereComponent method doneLoading.

public void doneLoading(Material planetMat, float planetSize) {
    this.planetSize = planetSize;
    setUpAtmosphericScatteringMaterial(planetMat);
    Material atmMat;
    if (mc.instance == null) {
        Pair<IntModel, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Bits.indexes(Usage.Position, Usage.Normal), GL20.GL_TRIANGLES);
        IntModel atmosphereModel = pair.getFirst();
        atmMat = pair.getSecond().get("base");
        setUpAtmosphericScatteringMaterial(atmMat);
        atmMat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
        // CREATE ATMOSPHERE MODEL
        mc.instance = new IntModelInstance(atmosphereModel, this.localTransform);
    } else {
        atmMat = mc.instance.materials.get(0);
        setUpAtmosphericScatteringMaterial(atmMat);
    }
}
Also used : IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) BlendingAttribute(gaiasky.util.gdx.shader.attribute.BlendingAttribute) Material(gaiasky.util.gdx.shader.Material) IntModel(gaiasky.util.gdx.model.IntModel) Map(java.util.Map)

Example 17 with Material

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

the class CloudComponent method doneLoading.

public void doneLoading(AssetManager manager) {
    this.manager = manager;
    Pair<IntModel, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Bits.indexes(Usage.Position, Usage.Normal, Usage.Tangent, Usage.BiNormal, Usage.TextureCoordinates), GL20.GL_TRIANGLES);
    IntModel cloudModel = pair.getFirst();
    Material material = pair.getSecond().get("base");
    material.clear();
    // CREATE CLOUD MODEL
    mc.instance = new IntModelInstance(cloudModel, this.localTransform);
    if (!Settings.settings.scene.initialization.lazyTexture)
        initMaterial();
    // Subscribe to new graphics quality setting event
    EventManager.instance.subscribe(this, Event.GRAPHICS_QUALITY_UPDATED);
    // Initialised
    texInitialised = !Settings.settings.scene.initialization.lazyTexture;
    // Loading
    texLoading = false;
}
Also used : IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) Material(gaiasky.util.gdx.shader.Material) IntModel(gaiasky.util.gdx.model.IntModel) Map(java.util.Map)

Example 18 with Material

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

the class ShapeObject method initModel.

public void initModel() {
    this.localTransform = new Matrix4();
    if (model == null) {
        Pair<IntModel, Map<String, Material>> m = ModelCache.cache.getModel(modelShape, modelParams, Bits.indexes(Usage.Position), primitiveType);
        model = m.getFirst();
        for (Map.Entry<String, Material> material : m.getSecond().entrySet()) {
            material.getValue().set(new BlendingAttribute(GL20.GL_ONE, GL20.GL_ONE));
            material.getValue().set(new ColorAttribute(ColorAttribute.Diffuse, cc[0], cc[1], cc[2], cc[3]));
        }
        mc = new ModelComponent(false);
        mc.initialize(null);
        DirectionalLight dLight = new DirectionalLight();
        dLight.set(1, 1, 1, 1, 1, 1);
        mc.env = new Environment();
        mc.env.add(dLight);
        mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1f));
        mc.env.set(new FloatAttribute(FloatAttribute.Shininess, 0.2f));
        mc.instance = new IntModelInstance(model, new Matrix4());
        // Relativistic effects
        if (Settings.settings.runtime.relativisticAberration)
            mc.rec.setUpRelativisticEffectsMaterial(mc.instance.materials);
        // Gravitational waves
        if (Settings.settings.runtime.gravitationalWaves)
            mc.rec.setUpGravitationalWavesMaterial(mc.instance.materials);
    }
}
Also used : IntModelInstance(gaiasky.util.gdx.model.IntModelInstance) BlendingAttribute(gaiasky.util.gdx.shader.attribute.BlendingAttribute) Material(gaiasky.util.gdx.shader.Material) Matrix4(com.badlogic.gdx.math.Matrix4) ModelComponent(gaiasky.scenegraph.component.ModelComponent) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) Environment(gaiasky.util.gdx.shader.Environment) FloatAttribute(gaiasky.util.gdx.shader.attribute.FloatAttribute) IntModel(gaiasky.util.gdx.model.IntModel) ColorAttribute(gaiasky.util.gdx.shader.attribute.ColorAttribute) Map(java.util.Map)

Example 19 with Material

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

the class ModelComponent method setVROffset.

public void setVROffset(NaturalCamera cam) {
    if (Settings.settings.runtime.openVr && cam.vrOffset != null) {
        int n = instance.materials.size;
        for (int i = 0; i < n; i++) {
            Material mat = instance.materials.get(i);
            if (mat.has(Vector3Attribute.VrOffset)) {
                cam.vrOffset.put(((Vector3Attribute) mat.get(Vector3Attribute.VrOffset)).value);
                ((Vector3Attribute) mat.get(Vector3Attribute.VrOffset)).value.scl(5e4f);
            } else {
                Vector3Attribute v3a = new Vector3Attribute(Vector3Attribute.VrOffset, cam.vrOffset.toVector3());
                mat.set(v3a);
            }
        }
    }
}
Also used : Material(gaiasky.util.gdx.shader.Material)

Example 20 with Material

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

the class ModelComponent method initModelFile.

private Pair<IntModel, Map<String, Material>> initModelFile() {
    IntModel model = null;
    Map<String, Material> materials = null;
    if (modelFile != null && manager.isLoaded(Settings.settings.data.dataFile(modelFile))) {
        // Model comes from file (probably .obj or .g3db)
        model = manager.get(Settings.settings.data.dataFile(modelFile), IntModel.class);
        materials = new HashMap<>();
        if (model.materials.size == 0) {
            Material material = new Material();
            model.materials.add(material);
            materials.put("base", material);
        } else {
            if (model.materials.size > 1)
                for (int i = 0; i < model.materials.size; i++) {
                    materials.put("base" + i, model.materials.get(i));
                }
            else
                materials.put("base", model.materials.first());
        }
        // Add skybox to materials if reflection present
        if (!Settings.settings.postprocess.ssr) {
            addReflectionCubemapAttribute(model.materials);
        }
    } else if (type != null) {
        // We actually need to create the model
        Bits attributes = Bits.indexes(Usage.Position, Usage.Normal, Usage.Tangent, Usage.BiNormal, Usage.TextureCoordinates);
        if (params.containsKey("attributes")) {
            attributes = Bits.indexes(((Long) params.get("attributes")).intValue());
        }
        Pair<IntModel, Map<String, Material>> pair = ModelCache.cache.getModel(type, params, attributes, GL20.GL_TRIANGLES);
        model = pair.getFirst();
        materials = pair.getSecond();
    } else {
        // Data error!
        logger.error(new RuntimeException("The 'model' element must contain either a 'type' or a 'model' attribute"));
    }
    // Clear base material
    assert materials != null;
    if (materials.containsKey("base") && materials.get("base").size() < 2)
        materials.get("base").clear();
    return new Pair<>(model, materials);
}
Also used : Material(gaiasky.util.gdx.shader.Material) IntModel(gaiasky.util.gdx.model.IntModel)

Aggregations

Material (gaiasky.util.gdx.shader.Material)22 IntModel (gaiasky.util.gdx.model.IntModel)7 IntModelInstance (gaiasky.util.gdx.model.IntModelInstance)7 Texture (com.badlogic.gdx.graphics.Texture)6 BlendingAttribute (gaiasky.util.gdx.shader.attribute.BlendingAttribute)6 Matrix4 (com.badlogic.gdx.math.Matrix4)5 ColorAttribute (gaiasky.util.gdx.shader.attribute.ColorAttribute)5 ModelComponent (gaiasky.scenegraph.component.ModelComponent)4 Environment (gaiasky.util.gdx.shader.Environment)4 FloatAttribute (gaiasky.util.gdx.shader.attribute.FloatAttribute)4 TextureAttribute (gaiasky.util.gdx.shader.attribute.TextureAttribute)4 Map (java.util.Map)4 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)2 IntModelBuilder (gaiasky.util.gdx.IntModelBuilder)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 TextureDescriptor (com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)1 PixmapTextureData (com.badlogic.gdx.graphics.glutils.PixmapTextureData)1 ExtendViewport (com.badlogic.gdx.utils.viewport.ExtendViewport)1 IntMeshPartBuilder (gaiasky.util.gdx.IntMeshPartBuilder)1