use of com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider in project libgdx by libgdx.
the class TextureRegion3DTest method create.
@Override
public void create() {
Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f);
atlas = new TextureAtlas(Gdx.files.internal("data/testpack"));
regions = atlas.getRegions();
modelBatch = new ModelBatch(new DefaultShaderProvider());
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse));
model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
instance = new ModelInstance(model);
attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
use of com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider in project libgdx by libgdx.
the class Basic3DTest method create.
@Override
public void create() {
modelBatch = new ModelBatch(new DefaultShaderProvider());
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 30f;
cam.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(cam)));
}
use of com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider in project libgdx by libgdx.
the class Benchmark3DTest method randomizeLights.
protected void randomizeLights() {
int pointLights = MathUtils.random(5);
int directionalLights = MathUtils.random(5);
DefaultShader.Config config = new Config();
config.numDirectionalLights = directionalLights;
config.numPointLights = pointLights;
config.numSpotLights = 0;
modelBatch.dispose();
modelBatch = new ModelBatch(new DefaultShaderProvider(config));
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
for (int i = 0; i < pointLights; i++) {
environment.add(new PointLight().set(randomColor(), randomPosition(), MathUtils.random(10f)));
}
for (int i = 0; i < directionalLights; i++) {
environment.add(new DirectionalLight().set(randomColor(), randomPosition()));
}
}
use of com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider 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);
}
use of com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider in project libgdx by libgdx.
the class ShaderTest method create.
@Override
public void create() {
modelBatch = new ModelBatch(new DefaultShaderProvider() {
@Override
protected Shader createShader(Renderable renderable) {
if (renderable.material.has(TestAttribute.ID))
return new TestShader(renderable);
return super.createShader(renderable);
}
});
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0f, 0f, 20f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
Material testMaterial1 = new Material("TestMaterial1", new TestAttribute(1f));
Material redMaterial = new Material("RedMaterial", ColorAttribute.createDiffuse(Color.RED));
Material testMaterial2 = new Material("TestMaterial2", new TestAttribute(1f), ColorAttribute.createDiffuse(Color.BLUE));
ModelBuilder builder = new ModelBuilder();
Node node;
builder.begin();
node = builder.node();
node.id = "testCone1";
node.translation.set(-10, 0f, 0f);
builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial1).cone(5, 5, 5, 20);
node = builder.node();
node.id = "redSphere";
builder.part("redSphere", GL20.GL_TRIANGLES, Usage.Position, redMaterial).sphere(5, 5, 5, 20, 20);
node = builder.node();
node.id = "testCone1";
node.translation.set(10, 0f, 0f);
builder.part("testCone", GL20.GL_TRIANGLES, Usage.Position, testMaterial2).cone(5, 5, 5, 20);
model = builder.end();
ModelInstance modelInstance;
modelInstance = new ModelInstance(model);
testAttribute1 = (TestAttribute) modelInstance.getMaterial("TestMaterial1").get(TestAttribute.ID);
testAttribute2 = (TestAttribute) modelInstance.getMaterial("TestMaterial2").get(TestAttribute.ID);
instances.add(modelInstance);
}
Aggregations