Creating some effects by editing pixels |
Creating some effects by editing pixels |
Pallav Nawani
|
Try
SDL_SetTextureColorMod(SDL_Texture* texture, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Uint8 Â Â Â Â r, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Uint8 Â Â Â Â g, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Uint8 Â Â Â Â b); To colorize a texture. Try RGB (100, 100, 100) to darken a texture and make it seem gray. Try RGB (80, 80, 140) to make it seem like night time (Dark Blue tint). Play with the values of r, g, and b to get the results you want. If you want to adjust alpha too, there is a separate function for that. Pallav Nawani IronCode Gaming Private Limited Website:Â http://www.ironcode.com Twitter:Â http://twitter.com/Ironcode_Gaming Facebook: http://www.facebook.com/Ironcode.Gaming Mobile: 9997478768 On Sat, Jul 12, 2014 at 6:57 PM, Grade wrote:
|
|||||||||||||
|
Grade
|
Thank you for your response !
I knew this function and it's very good indeed, and very fast ! However, I just tested with RGB (100, 100, 100), and it just seems to make the texture darker, and it really doesn't look like the wanted effect. I really want a grayscale effect juste like in a black & white picture. Is there any other function of this type that can make a texture gray ? Thank you in advance ! Grade. |
|||||||||||
|
Creating some effects by editing pixels |
Andreas Schiffler
Guest
|
You'd need to create a shader that removes the colors while drawing, or you could also calculate a second B/W texture and draw/mix that in as a primary/secondary rendering pass.
Here are some general references: http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/hlsl-greyscale-shader-tutorial-r3263 http://stackoverflow.com/questions/867653/how-to-implement-grayscale-rendering-in-opengl And SDL specific: https://hg.libsdl.org/SDL/file/default/test/testshader.c https://www.opengl.org/wiki/Tutorial2:_VAOs,_VBOs,_Vertex_and_Fragment_Shaders_%28C_/_SDL%29 On 7/12/2014 8:18 AM, Grade wrote:
|
|||||||||||||||
|
Creating some effects by editing pixels |
meklu
Guest
|
Isn't the range [0,255]? That looks like it should make the image less than half as bright as the original. You could try RGB(255, 255, 255).
-- Mwlker Narikka Grade kirjoitti Sat Jul 12 2014 18:18:39 GMT+0300 (EEST):
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
Creating some effects by editing pixels |
Melker Narikka
Guest
|
Oops, never mind, that is a multiplier on the color value.What you'd want is to sum up the individual color channels and divide those by three.
-- Melker Narikka On Sat, Jul 12, 2014 at 6:43 PM, wrote:
|
|||||||||||||||
|
Creating some effects by editing pixels |
Andreas Schiffler
Guest
|
The Y = (R+G+B)/3 formula is a quick-n-dirty calculation and will not always give good results. An even faster calculation is the approximation Y = (R >> 2) + (G >> 1) + (B >> 2) which is slightly more accurate. The "photo quality" conversion involves a bit more math. Wikipedia quotes the formula Y = 0.2126 R + 0.7152 G + 0.0722 B but people also use Y = 0.299 R + 0.587 G + 0.114 B. Generally one should apply a gamma correction to convert the resulting Y_linear to Y_sRGB. This could be done on the CPU with a 256 byte lookup table. The resulting Y_sRGB value (a byte) can then be used in as the component values for the RGB pixel, i.e. Uint8 pixel[4] = { Y_sRGB, Y_sRGB, Y_sRGB, 255 };. When drawing the grayscale texture, it can still be modulated for brightness and color with SDL_GetTextureColorMod() or transparency using SDL_GetTextureAlphaMod().
Here is a short SDL2 tutorial with sample images: http://www.programmersranch.com/2014/02/sdl2-converting-image-to-grayscale.html Other References: http://en.wikipedia.org/wiki/Grayscale#Colorimetric_.28luminance-preserving.29_conversion_to_grayscale http://www.fourcc.org/fccyvrgb.php http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html On 7/12/2014 8:45 AM, Melker Narikka wrote:
|
|||||||||||||||||||
|
Creating some effects by editing pixels |
Sik
|
2014-07-12 21:27 GMT-03:00, Andreas Schiffler:
I just had to deal with this last night when I implemented monochrome mode in my game, turns out the former is meant to be used with sRGB (i.e. gamma-corrected) values. If you use linear RGB then you should consider using the latter instead. In practice both seem way off (blue looks darker than it should), but I have no idea what are the correct coefficients. In fact they seem to vary depending on the person (which probably exacerbates the blue problem for me, since I don't see it darker than red, against what everybody says about the human eye). _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|