Happy to share any other code that may be relevant as well. Been puzzling over it for a few hours now. If anyone can identify what is going wrong here I would be so grateful. Please note that since I have six palettes, I plan to use discrete alpha values of 0.0, 0.1, 0.2, 0.3, 0.4 and 0.5 to determine which palette to swap to. c2 is thus the colour at that position, and what must be drawn to the screen. pos should then contain the corresponding position on the swap texture. I want c1 to contain the colour that would normally be drawn. } NewTexture is passed in containing the left, top, right and bottom of the swap texture in memory. Vec4 c2 = texture2D( gm_BaseTexture, pos ) Vec2 pos = vec2(NewTexture + (c1.r * ww), NewTexture + (c1.a * 2.0 * hh)) Vec4 c1 = texture2D( gm_BaseTexture, v_vTexcoord) I suspect it has something to do with me having a poor understanding of how texture pages work, but I can't work it out for the life of me.įloat ww = NewTexture - NewTexture įloat hh = NewTexture - NewTexture It is showing some promising features but the colours seem to be inverted somewhat, with darker shades being made light and vice versa. The bottom image is that same surface but being drawn through my shader. You can see it is a 160x120 section of the screen (which happens to contain the sunset portion of the palette) at a uniform 0.2 alpha, except for a radius around the mouse which is 0.0 alpha. The image below and left of the palette is the application surface after being drawn over the alpha mask. Each vertical strip of the palette at the top is sliced off and glued in place on the new texture which is 256 pixels wide. Running my code I get the following result:įor context, the top image is my complete palette - all the colours are along the top, with their various degrees of shading extending downwards (each of those shades is taken from elsewhere on the palette).īelow and right of that (the tiny coloured lines) is the texture I generate at runtime to determine how to swap palettes. Step 4: Draw the surface with a shader that detects the source colour and pinpoints the new colour within texture memory. An alpha of 0.0 means no shifting, and an alpha of 0.2 means shift two shades darker, etc. The colours will remain as they were on the application surface, but the alpha component will be used to indicate how far the colour is shifted. Step 3: Draw the application surface on top of the alpha mask, using the source colour but the destination alpha. Have drawn this in-game as well and it appears as I was expecting. For simplicity now, though, I am just using a cleared rectangle of alpha 0.2, with a spotlight of alpha 0.0 centred on the mouse. In future I plan to use six bands of shading - one for each of the six different palettes I have made. Step 2: Draw an alpha mask from all light sources in the room. Have drawn this texture in-game and it appears correct. A new sprite is created with a width of 255, and each strip of the palette is drawn at the x-position corresponding to the value of the red component. Each colour in my palette has a unique red component, and the application surface will always be drawn with an alpha value of 1.0 anyway. I wanted to hijack the red and alpha channels of the drawn pixel to determine the shift of the colour (similar to this article). I don't like the look of the classic alpha mask lighting as simply drawing a partially transparent black region over the screen gives you continuous shades rather than the discrete ones that exist on the art palette. My plan was to create a shader which performs a palette swap for regions of the screen. I have been keen to learn about shaders since they were introduced and am playing around with a concept at the moment which I thought would make an ideal first step of my journey.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |