com.badlogic.gdx.graphics.glutils.ShaderProgram Java Examples

The following examples show how to use com.badlogic.gdx.graphics.glutils.ShaderProgram. 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: GameRenderer.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) {
	this.viewport = viewport;
	this.camera = camera;
	this.engine = engine;

	shapeRenderer = new MyShapeRenderer();
	shapeRenderer.setAutoShapeType(true);

	spriteBatch = new SpriteBatch();
	font = new BitmapFont();
	font.setColor(Color.WHITE);
	font.setUseIntegerPositions(false);
	font.getData().setScale(0.01f);
	shadowBatch = new ModelBatch(new DepthShaderProvider());

	ShaderProgram.pedantic = false;
	final String vertUber = Gdx.files.internal("shaders/uber.vert").readString();
	final String fragUber = Gdx.files.internal("shaders/uber.frag").readString();
	modelBatch = new ModelBatch(new DefaultShaderProvider(vertUber, fragUber) {
		@Override
		protected Shader createShader(final Renderable renderable) {
			return new UberShader(renderable, config);
		}
	});
}
 
Example #2
Source File: IBLBuilder.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
private void render(CubemapSide side, ShapeRenderer shapes, ShaderProgram shader, float strength, float exponent){
	shader.begin();
	shader.setUniformf("u_exponent", exponent);
	shader.setUniformf("u_ambient", color.r, color.g, color.b, 0f);
	shader.setUniformf("u_diffuse", color.r, color.g, color.b, strength);

	localDir.set(side.direction);
	localUp.set(side.up);
	
	// XXX patch
	if(side == CubemapSide.NegativeX || side == CubemapSide.PositiveX){
		localDir.x = -localDir.x;
	}
		
	matrix.setToLookAt(localDir, localUp).tra();
	localSunDir.set(direction).scl(-1, -1, 1).mul(matrix); // XXX patch again
	
	shader.setUniformf("u_direction", localSunDir);
	
	shapes.begin(ShapeType.Filled);
	shapes.rect(0, 0, 1, 1);
	shapes.end();
}
 
Example #3
Source File: ClientGameEffects.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
public void renderFrameBuffer(Canvas canvas, Camera camera, float alpha) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    canvas.setDefaultTransforms();

    frameBufferSprite.setRegion(canvas.getFrameBuffer());
    
    canvas.begin();
    {
        canvas.getFrameBuffer().bind();
        {
            ShaderProgram shader = ExplosionEffectShader.getInstance().getShader();
            
            canvas.setShader(shader);
            canvas.drawImage(frameBufferSprite, 0, 0, 0x0);
        }
    }
    canvas.end();
}
 
Example #4
Source File: Renderer20.java    From fluid-simulator-v2 with Apache License 2.0 6 votes vote down vote up
static private String createVertexShader (boolean hasNormals, boolean hasColors, int numTexCoords) {
	String shader = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
		+ (hasNormals ? "attribute vec3 " + ShaderProgram.NORMAL_ATTRIBUTE + ";\n" : "")
		+ (hasColors ? "attribute vec4 " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "attribute vec2 " + ShaderProgram.TEXCOORD_ATTRIBUTE + i + ";\n";
	}

	shader += "uniform mat4 u_projModelView;\n";
	shader += (hasColors ? "varying vec4 v_col;\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "varying vec2 v_tex" + i + ";\n";
	}

	shader += "void main() {\n" + "   gl_Position = u_projModelView * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n"
		+ (hasColors ? "   v_col = " + ShaderProgram.COLOR_ATTRIBUTE + ";\n" : "");

	for (int i = 0; i < numTexCoords; i++) {
		shader += "   v_tex" + i + " = " + ShaderProgram.TEXCOORD_ATTRIBUTE + i + ";\n";
	}
	shader += "   gl_PointSize = 1.0;\n";
	shader += "}\n";
	return shader;
}
 
Example #5
Source File: GameScreen.java    From TerraLegion with MIT License 6 votes vote down vote up
@Override
public void create() {
	//Load UI
	gameHud = new GameHud(this, world);

	ShaderProgram.pedantic = false;
	program = new ShaderProgram(Gdx.files.internal("shaders/sepia.vsh"), Gdx.files.internal("shaders/sepia.fsh"));
	
	if (!program.isCompiled()) {
		System.out.println(program.getLog());
	}
	
	camera = new OrthoCamera();
	Timer.startGameTime();
	resize(Settings.getWidth(), Settings.getHeight());
}
 
