use of org.terasology.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class PreviewWorldScreen method genTexture.
private void genTexture() {
int imgWidth = 384;
int imgHeight = 384;
ByteBuffer buffer = ByteBuffer.allocateDirect(imgWidth * imgHeight * Integer.BYTES);
ByteBuffer[] data = new ByteBuffer[] { buffer };
ResourceUrn uri = new ResourceUrn("engine:terrainPreview");
TextureData texData = new TextureData(imgWidth, imgHeight, data, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR);
texture = Assets.generateAsset(uri, texData, Texture.class);
previewImage = find("preview", UIImage.class);
previewImage.setImage(texture);
}
use of org.terasology.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class AmbientOcclusionNode method generateNoiseTexture.
private Texture generateNoiseTexture() {
Optional<Texture> texture = Assets.getTexture("engine:ssaoNoise");
if (!texture.isPresent()) {
ByteBuffer noiseValues = BufferUtils.createByteBuffer(SSAO_NOISE_SIZE * SSAO_NOISE_SIZE * 4);
for (int i = 0; i < SSAO_NOISE_SIZE * SSAO_NOISE_SIZE; ++i) {
Vector3f noiseVector = new Vector3f(randomGenerator.nextFloat(-1.0f, 1.0f), randomGenerator.nextFloat(-1.0f, 1.0f), 0.0f);
noiseVector.normalize();
noiseValues.put((byte) ((noiseVector.x * 0.5 + 0.5) * 255.0f));
noiseValues.put((byte) ((noiseVector.y * 0.5 + 0.5) * 255.0f));
noiseValues.put((byte) ((noiseVector.z * 0.5 + 0.5) * 255.0f));
noiseValues.put((byte) 0x0);
}
noiseValues.flip();
return Assets.generateAsset(new ResourceUrn("engine:ssaoNoise"), new TextureData(SSAO_NOISE_SIZE, SSAO_NOISE_SIZE, new ByteBuffer[] { noiseValues }, Texture.WrapMode.REPEAT, Texture.FilterMode.NEAREST), Texture.class);
}
return texture.get();
}
use of org.terasology.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class WorldAtlasImpl method buildAtlas.
private void buildAtlas() {
calculateAtlasSizes();
int numMipMaps = getNumMipmaps();
ByteBuffer[] data = createAtlasMipmaps(numMipMaps, TRANSPARENT_COLOR, tiles, "tiles.png");
ByteBuffer[] dataNormal = createAtlasMipmaps(numMipMaps, UNIT_Z_COLOR, tilesNormal, "tilesNormal.png", tilesGloss);
ByteBuffer[] dataHeight = createAtlasMipmaps(numMipMaps, BLACK_COLOR, tilesHeight, "tilesHeight.png");
TextureData terrainTexData = new TextureData(atlasSize, atlasSize, data, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
Texture terrainTex = Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainTexData, Texture.class);
TextureData terrainNormalData = new TextureData(atlasSize, atlasSize, dataNormal, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
Assets.generateAsset(new ResourceUrn("engine:terrainNormal"), terrainNormalData, Texture.class);
TextureData terrainHeightData = new TextureData(atlasSize, atlasSize, dataHeight, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
Assets.generateAsset(new ResourceUrn("engine:terrainHeight"), terrainHeightData, Texture.class);
MaterialData terrainMatData = new MaterialData(Assets.getShader("engine:block").get());
terrainMatData.setParam("textureAtlas", terrainTex);
terrainMatData.setParam("colorOffset", new float[] { 1, 1, 1 });
terrainMatData.setParam("textured", true);
Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainMatData, Material.class);
createTextureAtlas(terrainTex);
}
use of org.terasology.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class HeadlessGraphics method registerCoreAssetTypes.
@Override
public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager) {
assetTypeManager.registerCoreAssetType(Font.class, (AssetFactory<Font, FontData>) FontImpl::new, "fonts");
assetTypeManager.registerCoreAssetType(Texture.class, (AssetFactory<Texture, TextureData>) HeadlessTexture::new, "textures", "fonts");
assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getName(2).toString().equals("textures")));
assetTypeManager.registerCoreFormat(Texture.class, new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getName(2).toString().equals("fonts")));
assetTypeManager.registerCoreAssetType(Shader.class, (AssetFactory<Shader, ShaderData>) HeadlessShader::new, "shaders");
assetTypeManager.registerCoreAssetType(Material.class, (AssetFactory<Material, MaterialData>) HeadlessMaterial::new, "materials");
assetTypeManager.registerCoreAssetType(Mesh.class, (AssetFactory<Mesh, MeshData>) HeadlessMesh::new, "mesh");
assetTypeManager.registerCoreAssetType(SkeletalMesh.class, (AssetFactory<SkeletalMesh, SkeletalMeshData>) HeadlessSkeletalMesh::new, "skeletalMesh");
assetTypeManager.registerCoreAssetType(MeshAnimation.class, (AssetFactory<MeshAnimation, MeshAnimationData>) MeshAnimationImpl::new, "animations");
assetTypeManager.registerCoreAssetType(Atlas.class, (AssetFactory<Atlas, AtlasData>) Atlas::new, "atlas");
assetTypeManager.registerCoreAssetType(Subtexture.class, (AssetFactory<Subtexture, SubtextureData>) Subtexture::new);
}
use of org.terasology.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class LwjglFrameBufferObject method generateTexture.
private Texture generateTexture(ResourceUrn urn) {
ByteBuffer buffer = ByteBuffer.allocateDirect(size.x() * size.y() * Integer.BYTES);
ByteBuffer[] mipmaps = new ByteBuffer[] { buffer };
TextureData data = new TextureData(size.x(), size.y(), mipmaps, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
return Assets.generateAsset(urn, data, Texture.class);
}
Aggregations