com.badlogic.gdx.graphics.Pixmap.Format Java Examples

The following examples show how to use com.badlogic.gdx.graphics.Pixmap.Format. 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: PostProcessor.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
public PostProcessor( int fboWidth, int fboHeight, boolean useDepth, boolean useAlphaChannel, boolean use32Bits,
		TextureWrap u, TextureWrap v ) {
	if( use32Bits ) {
		if( useAlphaChannel ) {
			fbFormat = Format.RGBA8888;
		} else {
			fbFormat = Format.RGB888;
		}
	} else {
		if( useAlphaChannel ) {
			fbFormat = Format.RGBA4444;
		} else {
			fbFormat = Format.RGB565;
		}
	}

	composite = newPingPongBuffer( fboWidth, fboHeight, fbFormat, useDepth );
	setBufferTextureWrap( u, v );

	pipelineState = new PipelineState();

	capturing = false;
	hasCaptured = false;
	enabled = true;
	this.useDepth = useDepth;
}
 
Example #2
Source File: IBLBuilder.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
/**
 * Create an environment map, to be used with {@link net.mgsx.gltf.scene3d.scene.SceneSkybox}
 * @param size base size (width and height) for generated cubemap
 * @return generated cubemap, caller is responsible to dispose it when no longer used.
 */
public Cubemap buildEnvMap(int size){
	FrameBufferCubemap fbo = new FrameBufferCubemap(Format.RGBA8888, size, size, false){
		@Override
		protected void disposeColorTexture(Cubemap colorTexture) {
		}
	};
	fbo.begin();
	while(fbo.nextSide()){
		Gdx.gl.glClearColor(0, 0, 0, 0);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		CubemapSide side = fbo.getSide();
		renderGradient(side, 0);
		renderLights(side, false);
	}
	fbo.end();
	Cubemap map = fbo.getColorBufferTexture();
	fbo.dispose();
	return map;
}
 
