Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 6:13 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Mar 31, 2012 7:44 pm 
Offline

Joined: Thu Mar 29, 2012 5:17 pm
Posts: 7
Hi

Along with Slick release, there is a transparent color test class, and it works fine against single solid color.
However, some case is that there are gradual colors, for example, there are several grey/black colors. How to make it transparent?
Please refer to the following image for details. Thanks.
Attachment:
File comment: Remove the black color.
blank.PNG
blank.PNG [ 8.55 KiB | Viewed 647 times ]


Stev


Top
 Profile  
 
PostPosted: Sat Mar 31, 2012 9:59 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
A few options:
  • Simply modify your assets using Photoshop/GIMP and save them as transparent. This is the best solution if you don't need it done during runtime.
  • Try rendering it using Graphics.setDrawMode to MODE_SCREEN or MODE_ADD. May produce some odd effects.
  • Loop through the pixels manually and turn pixels to a certain degree of transparency based on how close to the color black they are. This requires a bit of work and will be very slow.
  • Learn to write this in a shader. This will give you the most control but it also has a higher system requirement and a bit more complexity.


Top
 Profile  
 
PostPosted: Sat Mar 31, 2012 10:40 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
For anybody interested, I wrote up a small test that uses shaders to mimic Photoshop's blend modes. In the OP's case it would be easier just to use MODE_SCREEN, although might have undesirable results depending on the two images.

You can plug in any of Kevin Bjorke's GLSL fragment shaders, e.g. color burn, color dodge, multiply, overlay, etc.
http://forum.processing.org/topic/glsl- ... -available

One day I will add this to some sort of Slick Shader wiki. :P And also look into multi texture coords, since this isn't very practical for different image sizes at the moment.

Source:
http://pastebin.com/9kMiTYp3

Vertex shader:
Code:
void main(){
   gl_TexCoord[0] = gl_MultiTexCoord0;
   gl_TexCoord[1] = gl_MultiTexCoord1;
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}


Fragment shader:
Code:
//
// BlendScreen.glsl
// 2010 Kevin Bjorke http://www.botzilla.com
// Uses Processing & the GLGraphics library
//

uniform sampler2D bottomSampler;
uniform sampler2D topSampler;
uniform float Opacity;


// utility function that assumes NON-pre-multiplied RGB...
vec4 final_mix(
       vec4 NewColor,
       vec4 BaseColor,
       vec4 BlendColor
) {
    float A2 = BlendColor.a * Opacity;
    vec3 mixRGB = A2 * NewColor.rgb;
    mixRGB += ((1.0-A2) * BaseColor.rgb);
    return vec4(mixRGB,BaseColor.a+BlendColor.a);
}

void main(void) // fragment
{
   vec4 botColor = texture2D(bottomSampler,gl_TexCoord[0].st);
   vec4 topColor = texture2D(topSampler,gl_TexCoord[0].st);
   vec4 comp = final_mix(1.0-(1.0-botColor)*(1.0-topColor),botColor,topColor);
    gl_FragColor = comp;
}


Last edited by davedes on Sun Apr 01, 2012 7:09 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sun Apr 01, 2012 1:41 am 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 194
Location: United State of California
Wow that is massively cool. I'll have to try that out.

_________________
Current Testing Machine:
Windows 7 x64, 4GB RAM DDR3, 3.3ghz AMD Athlon II X3 455, AMD Radeon HD 6800 series.


Top
 Profile  
 
PostPosted: Sun Apr 01, 2012 2:38 am 
Offline

Joined: Thu Mar 29, 2012 5:17 pm
Posts: 7
Thanks! Davedes.

I resolved it following this suggestion "Try rendering it using Graphics.setDrawMode to MODE_SCREEN or MODE_ADD. May produce some odd effects.".
Before rendering the image, I set the draw mode to MODE_ADD. It works well.

Thank you for your prompt, help reply! :D

Stev


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 5:52 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Thanks davdes :)

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group