Search in sources :

Example 1 with CubemapAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute in project libgdx by libgdx.

the class ShaderCollectionTest method setEnvironment.

public void setEnvironment(String name) {
    if (name == null)
        return;
    if (cubemap != null) {
        cubemap.dispose();
        cubemap = null;
    }
    if (name.equals("<none>")) {
        if (environment.has(CubemapAttribute.EnvironmentMap)) {
            environment.remove(CubemapAttribute.EnvironmentMap);
            shaderProvider.clear();
        }
    } else {
        FileHandle root = Gdx.files.internal("data/g3d/environment");
        FacedCubemapData faces = new FacedCubemapData(root.child(name + "_PX.png"), root.child(name + "_NX.png"), root.child(name + "_PY.png"), root.child(name + "_NY.png"), root.child(name + "_PZ.png"), root.child(name + "_NZ.png"), // FIXME mipmapping on desktop
        false);
        cubemap = new Cubemap(faces);
        faces.load(CubemapSide.NegativeX, root.child(name + "_NX.png"));
        cubemap.load(faces);
        if (!environment.has(CubemapAttribute.EnvironmentMap))
            shaderProvider.clear();
        environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) FacedCubemapData(com.badlogic.gdx.graphics.glutils.FacedCubemapData) Cubemap(com.badlogic.gdx.graphics.Cubemap)

Example 2 with CubemapAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute in project libgdx by libgdx.

the class FrameBufferCubemapTest method create.

@Override
public void create() {
    super.create();
    camFb = new PerspectiveCamera(90, 800, 800);
    camFb.position.set(10f, 10f, 10f);
    camFb.lookAt(0, 0, 0);
    camFb.near = 0.1f;
    camFb.far = 1000f;
    camFb.update();
    fb = new FrameBufferCubemap(Format.RGBA8888, 800, 800, true);
    cubemap = fb.getColorBufferTexture();
    ObjLoader objLoader = new ObjLoader();
    cubeMesh = objLoader.loadModel(Gdx.files.internal("data/cube.obj"));
    cubeInstance = new ModelInstance(cubeMesh);
    cubeBatch = new ModelBatch(Gdx.files.internal("data/shaders/cubemap-vert.glsl"), Gdx.files.internal("data/shaders/cubemap-frag.glsl"));
    cubeInstance.materials.get(0).set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
    camCube = new PerspectiveCamera(67, Gdx.graphics.getWidth() * 0.5f, Gdx.graphics.getHeight() * 0.5f);
    camCube.position.set(0f, 2f, 2f);
    camCube.lookAt(0, 0, 0);
    camCube.near = 1f;
    camCube.far = 300f;
    camCube.update();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) ObjLoader(com.badlogic.gdx.graphics.g3d.loader.ObjLoader) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FrameBufferCubemap(com.badlogic.gdx.graphics.glutils.FrameBufferCubemap)

Example 3 with CubemapAttribute

use of com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute in project libgdx by libgdx.

the class KTXTest method create.

@Override
public void create() {
    // Cubemap test
    String cubemapVS = //
    "" + //
    "attribute vec3 a_position;\n" + //
    "uniform mat4 u_projViewTrans;\n" + //
    "uniform mat4 u_worldTrans;\n" + //
    "\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec4 g_position = vec4(a_position, 1.0);\n" + //
    "   g_position = u_worldTrans * g_position;\n" + //
    "   v_cubeMapUV = normalize(g_position.xyz);\n" + //
    "   gl_Position = u_projViewTrans * g_position;\n" + "}";
    String cubemapFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform samplerCube u_environmentCubemap;\n" + //
    "varying vec3 v_cubeMapUV;\n" + //
    "void main() {\n" + //
    "	gl_FragColor = vec4(textureCube(u_environmentCubemap, v_cubeMapUV).rgb, 1.0);\n" + "}\n";
    modelBatch = new ModelBatch(new DefaultShaderProvider(new Config(cubemapVS, cubemapFS)));
    cubemap = new Cubemap(new KTXTextureData(Gdx.files.internal("data/cubemap.zktx"), true));
    cubemap.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.1f, 0.1f, 0.1f, 1.f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
    environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
    perspectiveCamera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    perspectiveCamera.position.set(10f, 10f, 10f);
    perspectiveCamera.lookAt(0, 0, 0);
    perspectiveCamera.near = 0.1f;
    perspectiveCamera.far = 300f;
    perspectiveCamera.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    instance = new ModelInstance(model);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(perspectiveCamera)));
    // 2D texture test
    String etc1aVS = //
    "" + //
    "uniform mat4 u_projTrans;\n" + //
    "\n" + //
    "attribute vec4 a_position;\n" + //
    "attribute vec2 a_texCoord0;\n" + //
    "attribute vec4 a_color;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   gl_Position = u_projTrans * a_position;\n" + //
    "   v_texCoord = a_texCoord0;\n" + //
    "   v_color = a_color;\n" + //
    "}\n";
    String etc1aFS = //
    "" + //
    "#ifdef GL_ES\n" + //
    "precision mediump float;\n" + //
    "#endif\n" + //
    "uniform sampler2D u_texture;\n" + //
    "\n" + //
    "varying vec4 v_color;\n" + //
    "varying vec2 v_texCoord;\n" + //
    "\n" + //
    "void main() {\n" + //
    "   vec3 col = texture2D(u_texture, v_texCoord.st).rgb;\n" + //
    "   float alpha = texture2D(u_texture, v_texCoord.st + vec2(0.0, 0.5)).r;\n" + //
    "   gl_FragColor = vec4(col, alpha) * v_color;\n" + //
    "}\n";
    etc1aShader = new ShaderProgram(etc1aVS, etc1aFS);
    orthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    image = new Texture("data/egg.zktx");
    batch = new SpriteBatch(100, etc1aShader);
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Config(com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.Config) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) KTXTextureData(com.badlogic.gdx.graphics.glutils.KTXTextureData) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Cubemap(com.badlogic.gdx.graphics.Cubemap) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

CubemapAttribute (com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute)3 Cubemap (com.badlogic.gdx.graphics.Cubemap)2 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)2 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 Environment (com.badlogic.gdx.graphics.g3d.Environment)1 Material (com.badlogic.gdx.graphics.g3d.Material)1 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)1 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)1 ObjLoader (com.badlogic.gdx.graphics.g3d.loader.ObjLoader)1 Config (com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.Config)1 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)1 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)1 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)1 FacedCubemapData (com.badlogic.gdx.graphics.glutils.FacedCubemapData)1