Example #3
Source File: IBLBuilder.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an irradiance map, to be used with {@link net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute#DiffuseEnv}
 * @param size base size (width and height) for generated cubemap
 * @return generated cubemap, caller is responsible to dispose it when no longer used.
 */
public Cubemap buildIrradianceMap(int size){
	
	FrameBufferCubemap fbo = new FrameBufferCubemap(Format.RGBA8888, size, size, false){
		@Override
		protected void disposeColorTexture(Cubemap colorTexture) {
		}
	};
	
	fbo.begin();
	while(fbo.nextSide()){
		Gdx.gl.glClearColor(0, 0, 0, 0);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		CubemapSide side = fbo.getSide();
		renderGradient(side, 0.5f);
		renderLights(side, true);
	}
	fbo.end();
	Cubemap map = fbo.getColorBufferTexture();
	fbo.dispose();
	return map;
}
 
Example #4
Source File: PomyuCharaLoader.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
private Texture transparentProcessing(Texture tex, int index, boolean[] flag) {
	//透過処理 右下の1pixelが透過色 選択画面アイコンは透過しない
	if(tex == null || flag[index]) {
		return tex;
	}
	Pixmap pixmap = new Pixmap( tex.getWidth(), tex.getHeight(), Format.RGBA8888 );
	int transparentColor = tex.getTextureData().consumePixmap().getPixel(tex.getWidth() - 1, tex.getHeight() - 1);
	for(int x = 0; x < tex.getWidth(); x++) {
		for(int y = 0; y < tex.getHeight(); y++) {
			if(transparentColor != tex.getTextureData().consumePixmap().getPixel(x, y)) {
				pixmap.drawPixel(x, y, tex.getTextureData().consumePixmap().getPixel(x, y));
			}
		}
	}
	tex.dispose();
	tex = new Texture( pixmap );
	pixmap.dispose();
	flag[index] = true;
	return tex;
}
 
Example #5
Source File: Renderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public Renderer () {
	try {
		lights = new Environment();
		lights.add(new DirectionalLight().set(Color.WHITE, new Vector3(-1, -0.5f, 0).nor()));

		spriteBatch = new SpriteBatch();
		modelBatch = new ModelBatch();

		backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true);
		backgroundTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

		font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"), false);

		camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example #6
Source File: TransitionManager.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
public TransitionManager (Rectangle viewport, boolean use32Bits, boolean useAlphaChannel, boolean useDepth) {
	this.viewport.set(viewport);
	transition = null;
	paused = false;
	fbFormat = Format.RGB565;
	usedepth = useDepth;

	if (use32Bits) {
		if (useAlphaChannel) {
			fbFormat = Format.RGBA8888;
		} else {
			fbFormat = Format.RGB888;
		}
	} else {
		if (useAlphaChannel) {
			fbFormat = Format.RGBA4444;
		} else {
			fbFormat = Format.RGB565;
		}
	}

	fbFrom = new FrameBuffer(fbFormat, (int)viewport.width, (int)viewport.height, useDepth);
	fbTo = new FrameBuffer(fbFormat, (int)viewport.width, (int)viewport.height, useDepth);
}
 
Example #7
Source File: ShaderTest.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
     * 
     */
    public ShaderTest() {        
        ShaderProgram.pedantic = false;
        
        vertBlur = loadShader("blurv.frag");
        horBlur = loadShader("blurh.frag");
        light = loadShader("light.frag");
        
        shader = loadShader("inprint.frag");
        
        this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        this.camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
//        camera.setToOrtho(false);
        transform = new Matrix4();
        camera.update();
        batch = new SpriteBatch();//1024, shader);
        batch.setShader(null);
        batch.setProjectionMatrix(camera.combined);
        batch.setTransformMatrix(transform);
        
        this.buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);    
        
        this.fboPing = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
        this.fboPong = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    }
 
Example #8
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
public static Pixmap toWhite(Pixmap img) {
    Pixmap alpha = new Pixmap(img.getWidth(), img.getHeight(), Format.RGBA8888);        
    //alpha.drawPixmap(img, 0, 0);
        
    int width = alpha.getWidth();
    int height = alpha.getHeight();
            
    //alpha.setColor(0xff00009f);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int col = img.getPixel(x, y);
            Color color = new Color(col);
            if ( color.a > 0.2f ) {
                alpha.drawPixel(x, y, Color.WHITE.toIntBits());
            }
        }
    }
    
    img.dispose();
    
    return alpha;
}
 
Example #9
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applying mask into image using specified masking color. Any Color in the
 * image that matches the masking color will be converted to transparent.
 * 
 * @param img The source image
 * @param keyColor Masking color
 * @return Masked image
 */
public static Pixmap applyMask(Pixmap img, Color keyColor) {
    Pixmap alpha = new Pixmap(img.getWidth(), img.getHeight(), Format.RGBA8888);        
    //alpha.drawPixmap(img, 0, 0);
        
    int width = alpha.getWidth();
    int height = alpha.getHeight();
    
    int colorMask = Color.rgba8888(keyColor);
    
    //alpha.setColor(0xff00009f);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int col = img.getPixel(x, y);
            if ( col != colorMask ) {
                alpha.drawPixel(x, y, img.getPixel(x, y));
            }
        }
    }
    return alpha;
}
 
Example #10
Source File: LightMap.java    From box2dlights with Apache License 2.0 6 votes vote down vote up
public LightMap(RayHandler rayHandler, int fboWidth, int fboHeight) {
	this.rayHandler = rayHandler;

	if (fboWidth <= 0)
		fboWidth = 1;
	if (fboHeight <= 0)
		fboHeight = 1;
	frameBuffer = new FrameBuffer(Format.RGBA8888, fboWidth,
			fboHeight, false);
	pingPongBuffer = new FrameBuffer(Format.RGBA8888, fboWidth,
			fboHeight, false);

	lightMapMesh = createLightMapMesh();

	shadowShader = ShadowShader.createShadowShader();
	diffuseShader = DiffuseShader.createShadowShader();

	withoutShadowShader = WithoutShadowShader.createShadowShader();

	blurShader = Gaussian.createBlurShader(fboWidth, fboHeight);

}
 
