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);
}
}
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;
}
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);
}
}
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);
}
}
}
}
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);
}
Aggregations