import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
+import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.Shader;
+import com.badlogic.gdx.graphics.g3d.shaders.subshaders.DiffuseTextureShader;
import com.badlogic.gdx.graphics.g3d.shaders.subshaders.SubShader;
import com.badlogic.gdx.graphics.g3d.shaders.subshaders.TransformShader;
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
public CompositeShader(Renderable renderable) {
subShaders.add(new TransformShader());
+ subShaders.add(new DiffuseTextureShader());
init(renderable);
}
program.begin();
this.camera = camera;
this.context = context;
+ context.setDepthTest(true, GL20.GL_LEQUAL);
}
@Override
--- /dev/null
+package com.badlogic.gdx.graphics.g3d.shaders.subshaders;
+
+import com.badlogic.gdx.graphics.Camera;
+import com.badlogic.gdx.graphics.g3d.Renderable;
+import com.badlogic.gdx.graphics.g3d.materials.Material.Attribute;
+import com.badlogic.gdx.graphics.g3d.materials.TextureAttribute;
+import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
+import com.badlogic.gdx.graphics.glutils.ShaderProgram;
+
+public class DiffuseTextureShader extends BaseSubShader {
+ private boolean enabled;
+
+ @Override
+ public void init (Renderable renderable) {
+ if(renderable.material.has(TextureAttribute.Diffuse)) {
+ vertexVars.addAll(new String[] {
+ "attribute vec2 a_texCoord0;",
+ "varying vec2 v_texCoords0;"
+ });
+ vertexCode.addAll(new String[] {
+ "v_texCoords0 = a_texCoord0;"
+ });
+ fragmentVars.addAll(new String[] {
+ "uniform sampler2D u_diffuseTexture;",
+ "varying MED vec2 v_texCoords0;"
+ });
+ fragmentCode.addAll(new String[] {
+ "color = texture2D(u_diffuseTexture, v_texCoords0);"
+ });
+ enabled = true;
+ }
+ }
+
+ @Override
+ public void apply (ShaderProgram program, RenderContext context, Camera camera, Renderable renderable) {
+ if(enabled) {
+ TextureAttribute attribute = (TextureAttribute)renderable.material.get(TextureAttribute.Diffuse);
+ int unit = context.textureBinder.bind(attribute.textureDescription);
+ program.setUniformi("u_diffuseTexture", unit);
+ }
+ }
+}