Example #11
Source File: Ssao.java    From uracer-kotd with Apache License 2.0 6 votes vote down vote up
public Ssao (int fboWidth, int fboHeight, Quality quality) {
	Gdx.app.log("SsaoProcessor", "Quality profile = " + quality.toString());
	float oscale = quality.scale;

	// maps
	occlusionMap = new PingPongBuffer((int)((float)fboWidth * oscale), (int)((float)fboHeight * oscale), Format.RGBA8888, false);

	// shaders
	shMix = ShaderLoader.fromFile("screenspace", "ssao/mix");
	shSsao = ShaderLoader.fromFile("ssao/ssao", "ssao/ssao");

	// blur
	blur = new Blur(occlusionMap.width, occlusionMap.height);
	blur.setType(BlurType.Gaussian5x5b);
	blur.setPasses(2);

	createRandomField(16, 16, Format.RGBA8888);
	// enableDebug();
}
 
Example #12
Source File: TexturePacker.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
private int getBufferedImageType (Format format) {
	switch (settings.format) {
	case RGBA8888:
	case RGBA4444:
		return BufferedImage.TYPE_INT_ARGB;
	case RGB565:
	case RGB888:
		return BufferedImage.TYPE_INT_RGB;
	case Alpha:
		return BufferedImage.TYPE_BYTE_GRAY;
	default:
		throw new RuntimeException("Unsupported format: " + settings.format);
	}
}
 
Example #13
Source File: ColorFadeTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
/** @param color the {@link Color} to fade to
 * @param interpolation the {@link Interpolation} method */
public ColorFadeTransition (Color color, Interpolation interpolation) {
	this.color = new Color(Color.WHITE);
	this.interpolation = interpolation;

	texture = new Texture(1, 1, Format.RGBA8888);
	Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
	pixmap.setColor(color);
	pixmap.fillRectangle(0, 0, 1, 1);
	texture.draw(pixmap, 0, 0);
}
 
Example #14
Source File: FadingGame.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void resize(int width, int height) {
    if (screen != null) screen.resize(width, height);
    if (nextScreen != null) nextScreen.resize(width, height);

    this.currentScreenFBO.dispose();
    this.nextScreenFBO.dispose();

    this.currentScreenFBO = new FrameBuffer(Format.RGBA8888, width, height, false);
    this.nextScreenFBO = new FrameBuffer(Format.RGBA8888, width, height, false);

}
 
Example #15
Source File: PickerCommons.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void createPixmap () {
	Pixmap whitePixmap = new Pixmap(2, 2, Format.RGB888);
	whitePixmap.setColor(Color.WHITE);
	whitePixmap.drawRectangle(0, 0, 2, 2);
	whiteTexture = new Texture(whitePixmap);
	whiteTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
	whitePixmap.dispose();
}
 
Example #16
Source File: World.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public void takeScreenshot(String filename, int w) {

		// get viewport
		IntBuffer results = BufferUtils.newIntBuffer(16);
		Gdx.gl20.glGetIntegerv(GL20.GL_VIEWPORT, results);

		int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth);

		FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false);

		fbo.begin();
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		draw();
		Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h);

		// restore viewport
		fbo.end(results.get(0), results.get(1), results.get(2), results.get(3));

		// Flip the pixmap upside down
		ByteBuffer pixels = pixmap.getPixels();
		int numBytes = w * h * 4;
		byte[] lines = new byte[numBytes];
		int numBytesPerLine = w * 4;
		for (int i = 0; i < h; i++) {
			pixels.position((h - i - 1) * numBytesPerLine);
			pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
		}
		pixels.clear();
		pixels.put(lines);

		PixmapIO.writePNG(EngineAssetManager.getInstance().getUserFile(filename), pixmap);

		fbo.dispose();
	}
 
Example #17
Source File: Art.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads a pixel map from the file system.
 * 
 * @param image
 * @return the Pixmap
 */
