Search in sources :

Example 1 with TextureData

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);
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) ResourceUrn(org.terasology.assets.ResourceUrn) UIImage(org.terasology.rendering.nui.widgets.UIImage) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.rendering.assets.texture.Texture)

Example 2 with TextureData

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();
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) Vector3f(org.terasology.math.geom.Vector3f) ResourceUrn(org.terasology.assets.ResourceUrn) Texture(org.terasology.rendering.assets.texture.Texture) DepthStencilTexture(org.terasology.rendering.dag.stateChanges.SetInputTextureFromFbo.FboTexturesTypes.DepthStencilTexture) NormalsTexture(org.terasology.rendering.dag.stateChanges.SetInputTextureFromFbo.FboTexturesTypes.NormalsTexture) ByteBuffer(java.nio.ByteBuffer)

Example 3 with TextureData

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);
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) MaterialData(org.terasology.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.assets.ResourceUrn) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.rendering.assets.texture.Texture)

Example 4 with TextureData

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);
}
Also used : PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) EngineSubsystem(org.terasology.engine.subsystem.EngineSubsystem) RenderingSubsystemFactory(org.terasology.engine.subsystem.RenderingSubsystemFactory) Texture(org.terasology.rendering.assets.texture.Texture) MeshData(org.terasology.rendering.assets.mesh.MeshData) HeadlessMaterial(org.terasology.engine.subsystem.headless.assets.HeadlessMaterial) HeadlessDisplayDevice(org.terasology.engine.subsystem.headless.device.HeadlessDisplayDevice) HeadlessTexture(org.terasology.engine.subsystem.headless.assets.HeadlessTexture) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) FontData(org.terasology.rendering.assets.font.FontData) Material(org.terasology.rendering.assets.material.Material) MaterialData(org.terasology.rendering.assets.material.MaterialData) Mesh(org.terasology.rendering.assets.mesh.Mesh) Shader(org.terasology.rendering.assets.shader.Shader) PNGTextureFormat(org.terasology.rendering.assets.texture.PNGTextureFormat) CanvasRenderer(org.terasology.rendering.nui.internal.CanvasRenderer) Atlas(org.terasology.rendering.assets.atlas.Atlas) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) HeadlessShader(org.terasology.engine.subsystem.headless.assets.HeadlessShader) Context(org.terasology.context.Context) ModuleAwareAssetTypeManager(org.terasology.assets.module.ModuleAwareAssetTypeManager) MeshAnimationImpl(org.terasology.rendering.assets.animation.MeshAnimationImpl) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) ShaderManager(org.terasology.rendering.ShaderManager) AssetFactory(org.terasology.assets.AssetFactory) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) FontImpl(org.terasology.rendering.assets.font.FontImpl) ShaderData(org.terasology.rendering.assets.shader.ShaderData) HeadlessCanvasRenderer(org.terasology.engine.subsystem.headless.renderer.HeadlessCanvasRenderer) HeadlessRenderingSubsystemFactory(org.terasology.engine.subsystem.headless.renderer.HeadlessRenderingSubsystemFactory) HeadlessMesh(org.terasology.engine.subsystem.headless.assets.HeadlessMesh) ShaderManagerHeadless(org.terasology.engine.subsystem.headless.renderer.ShaderManagerHeadless) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) Font(org.terasology.rendering.assets.font.Font) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture) TextureData(org.terasology.rendering.assets.texture.TextureData) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) Atlas(org.terasology.rendering.assets.atlas.Atlas) FontData(org.terasology.rendering.assets.font.FontData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) Mesh(org.terasology.rendering.assets.mesh.Mesh) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) HeadlessMesh(org.terasology.engine.subsystem.headless.assets.HeadlessMesh) HeadlessMaterial(org.terasology.engine.subsystem.headless.assets.HeadlessMaterial) Material(org.terasology.rendering.assets.material.Material) HeadlessSkeletalMesh(org.terasology.engine.subsystem.headless.assets.HeadlessSkeletalMesh) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Shader(org.terasology.rendering.assets.shader.Shader) HeadlessShader(org.terasology.engine.subsystem.headless.assets.HeadlessShader) Texture(org.terasology.rendering.assets.texture.Texture) HeadlessTexture(org.terasology.engine.subsystem.headless.assets.HeadlessTexture) Font(org.terasology.rendering.assets.font.Font) MeshData(org.terasology.rendering.assets.mesh.MeshData) SkeletalMeshData(org.terasology.rendering.assets.skeletalmesh.SkeletalMeshData) ShaderData(org.terasology.rendering.assets.shader.ShaderData) AtlasData(org.terasology.rendering.assets.atlas.AtlasData) TextureData(org.terasology.rendering.assets.texture.TextureData) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) MeshAnimation(org.terasology.rendering.assets.animation.MeshAnimation) MeshAnimationData(org.terasology.rendering.assets.animation.MeshAnimationData) MaterialData(org.terasology.rendering.assets.material.MaterialData) Subtexture(org.terasology.rendering.assets.texture.subtexture.Subtexture)

Example 5 with TextureData

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);
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TextureData (org.terasology.rendering.assets.texture.TextureData)8 Texture (org.terasology.rendering.assets.texture.Texture)7 ByteBuffer (java.nio.ByteBuffer)6 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)4 MaterialData (org.terasology.rendering.assets.material.MaterialData)4 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 AssetFactory (org.terasology.assets.AssetFactory)3 ResourceUrn (org.terasology.assets.ResourceUrn)3 Config (org.terasology.config.Config)3 Context (org.terasology.context.Context)3 MeshAnimation (org.terasology.rendering.assets.animation.MeshAnimation)3 MeshAnimationData (org.terasology.rendering.assets.animation.MeshAnimationData)3 MeshAnimationImpl (org.terasology.rendering.assets.animation.MeshAnimationImpl)3 Atlas (org.terasology.rendering.assets.atlas.Atlas)3 AtlasData (org.terasology.rendering.assets.atlas.AtlasData)3 Font (org.terasology.rendering.assets.font.Font)3 FontData (org.terasology.rendering.assets.font.FontData)3 FontImpl (org.terasology.rendering.assets.font.FontImpl)3 Material (org.terasology.rendering.assets.material.Material)3