Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Schizm

Pages: [1]
1
General / Re: Palette shader problem
« on: April 26, 2012, 12:23:45 pm »
Time to bump.

2
General / Re: Palette shader problem
« on: April 24, 2012, 01:23:49 am »
Not sure, why I did this (never thought it will help), but I've changed 1D-texture's width to 255 instead of 256. Now colors are correct, but FPS then drops from 120 to 6-8. How to reproduce same effect, but in more OpenGL-friendly way? (index = (index / 256.0) * 255.0) does not work as expected, producing only more wrong colors.

Texture initialization code:
        glGenTextures(1, &this->m_PaletteTex);
        glBindTexture(GL_TEXTURE_1D, this->m_PaletteTex);

        // here I tried changing 256 to 255, which fixed color offsets but introduced massive lag
        glTexImage1D(GL_TEXTURE_1D, 0, 4, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, this->m_Palette);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);

        glBindTexture(GL_TEXTURE_1D, 0);
 

3
General / Re: Rotate using mouse without constraint of the window
« on: April 24, 2012, 12:40:07 am »
You need four variables: delta_x, delta_y, last_x and last_y;
The first two will contain mouse cursor position relative to last frame drawn, the last are used to store previous pointer position.

1. Set delta_x, delta_y to zero.
2. Receive mouse event.
3. delta_x = last_x-event.MouseMove.X; delta_y = last_y-event.MouseMove.Y;
4. last_x += delta_x; last_y += delta_y;
5. Process received values (delta_x and delta_y).
6. Use sf::Window::SetCursorPosition(window_center_x, window_center_y) to set cursor position to window's center.
7. Repeat from step 1.

The method described above is fairly simple and is used by most 3-D games, especially FPS ones.

4
General / Palette shader problem
« on: April 24, 2012, 12:27:45 am »
Well, it's not really related to SFML, but I see that's common thing in General forum :)

I'm writing some game engine (in fact, reverse-engineering one old game).
I need to be able to load an image (it's in game's internal format, uses palette and per-pixel alpha) and then swap it's palette at rendering time; First I used to load full copy of the image for each needed palette, but that seems to consume too much memory (over 70mb per sprite, nearly 200 different possible sprites/palettes, all on the same game level). So then I left old solution as fallback if shaders are not supported and started writing a shader that will apply a palette to my image, so memory usage can be reduced to ~10mb or even ~5mb per sprite (~100 images).

Now, look at this screenshot:

As you probably can notice, the colors are a bit off their real index, but I'm not sure why it happened.

This is how it's supposed to look like (with shaders disabled):


The image loading code is all ok (see second screenshot). Problem should be in the shader code, but I'm not really sure where is it.

Fragment shader code:
#extension GL_ARB_texture_rectangle : enable

uniform sampler2DRect rec1;
uniform sampler1D palette;

void main(void)
{
        vec4 oldcol = texture2DRect(rec1, gl_TexCoord[0].st);
        float index = (oldcol.r + oldcol.g + oldcol.b) / 3;
        vec4 newcol = texture1D(palette, index);

        gl_FragColor.rgb = newcol.rgb * gl_Color.rgb;
        gl_FragColor.a = oldcol.a * gl_Color.a;
}

rec1 = GL_TEXTURE_RECTANGLE_ARB texture containing palette index in (r,g,b) and per-pixel alpha.
palette = GL_TEXTURE_1D texture, 256 texels wide, containing palette colors.

I'm really stuck here, please help :(

Pages: [1]