public static Pixmap loadPixmap(String image) {
    try {
        return TextureUtil.loadPixmap(image);
    } 
    catch (Exception e) {
        Cons.println("*** A problem occured loading an image: " + e);
    }
    
    return new Pixmap(10, 10, Format.RGBA8888);
}
 
Example #18
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
     * 
     */
    public GdxCanvas() {
        this.batch = new SpriteBatch();
        this.color = new Color();
        this.tmpColor = new Color();
        
        this.shaderStack = new Stack<>();
        this.zoomStack = new Stack<>();
        
        this.camera = new OrthographicCamera(getWidth(), getHeight());
        this.camera.setToOrtho(true, getWidth(), getHeight());
        this.camera.position.x = this.camera.viewportWidth/2;
        this.camera.position.y = this.camera.viewportHeight/2;
        this.camera.update();
        
        this.viewport = new FitViewport(getWidth(), getHeight(), camera);
        this.viewport.apply();
                
        this.generators = new HashMap<String, FreeTypeFontGenerator>();
        this.fonts = new HashMap<String, BitmapFont>();
        this.bounds = new GlyphLayout();
                
        this.transform = new Matrix4();
        //this.batch.setTransformMatrix(transform);
                
        //Matrix4 projection = new Matrix4();
        //projection.setToOrtho( 0, getWidth(), getHeight(), 0, -1, 1);
        //this.batch.setProjectionMatrix(projection);
        
//        this.wHeight = getHeight();
        this.batch.setProjectionMatrix(this.camera.combined);
        
        this.shapes = new ShapeRenderer();
        //this.shapes.setTransformMatrix(transform);    
//        this.shapes.setProjectionMatrix(projection);
        //this.shapes.setProjectionMatrix(camera.combined);
        
        this.fbo = new FrameBuffer(Format.RGBA8888, getWidth(), getHeight(), false);
    }
 
Example #19
Source File: GlyphPage.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/** @param pageWidth The width of the backing texture.
 * @param pageHeight The height of the backing texture. */
GlyphPage (UnicodeFont unicodeFont, int pageWidth, int pageHeight) {
	this.unicodeFont = unicodeFont;
	this.pageWidth = pageWidth;
	this.pageHeight = pageHeight;

	texture = new Texture(pageWidth, pageHeight, Format.RGBA8888);
}
 
Example #20
Source File: MainMenuInterface.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
private void setUpSkin() {
	Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
	pixmap.setColor(Color.LIGHT_GRAY);
	pixmap.fill();
	skin.add("grey", new Texture(pixmap));
	titleSprite.setX(TITLE_SPRITE_POS_X);
	titleSprite.setY(TITLE_SPRITE_POS_Y);

	LabelStyle labelStyle = new LabelStyle();
	skin.add("default", finePrint);
	labelStyle.font = skin.getFont("default");
	skin.add("default", labelStyle);

	CheckBoxStyle checkBoxStyle = new CheckBoxStyle();
	checkBoxStyle.checkboxOff = skin.newDrawable("grey", Color.LIGHT_GRAY);
	checkBoxStyle.checkboxOn = skin.newDrawable("grey", Color.LIGHT_GRAY);
	checkBoxStyle.font = skin.getFont("default");
	checkBoxStyle.checkboxOff = new TextureRegionDrawable(unchecked);
	checkBoxStyle.checkboxOn = new TextureRegionDrawable(checked);
	skin.add("default", checkBoxStyle);

	SliderStyle sliderStyle = new SliderStyle();
	sliderStyle.background = new TextureRegionDrawable(background);
	sliderStyle.knob = new TextureRegionDrawable(knob);
	skin.add("default-horizontal", sliderStyle);

	ButtonStyle buttonStyle = new ButtonStyle();
	skin.add("default", buttonStyle);

	TextButtonStyle textButtonStyle = new TextButtonStyle();
	textButtonStyle.font = skin.getFont("default");
	textButtonStyle.up = new NinePatchDrawable(patchBox);
	skin.add("default", textButtonStyle);
}
 
