Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (549)
Games in Android Showcase (139)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Is it possible to change the alpha range on the GPU ?  (Read 2154 times)
0 Members and 1 Guest are viewing this topic.
Offline blizzard

Senior Newbie

« Posted 2012-03-06 14:57:55 »

Hello experts,

I hope you can help me.

I draw thousands of colored quads by using the Quadstrip and Quads functionality.
The vertices and colors are stored in vbo buffers and it works well and fast.

I use blending to just  create a let me say a brightness effect

glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ZERO) this works also well.

Now I want to adapt the alpha range to the lowest and highest value of my received alpha value
to spread the alpha range exactly to my maximum ranges.

normally :
alpha 0
my lowest value 0,234
my highest value 0,822
alpha 1

I need:
alpha 0 mapped to 0,234
alpha 1 mapped to 0,822

Has anybody an idea how I can solve this  so that the change affect directly the drawing of my stored quads in the vbo´s .
Is there a OGL functionality available or is a shader a solution (I never wrote one )
Thanks for your answers

Offline theagentd

« JGO Bitwise Duke »

Medals: 385
Projects: 2
Exp: 8 years

« Reply #1 - Posted 2012-03-06 15:40:55 »

A 3 line shader?

Offline blizzard

Senior Newbie

« Reply #2 - Posted 2012-03-07 11:16:25 »

Sorry I don´t understand your question .
I don´t know very much about shaders, can a shader be used to solve my problem ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Danny02
« Reply #3 - Posted 2012-03-07 11:37:04 »

a shader can manipulate your output color.
And so, you can of course only change the alpha channel if you wish.

you could do just something like this
//vertex shader(just your standart one):
in vec4 in_position;
in vec2 in_texcoords;

out vec2 texcoords

uniform mat4 MVP_Matrix;

void main()
   texcoords = in_texcoords;
   glPosition = MVP_Matrix * in_position;

//fragment shader:
in vec2 texcoords;
uniform sampler2D colormap;

uniform float low, high;

void main(){
  vec4 color = texture(colormap, texcoords);
  color.a = color.a * (high-low) + low
  gl_FragColor = color;
Offline blizzard

Senior Newbie

« Reply #4 - Posted 2012-03-07 12:59:12 »

Thank you for the answer ..
A good information that a fragment shader can solve the problem.
I have to read a little bit more about shader programming, at the moment I did not unstand your code
because of less knowledge.
I use jogl to acces the OGL interface and I will look for examples

Is it possible to set new values from my program on the cpu during the shaders is working ?
Offline theagentd

« JGO Bitwise Duke »

Medals: 385
Projects: 2
Exp: 8 years

« Reply #5 - Posted 2012-03-07 13:05:18 »

If you stick to earlier OpenGL versions you don't even need a vertex shader. You only need a very small fragment shader:

uniform sampler2D sampler;
uniform float low, high;

void main(){
    gl_FragColor = texture2D(sampler, gl_TexCoord[0]);
    gl_FragColor.a = gl_FragColor.a * (high-low) + low;

You can also change the high and low uniforms into constants if you don't need to be able to set them at runtime, which would make the Java code to setup the shader a little bit simpler. Well, Danny02 put it pretty well, but that's a newer GLSL version which is a bit harder for beginners.

Offline blizzard

Senior Newbie

« Reply #6 - Posted 2012-03-07 14:00:10 »

so I will start reading shader information :-)
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Archive (25 views)
2015-01-29 04:26:08

theagentd (22 views)
2015-01-28 15:33:52

GamerIDGoesHere (32 views)
2015-01-27 01:23:23

GamerIDGoesHere (33 views)
2015-01-27 01:22:15

CopyableCougar4 (40 views)
2015-01-27 00:34:41

CopyableCougar4 (28 views)
2015-01-26 04:47:56

Olo (19 views)
2015-01-25 21:26:00

Olo (26 views)
2015-01-25 18:44:22

Robo11 (43 views)
2015-01-25 06:14:26

basil_ (34 views)
2015-01-17 22:29:32
2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!