Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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 1977 times)
0 Members and 1 Guest are viewing this topic.
Offline blizzard

Senior Newbie





« Posted 2012-03-06 15: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
« Reply #1 - Posted 2012-03-06 16:40:55 »

A 3 line shader?

Myomyomyo.
Offline blizzard

Senior Newbie





« Reply #2 - Posted 2012-03-07 12: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 12: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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
//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 13: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
« Reply #5 - Posted 2012-03-07 14: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:

1  
2  
3  
4  
5  
6  
7  
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.

Myomyomyo.
Offline blizzard

Senior Newbie





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

thanks
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.

xsi3rr4x (52 views)
2014-04-15 18:08:23

BurntPizza (49 views)
2014-04-15 03:46:01

UprightPath (64 views)
2014-04-14 17:39:50

UprightPath (46 views)
2014-04-14 17:35:47

Porlus (63 views)
2014-04-14 15:48:38

tom_mai78101 (88 views)
2014-04-10 04:04:31

BurntPizza (147 views)
2014-04-08 23:06:04

tom_mai78101 (244 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org 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‑gaming.org
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!