Java Code Examples for com.badlogic.gdx.graphics.glutils.ShaderProgram#setUniformi()

The following examples show how to use com.badlogic.gdx.graphics.glutils.ShaderProgram#setUniformi() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageBasedLightSystem.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
@Override
    public void update(TimeStep timeStep) {
        ShaderProgram shader = this.shader.getShader();
        shader.begin();
        {
//            this.ambientColor.set(0.3f, 0.3f, 0.4f);
//            this.ambientColor.set(0.9f, 0.9f, 0.9f);
//            this.ambientIntensity = 0.4f;
            
            shader.setUniformi("u_lightmap", 1);
            shader.setUniformf("ambientColor", ambientColor.x, ambientColor.y, ambientColor.z, ambientIntensity);        
            shader.setUniformf("resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
                    //SeventhGame.DEFAULT_MINIMIZED_SCREEN_WIDTH, SeventhGame.DEFAULT_MINIMIZED_SCREEN_HEIGHT);
        }
        shader.end();
        
        
        for(int i = 0; i < this.lights.size(); i++) {
            Light light = this.lights.get(i);
            light.update(timeStep);
        }
        
    }
 
Example 2
Source File: TextureAttribute.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
@Override
public void bind (ShaderProgram program) {
	texture.bind(unit);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, minFilter);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER, magFilter);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S, uWrap);
	Gdx.gl.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T, vWrap);
	program.setUniformi(name, unit);
}
 
Example 3
Source File: CubesShaderProvider.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public void begin(ShaderProgram program, Camera camera, RenderContext context) {
  TextureAttribute textureAttribute = AmbientOcclusion.getTextureAttribute();

  ao_unit = context.textureBinder.bind(textureAttribute.textureDescription);
  program.setUniformi(u_aoTexture, ao_unit);
  program.setUniformf(u_aoUVTransform, textureAttribute.offsetU, textureAttribute.offsetV, textureAttribute.scaleU, textureAttribute.scaleV);
  program.setUniformf(u_aoStrength, AmbientOcclusion.getStrength().strength);
}
 
Example 4
Source File: GameWorldRenderer.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
private boolean renderCar (Car car, boolean depthOnly, boolean nightMode) {
	CarStillModel model = car.getStillModel();

	if (Config.Debug.FrustumCulling && !camPersp.frustum.boundsInFrustum(model.boundingBox)) {
		return false;
	}

	ShaderProgram shader = null;
	if (depthOnly) {
		shader = shNormalDepth;
	} else {
		if (nightMode) {
			shader = OrthographicAlignedStillModel.shaderNight;
		} else {
			shader = OrthographicAlignedStillModel.shader;
		}
	}

	gl.glEnable(GL20.GL_CULL_FACE);

	shader.begin();
	Art.meshCar.get(car.getCarPreset().type.regionName).bind();

	// common matrices
	if (depthOnly) {
		shader.setUniformMatrix("proj", camPersp.projection);
		shader.setUniformMatrix("view", camPersp.view);
		shader.setUniformi("u_texture", 0);
	} else {
		shader.setUniformf("alpha", model.getAlpha());
		if (nightMode) {
			shader.setUniformf("u_ambient", treesAmbientColor);
		}
	}

	// car body
	{
		if (depthOnly) {
			mtx.set(camPersp.view).mul(model.mtxbody);
			nmat.set(mtx).inv().transpose();
			shader.setUniformMatrix("nmat", nmat);
			shader.setUniformMatrix("model", model.mtxbody);
		} else {
			shader.setUniformMatrix("u_projTrans", model.mtxbodytransformed);
		}

		model.body.render(shader, model.smBody.primitiveType);
	}

	// car left tire
	{
		if (depthOnly) {
			mtx.set(camPersp.view).mul(model.mtxltire);
			nmat.set(mtx).inv().transpose();
			shader.setUniformMatrix("nmat", nmat);
			shader.setUniformMatrix("model", model.mtxltire);
		} else {
			shader.setUniformMatrix("u_projTrans", model.mtxltiretransformed);
		}

		model.leftTire.render(shader, model.smLeftTire.primitiveType);
	}

	// car right tire
	{
		if (depthOnly) {
			mtx.set(camPersp.view).mul(model.mtxrtire);
			nmat.set(mtx).inv().transpose();
			shader.setUniformMatrix("nmat", nmat);
			shader.setUniformMatrix("model", model.mtxrtire);
		} else {
			shader.setUniformMatrix("u_projTrans", model.mtxrtiretransformed);
		}

		model.rightTire.render(shader, model.smRightTire.primitiveType);
	}

	return true;
}
 
Example 5
Source File: ChannelBar.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
protected void setShaderUniforms (ShaderProgram shader) {
	shader.setUniformi("u_mode", mode);
	channelBarListener.setShaderUniforms(shader);
}
 
Example 6
Source File: Box2dLightCustomShaderTest.java    From box2dlights with Apache License 2.0 4 votes vote down vote up
private ShaderProgram createLightShader () {
	// Shader adapted from https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson6
	final String vertexShader =
		"attribute vec4 vertex_positions;\n" //
			+ "attribute vec4 quad_colors;\n" //
			+ "attribute float s;\n"
			+ "uniform mat4 u_projTrans;\n" //
			+ "varying vec4 v_color;\n" //
			+ "void main()\n" //
			+ "{\n" //
			+ "   v_color = s * quad_colors;\n" //
			+ "   gl_Position =  u_projTrans * vertex_positions;\n" //
			+ "}\n";
	final String fragmentShader = "#ifdef GL_ES\n" //
		+ "precision lowp float;\n" //
		+ "#define MED mediump\n"
		+ "#else\n"
		+ "#define MED \n"
		+ "#endif\n" //
		+ "varying vec4 v_color;\n" //
		+ "uniform sampler2D u_normals;\n" //
		+ "uniform vec3 u_lightpos;\n" //
		+ "uniform vec2 u_resolution;\n" //
		+ "uniform float u_intensity = 1.0;\n" //
		+ "void main()\n"//
		+ "{\n"
		+ "  vec2 screenPos = gl_FragCoord.xy / u_resolution.xy;\n"
		+ "  vec3 NormalMap = texture2D(u_normals, screenPos).rgb; "
		+ "  vec3 LightDir = vec3(u_lightpos.xy - screenPos, u_lightpos.z);\n"

		+ "  vec3 N = normalize(NormalMap * 2.0 - 1.0);\n"

		+ "  vec3 L = normalize(LightDir);\n"

		+ "  float maxProd = max(dot(N, L), 0.0);\n"
		+ "" //
		+ "  gl_FragColor = v_color * maxProd * u_intensity;\n" //
		+ "}";

	ShaderProgram.pedantic = false;
	ShaderProgram lightShader = new ShaderProgram(vertexShader,
		fragmentShader);
	if (!lightShader.isCompiled()) {
		Gdx.app.log("ERROR", lightShader.getLog());
	}

	lightShader.begin();
	lightShader.setUniformi("u_normals", 1);
	lightShader.setUniformf("u_resolution", Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	lightShader.end();

	return lightShader;
}