Example #21
Source File: PingPongBuffer.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
/** Creates a new ping-pong buffer and owns the resources. */
public PingPongBuffer( int width, int height, Format frameBufferFormat, boolean hasDepth ) {
	ownResources = true;
	owned1 = new FrameBuffer( frameBufferFormat, width, height, hasDepth );
	owned2 = new FrameBuffer( frameBufferFormat, width, height, hasDepth );
	set( owned1, owned2 );
}
 
Example #22
Source File: BGDrawer.java    From libGDX-Path-Editor with Apache License 2.0 5 votes vote down vote up
public BGDrawer() {
	renderer = new ShapeRenderer();
	
	Pixmap p = new Pixmap(4, 4, Format.RGBA4444);
	p.setColor(0.698f, 0.698f, 0.698f, 1f);
	p.fill();
	overlay = new Texture(p);
	p.dispose();
	
	t = new Sprite(overlay);
	b = new Sprite(overlay);
	l = new Sprite(overlay);
	r = new Sprite(overlay);
}
 
Example #23
Source File: VfxManager.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
public VfxManager(Format fboFormat, int bufferWidth, int bufferHeight) {
    this.width = bufferWidth;
    this.height = bufferHeight;

    this.context = new VfxRenderContext(fboFormat, bufferWidth, bufferHeight);

    // VfxFrameBufferPool will manage both ping-pong VfxFrameBuffer instances for us.
    this.pingPongWrapper = new VfxPingPongWrapper(context.getBufferPool());
}
 
Example #24
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 #25
Source File: CCPanel.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    Table table = new Table();

    Size size = widget.getSize();
    if (widget.getComboBoxIndex() == 0) { // 无颜色

    } else if (widget.getComboBoxIndex() == 1 && widget.getBackColorAlpha() != 0) {// 单色
        Pixmap pixmap = new Pixmap((int) size.getX(), (int) size.getY(),
            Format.RGBA8888);

        pixmap.setColor(editor.getColor(widget.getSingleColor(),
            widget.getBackColorAlpha()));

        pixmap.fill();

        Drawable d = new TextureRegionDrawable(new TextureRegion(
            new Texture(pixmap)));
        table.setBackground(d);
        pixmap.dispose();
    }

    if (widget.getFileData() != null) {// Panel的图片并不是拉伸平铺的!!.但是这里修改为填充
        Drawable tr = editor.findDrawable(widget, widget.getFileData());
        if (tr != null) {
            Image bg = new Image(tr);
            bg.setPosition((size.getX() - bg.getWidth()) / 2,
                (size.getY() - bg.getHeight()) / 2);
            // bg.setFillParent(true);
            bg.setTouchable(Touchable.disabled);

            table.addActor(bg);
        }
    }

    table.setClip(widget.isClipAble());

    return table;
}
 
Example #26
Source File: Art.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public static Texture newTexture (String name, boolean mipMap) {
	Texture t = new Texture(Gdx.files.internal(name), Format.RGBA8888, mipMap);

	if (mipMap) {
		t.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Nearest);
	} else {
		t.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
	}

	return t;
}
 
