tommyettinger / colorful-gdx

A libGDX mechanism to manipulate colors in powerful ways
Apache License 2.0
75 stars 0 forks source link

Default shader issue #4

Closed slasherbane closed 1 year ago

slasherbane commented 2 years ago

Hi ^^,

i m creating a game with libgdx and the tile concept. I try to recolor some unit on a tile depending on their faction but i have a strange issue and i don't know how to solve it . Without the the lib or with the default sprite batch , the blue recolor is....weeeiiiiiird : image

and ith the default shader of ColorfulBatch:

image

The units deseappear from wiew when i use some shader ....why ? Any idea please ?

tommyettinger commented 2 years ago

Sorry for my late reply, let's see here...

Are you using the ColorfulBatch in the rgb package? That's usually the one that makes the most sense in an existing project, since libGDX only offers RGB colors (well, and limited support for HSV). I'm guessing you're using one of the other packages, though, like oklab or ipt_hq, because both of those would treat a batch color of (0.25f, 0.25f, 1.0f, 1.0f) (which is light blue in RGB) as darker yellow-green. Oklab or IPT_HQ colors are best obtained from the Palette in their package or created anew using ColorTools, also in that package. Really, that's true for all of the packages; it isn't intended to mix the different color space packages. I don't know why your sprites disappeared, and I haven't seen any of your code that might help diagnose this. The main thing I can think of is that ColorfulBatch can't render normal libGDX Sprites (maybe it can, but I wouldn't expect it to look 100% right), but it can render the slightly-changed ColorfulSprites from the same package as the ColorfulBatch. A ColorfulSprite is meant to allow the full configuration that a ColorfulBatch has, so you can change colors additively with batch.setColor() and multiplicatively with batch.setTweak(). A normal SpriteBatch can only do multiplicative color changes, and it can't increase any RGBA channel.

It's entirely possible you don't need ColorfulBatch for what you want to do. If you want to keep using existing Sprite code or code in libraries like TextraTypist (anything that depends on details of SpriteBatch is incompatible with ColorfulBatch), you can often do just fine creating a SpriteBatch with an already-written shader from the Shaders class in colorful-gdx. Several of these are meant for colorizing existing images. The docs for each shader that's meant for usage in Shaders say what fragment and what vertex shader go together. An example of how I do this:

// in create()
        ShaderProgram shader = new ShaderProgram(Shaders.vertexShader, Shaders.fragmentShaderColorize);
        if(!shader.isCompiled()){
            System.out.println("Shader failed to compile: " + shader.getLog());
        }
        // this should be declared outside, since it is used as a normal SpriteBatch in render()
        colorizeBatch = new SpriteBatch(1024, shader); // 1000 is size of a buffer inside SpriteBatch; it's the default.

The libGDX Discord may be a good place to ask for help if the shaders aren't making sense; I'm usually online there. https://discord.gg/SQew7sjPvU You can probably tell I don't check GitHub notifications all the time...

slasherbane commented 2 years ago

thnks for you response, i'm using the rgb package :) . i could try to change ssettings to the color batch with your advise .

thaks for your help

slasherbane commented 2 years ago

i try and i achieved something interessting thks a lot ^^ image

slasherbane commented 2 years ago

i think my original sprite need to be white to do the right job later

slasherbane commented 2 years ago

i thing , because i m not using colorfulSprite, the sprite load transparent for some reason and not shows on the screen

tommyettinger commented 2 years ago

i think my original sprite need to be white to do the right job later

It doesn't, that's the main point of ColorfulBatch and the RGB code in Shaders here. I don't know what your art looks like before its colors are changed; that would help a lot...

tommyettinger commented 1 year ago

Almost a year with no extra info, so I'm just going to close this now. The current code should be able to render Sprite using ColorfulBatch, but a Sprite doesn't contain some color info (the "tweak," multiplicative changes instead of additive ones), so that just gets pulled from the ColorfulBatch settings.