Example #6
Source File: ShaderUtils.java    From Mundus with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles and links shader.
 *
 * @param vertexShader
 *            path to vertex shader
 * @param fragmentShader
 *            path to fragment shader
 *
 * @return compiled shader program
 */
public static ShaderProgram compile(String vertexShader, String fragmentShader) {
    String vert;
    String frag;

    if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        vert = Gdx.files.internal(vertexShader).readString();
        frag = Gdx.files.internal(fragmentShader).readString();
    } else {
        vert = Gdx.files.classpath(vertexShader).readString();
        frag = Gdx.files.classpath(fragmentShader).readString();
    }

    ShaderProgram program = new ShaderProgram(vert, frag);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }

    return program;
}
 
Example #7
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 #8
Source File: ShaderLoader.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
public static ShaderProgram fromString( String vertex, String fragment, String vertexName, String fragmentName, String defines ) {
	ShaderProgram.pedantic = ShaderLoader.Pedantic;
	ShaderProgram shader = new ShaderProgram( defines + "\n" + vertex, defines + "\n" + fragment );
	if( !shader.isCompiled() ) {
		Gdx.app.error( "ShaderLoader", shader.getLog() );
		Gdx.app.exit();
	} else {
		if( defines != null && defines.length() > 0 ) {
			Gdx.app.log( "ShaderLoader", vertexName + "/" + fragmentName + " compiled w/ (" + defines.replace( "\n", ", " )
					+ ")" );
		} else {
			Gdx.app.log( "ShaderLoader", vertexName + "/" + fragmentName + " compiled!" );
		}
	}

	return shader;
}
 
Example #9
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 #10
Source File: StillModel.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
@Override
public void render (ShaderProgram program) {
	int len = subMeshes.length;
	for (int i = 0; i < len; i++) {
		StillSubMesh subMesh = subMeshes[i];
		if (i == 0) {
			subMesh.material.bind(program);
		} else if (!subMeshes[i - 1].material.equals(subMesh.material)) {
			subMesh.material.bind(program);
		}
		subMesh.mesh.render(program, subMesh.primitiveType);
	}
}
 
Example #11
Source File: UStillModel.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
@Override
public void render (ShaderProgram program) {
	int len = subMeshes.length;
	for (int i = 0; i < len; i++) {
		StillSubMesh subMesh = subMeshes[i];
		if (i == 0) {
			subMesh.material.bind(program);
		} else if (!subMeshes[i - 1].material.equals(subMesh.material)) {
			subMesh.material.bind(program);
		}
		subMesh.mesh.render(program, subMesh.primitiveType);
	}
}
 
Example #12
Source File: Skin.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
private void preDraw(Consumer<ShaderProgram> shaderVariableSetter) {
	if(shaders[current] != shaders[type]) {
		sprite.setShader(shaders[type]);
		current = type;
	}

	if (shaders[type] != null && shaderVariableSetter != null) {
		// シェーダの変数を変更する場合はバッチを切る
		// (shader.begin() - end() で囲うのは正しく動作しないため不可)
		sprite.flush();
		shaderVariableSetter.accept(shaders[type]);
	}

	switch (blend) {
	case 2:
		sprite.setBlendFunction(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
		break;
	case 3:
		// TODO 減算描画は難しいか?
		Gdx.gl.glBlendEquation(GL20.GL_FUNC_SUBTRACT);
		sprite.setBlendFunction(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
		Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD);
		break;
	case 4:
		sprite.setBlendFunction(GL11.GL_ZERO, GL11.GL_SRC_COLOR);
		break;
	case 9:
		sprite.setBlendFunction(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ZERO);
		break;
	}

	if(color != null) {
		orgcolor = sprite.getColor();
		sprite.setColor(color);				
	} else {
		orgcolor = null;
	}
}
 
Example #13
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) {
  WorldClient worldClient = ((WorldClient) Cubes.getClient().world);
  float distance = Settings.getIntegerSettingValue(Settings.GRAPHICS_VIEW_DISTANCE) * Area.SIZE_BLOCKS;
  float fogDistance = MathUtils.clamp(distance * 0.1f, 8f, 16f);

  program.setUniformf(u_cameraposition, Cubes.getClient().player.position);
  program.setUniformf(u_skycolor, worldClient.getSkyColour());
  program.setUniformf(u_fogdistance, fogDistance);
  program.setUniformf(u_minfogdistance, distance - fogDistance);
}
 