Example #27
Source File: IBLBuilder.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an radiance map, to be used with {@link net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute#SpecularEnv}
 * generated cubemap contains mipmaps in order to perform roughness in PBR shading
 * @param levels mipMapLevels how many mipmaps level, eg. 10 levels produce a 1024x1024 cubemap with mipmaps.
 * @return generated cubemap, caller is responsible to dispose it when no longer used.
 */
public Cubemap buildRadianceMap(final int mipMapLevels){
	Pixmap[] maps = new Pixmap[mipMapLevels * 6];
	int index = 0;
	for(int level=0 ; level<mipMapLevels ; level++){
		int size = 1 << (mipMapLevels - level - 1);
		FrameBuffer fbo = new FrameBuffer(Format.RGBA8888, size, size, false);
		fbo.begin();
		for(int s=0 ; s<6 ; s++){
			Gdx.gl.glClearColor(0, 0, 0, 0);
			Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
			
			CubemapSide side = CubemapSide.values()[s];
			
			float blur = (float)level / (float)mipMapLevels;
			
			renderGradient(side, blur);
			renderLights(side, false);
			
			maps[index] = ScreenUtils.getFrameBufferPixmap(0, 0, size, size);
			index++;
		}
		fbo.end();
		fbo.dispose();
	}
	FacedMultiCubemapData data = new FacedMultiCubemapData(maps, mipMapLevels);
	Cubemap map = new Cubemap(data);
	map.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
	return map;
}
 
Example #28
Source File: Ssao.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
/** Computes random field for the ssao shader */
private void createRandomField (int width, int height, Format format) {
	randomField = new Texture(width, height, format);
	randomField.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
	randomField.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);

	Pixmap pixels = new Pixmap(width, height, format);
	ByteBuffer bytes = pixels.getPixels();
	int wrote = 0;

	while (wrote < width * height * 4) {
		float x = (MathUtils.random() - 0.5f) * 2.0f;
		float y = (MathUtils.random() - 0.5f) * 2.0f;
		float z = (MathUtils.random() - 0.5f) * 2.0f;
		float l = (float)Math.sqrt(x * x + y * y + z * z);
		if (l <= 1.0f && l > 0.1f) {
			x = (x + 1.0f) * 0.5f;
			y = (y + 1.0f) * 0.5f;
			z = (z + 1.0f) * 0.5f;
			bytes.put((byte)(x * 255f));
			bytes.put((byte)(y * 255f));
			bytes.put((byte)(z * 255f));
			bytes.put((byte)255);
			wrote += 4;
		}
	}

	bytes.flip();
	randomField.draw(pixels, 0, 0);
	pixels.dispose();
}
 
Example #29
Source File: LightShafts.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public LightShafts (int fboWidth, int fboHeight, Quality quality) {
	Gdx.app.log("LightShafts", "Quality profile = " + quality.toString());
	float oscale = quality.scale;

	oneOnW = 1f / (float)Config.Graphics.ReferenceScreenWidth;
	oneOnH = 1f / (float)Config.Graphics.ReferenceScreenHeight;

	// maps
	occlusionMap = new PingPongBuffer((int)((float)fboWidth * oscale), (int)((float)fboHeight * oscale), Format.RGBA8888, false);

	// shaders
	shShafts = ShaderLoader.fromFile("screenspace", "lightshafts/lightshafts");
	combine = new Combine();
	threshold = new Threshold();

	// blur
	blur = new Blur(occlusionMap.width, occlusionMap.height);
	blur.setType(BlurType.Gaussian5x5b);

	blur.setPasses(2);
	int w = Gdx.graphics.getWidth();
	if (w >= 1920)
		blur.setPasses(4);
	else if (w >= 1680)
		blur.setPasses(3);
	else if (w >= 1280) blur.setPasses(2);

	setParams(16, 0.0034f, 1f, 0.84f, 5.65f, 1f, Config.Graphics.ReferenceScreenWidth / 2,
		Config.Graphics.ReferenceScreenHeight / 2);

	// enableDebug();
}
 
Example #30
Source File: DirectionalShadowLight.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public DirectionalShadowLight(int shadowMapWidth, int shadowMapHeight, float shadowViewportWidth,
		float shadowViewportHeight, float shadowNear, float shadowFar) {
	fbo = new FrameBuffer(Format.RGBA8888, shadowMapWidth, shadowMapHeight, true);
	cam = new OrthographicCamera(shadowViewportWidth, shadowViewportHeight);
	cam.near = shadowNear;
	cam.far = shadowFar;
	textureDesc = new TextureDescriptor();
	textureDesc.minFilter = textureDesc.magFilter = Texture.TextureFilter.Nearest;
	textureDesc.uWrap = textureDesc.vWrap = Texture.TextureWrap.ClampToEdge;
}