Example #14
Source File: DiffuseShader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
static final public ShaderProgram createShadowShader() {
	final String vertexShader = "attribute vec4 a_position;\n" //
			+ "attribute vec2 a_texCoord;\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "\n" //
			+ "void main()\n" //
			+ "{\n" //
			+ "   v_texCoords = a_texCoord;\n" //
			+ "   gl_Position = a_position;\n" //
			+ "}\n";

	// this is allways perfect precision
	final String fragmentShader = "#ifdef GL_ES\n" //
			+ "precision mediump float;\n" //
			+ "#endif\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "uniform sampler2D u_texture;\n" //
			+ "uniform  vec4 ambient;\n"
				+ "void main()\n"//
			+ "{\n" //
			+ "gl_FragColor = ambient + texture2D(u_texture, v_texCoords);\n"
				+ "}\n";
	ShaderProgram.pedantic = false;
	ShaderProgram shadowShader = new ShaderProgram(vertexShader,
				fragmentShader);
	if (shadowShader.isCompiled() == false) {
		Gdx.app.log("ERROR", shadowShader.getLog());

	}

	return shadowShader;
}
 
Example #15
Source File: ShadowShader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
static final public ShaderProgram createShadowShader() {
	final String vertexShader = "attribute vec4 a_position;\n" //
			+ "attribute vec2 a_texCoord;\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "\n" //
			+ "void main()\n" //
			+ "{\n" //
			+ "   v_texCoords = a_texCoord;\n" //
			+ "   gl_Position = a_position;\n" //
			+ "}\n";
	final String fragmentShader = "#ifdef GL_ES\n" //
			+ "#define MED " + RayHandler.getColorPrecision() + "\n" + "precision "
			+ RayHandler.getColorPrecision()
			+ " float;\n" //
			+ "#else\n" + "#define MED \n" + "#endif\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "uniform MED sampler2D u_texture;\n" //
			+ "uniform MED vec4 ambient;\n" + "void main()\n"//
			+ "{\n" //
			+ "vec4 v_c = texture2D(u_texture, v_texCoords);\n" + "v_c.rgb = ambient.rgb + v_c.rgb* v_c.a;\n"//
			+ "v_c.a = ambient.a - v_c.a;\n"//
			+ "gl_FragColor = v_c;\n"//
			+ "}\n";
	ShaderProgram.pedantic = false;
	ShaderProgram shadowShader = new ShaderProgram( vertexShader, fragmentShader );
	if( shadowShader.isCompiled() == false ) {
		Gdx.app.log( "ERROR", shadowShader.getLog() );

	}

	return shadowShader;
}
 
Example #16
Source File: GLTFPostProcessingExample.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
	
	sceneManager = createSceneManager();
	sceneManager.camera = camera = new PerspectiveCamera();
	camera.fieldOfView = 50;
	camera.near = 0.01f;
	camera.far = 10f;
	camera.position.set(1, 1, 1).scl(.1f);
	camera.up.set(Vector3.Y);
	camera.lookAt(Vector3.Zero);
	camera.update();
	
	// load user scene
	SceneAsset asset = new GLTFLoader().load(Gdx.files.internal("models/BoomBox/glTF/BoomBox.gltf"));
	sceneManager.addScene(new Scene(asset.scene));
	
	cameraController = new CameraInputController(camera);
	cameraController.translateUnits = .1f;
	Gdx.input.setInputProcessor(cameraController);

	viewport = new FitViewport(1000, 500, camera);
	
	// post processing
	if(postProcessingEnabled){
		fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
		effectShader = new ShaderProgram(Gdx.files.classpath("shaders/effect.vs.glsl"), Gdx.files.classpath("shaders/effect.fs.glsl"));
		batch = new SpriteBatch();
	}
	
}
 
Example #17
Source File: Main.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
private Mesh buildMeshFromVerticesAndTexCoords(List<Double> vertexCoords, List<Double> texCoords) {
  if ((vertexCoords.size() % 3) != 0) {
    throw new RuntimeException("Vertex coordinates size is " + vertexCoords.size() + "; must be a multiple of 3");
  }
  if ((texCoords.size() % 2) != 0) {
    throw new RuntimeException("Texture coordinates size is " + texCoords.size() + "; must be a multiple of 2");
  }
  if (vertexCoords.size() / 3 != texCoords.size() / 2) {
    throw new RuntimeException("There is vertex data for " + vertexCoords.size() / 3 + " triangle(s), "
            + "and texture data for " + texCoords.size() / 2 + " triangle(s) -- these should match");
  }

  float[] data = new float[vertexCoords.size() + texCoords.size()];
  int vertexIndex = 0;
  int texIndex = 0;
  int dataIndex = 0;
  for (int i = 0; i < vertexCoords.size() / 3; i++) {
    data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue();
    data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue();
    data[dataIndex++] = (float) vertexCoords.get(vertexIndex++).doubleValue();
    data[dataIndex++] = (float) texCoords.get(texIndex++).doubleValue();
    data[dataIndex++] = (float) texCoords.get(texIndex++).doubleValue();
  }
  Mesh mesh = new Mesh( true, vertexCoords.size() / 3, 0,
          new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
          new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
  mesh.setVertices(data);
  return mesh;
}
 
Example #18
Source File: Main.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
private Mesh buildMeshFromVertices(List<Double> vertexCoords) {
  if ((vertexCoords.size() % 3) != 0) {
    throw new RuntimeException("Vertex coordinates size is " + vertexCoords.size() + "; must be a multiple of 3");
  }
  float[] data = new float[vertexCoords.size()];
  for (int i = 0; i < vertexCoords.size(); i++) {
    data[i] = (float) vertexCoords.get(i).doubleValue();
  }
  Mesh mesh = new Mesh( true, vertexCoords.size() / 3, 0,
          new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
  mesh.setVertices(data);
  return mesh;
}
 
Example #19
Source File: FrametimeGraph.java    From Cubes with MIT License 5 votes vote down vote up
private static ShaderProgram createShaderProgram() {
  String vertex = "attribute vec4 " + ShaderProgram.POSITION_ATTRIBUTE + ";\n";
  vertex += "uniform mat4 u_projModelView;\n";
  vertex += "void main() {\n" + "   gl_Position = u_projModelView * " + ShaderProgram.POSITION_ATTRIBUTE + ";\n";
  vertex += "   gl_PointSize = 1.0;\n";
  vertex += "}\n";
  String fragment = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n";
  fragment += "void main() {\n" + "   gl_FragColor = vec4(1, 0, 0, 1)"; //#00ff00ff
  fragment += ";\n}";
  return new ShaderProgram(vertex, fragment);
}
 
Example #20
Source File: WithoutShadowShader.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
static final public ShaderProgram createShadowShader() {
	final String vertexShader = "attribute vec4 a_position;\n" //
			+ "attribute vec2 a_texCoord;\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "\n" //
			+ "void main()\n" //
			+ "{\n" //
			+ "   v_texCoords = a_texCoord;\n" //
			+ "   gl_Position = a_position;\n" //
			+ "}\n";

	//this is allways perfect precision
	final String fragmentShader = "#ifdef GL_ES\n" //
			+ "precision mediump float;\n" //
			+ "#endif\n" //
			+ "varying vec2 v_texCoords;\n" //
			+ "uniform sampler2D u_texture;\n" //
			+ "void main()\n"//
			+ "{\n" //
			+ "gl_FragColor = texture2D(u_texture, v_texCoords);\n"
			+ "}\n";
	ShaderProgram.pedantic = false;
	ShaderProgram woShadowShader = new ShaderProgram(vertexShader,
			fragmentShader);
	if (woShadowShader.isCompiled() == false) {
		Gdx.app.log("ERROR", woShadowShader.getLog());

	}

	return woShadowShader;
}
 
Example #21
Source File: ShaderManager.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
public static void dispose() {
	for(Entry<String, ShaderProgram> e : shaders.entrySet()) {
		if(e.getValue() != null) {
			e.getValue().dispose();
		}
	}
}
 
Example #22
Source File: PaletteIndexedBatch.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public PaletteIndexedBatch(int size, ShaderProgram shader) {
  super(size);
  this.shader = shader;
  PALETTE_LOCATION    = shader.getUniformLocation("ColorTable");
  COLORMAP_LOCATION   = shader.getUniformLocation("ColorMap");
  BLENDMODE_LOCATION  = shader.getUniformLocation("blendMode");
  COLORMAPID_LOCATION = shader.getUniformLocation("colormapId");
  GAMMA_LOCATION      = shader.getUniformLocation("gamma");
}
 
Example #23
Source File: EditorTerrainShader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public EditorTerrainShader() {
    String vertexShader = "\n#define PICKER\n" + Gdx.files.classpath(VERTEX_SHADER).readString();
    String fragmentShader = "\n#define PICKER\n" + Gdx.files.classpath(FRAGMENT_SHADER).readString();

    program = new ShaderProgram(vertexShader, fragmentShader);
    if (!program.isCompiled()) {
        throw new GdxRuntimeException(program.getLog());
    }
}
 
Example #24
Source File: BasicColorPicker.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	boolean wasPedantic = ShaderProgram.pedantic;
	ShaderProgram.pedantic = false;
	super.draw(batch, parentAlpha);
	ShaderProgram.pedantic = wasPedantic;
}
 
Example #25
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 #26
Source File: PickerCommons.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private ShaderProgram loadShader (String vertFile, String fragFile) {
	ShaderProgram program = new ShaderProgram(
			Gdx.files.classpath("com/kotcrab/vis/ui/widget/color/internal/" + vertFile),
			Gdx.files.classpath("com/kotcrab/vis/ui/widget/color/internal/" + fragFile));

	if (program.isCompiled() == false) {
		throw new IllegalStateException("ColorPicker shader compilation failed. Shader: " + vertFile + ", " + fragFile + ": " + program.getLog());
	}

	return program;
}
 
Example #27
Source File: PickerCommons.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
ShaderProgram getBarShader (int mode) {
	switch (mode) {
		case ChannelBar.MODE_ALPHA:
		case ChannelBar.MODE_R:
		case ChannelBar.MODE_G:
		case ChannelBar.MODE_B:
			return rgbShader;
		case ChannelBar.MODE_H:
		case ChannelBar.MODE_S:
		case ChannelBar.MODE_V:
			return hsvShader;
		default:
			throw new IllegalStateException("Unsupported mode: " + mode);
	}
}
 
Example #28
Source File: CubesShaderProvider.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public void init(ShaderProgram program) {
  u_cameraposition = program.fetchUniformLocation("u_cameraposition", true);
  u_skycolor = program.fetchUniformLocation("u_skycolor", true);
  u_fogdistance = program.fetchUniformLocation("u_fogdistance", true);
  u_minfogdistance = program.fetchUniformLocation("u_minfogdistance", true);
}
 
Example #29
Source File: ShaderTest.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
private ShaderProgram loadShader(String fragFile) {
    ShaderProgram shader = new ShaderProgram(Gdx.files.internal("./assets/gfx/shaders/base.vert")
                                            , Gdx.files.internal("./assets/gfx/shaders/" + fragFile));
    if(!shader.isCompiled()) {
        System.out.println("Not compiled!");
    }
    
    //Good idea to log any warnings if they exist
    if (shader.getLog().length()!=0) {
        System.out.println(shader.getLog());
    }
    
    return shader;
}
 
Example #30
Source File: Renderer20.java    From fluid-simulator-v2 with Apache License 2.0 5 votes vote down vote up
private VertexAttribute[] buildVertexAttributes (boolean hasNormals, boolean hasColor, int numTexCoords) {
	Array<VertexAttribute> attribs = new Array<VertexAttribute>();
	attribs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
	if (hasNormals) attribs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
	if (hasColor) attribs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
	for (int i = 0; i < numTexCoords; i++) {
		attribs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i));
	}
	VertexAttribute[] array = new VertexAttribute[attribs.size];
	for (int i = 0; i < attribs.size; i++)
		array[i] = attribs.get(i);
	return array;
}