Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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  
  Shaders with vec4, problem with texture colors  (Read 541 times)
0 Members and 1 Guest are viewing this topic.
Offline ernest210

Senior Newbie





« Posted 2013-04-08 19:28:14 »

Hello.
I wrote a code which generating heightmap and i use four textures for texturing. Almost all working fine except one blending,
one texture on the edge is white or black. I know what it means value is bigger than 1 or equal 0 but i'm almost sure (to 99 percent) i do not pass this values.
My shaders code:
1  
2  
3  
4  
5  
6  
vec3 tx  = vec3(0.0, 0.0, 0.0);
tx += texture2D(ground_grass, pass_TextureCoord).rgb * colors.r;
tx += texture2D(ground_rock, pass_TextureCoord).rgb * colors.g;
tx += texture2D(ground_snow, pass_TextureCoord).rgb * colors.b;
tx += texture2D(ground_dirt, pass_TextureCoord).rgb * colors.a;
gl_FragColor = vec4(tx, 1.0);


The problem appearing only for texture which is multiplied by "colors.a" the r, g, b always working fine. I changed textures between each other with different borders and the problem is only with "a" value.
The value of the buffer looks something like this
1  
2  
3  
0.6f, 0.0f, 0.0f, 0.0f,
0.0f, 0.6f, 0.0f, 0.0f,
...


and my binding buffer looks like
1  
2  
3  
4  
vbocId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbocId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, colorsBuffer,GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 4);


So i have four values for one vertex which set textures color. I checked array with colors and i never have situation where one sequence have only 0 value or two value (or more) with 0.6f.
So what's going on with this value "a" in vec4, do any of you had similar problem.
Whether it is possible to shaders changed in some way this "a" value?


I also did a little test I created four buffers which hold values only for one texture. Values are always kept in one position and all works fine.
1  
2  
3  
4  
5  
6  
7  
vec3 tx  = vec3(0.0, 0.0, 0.0);
tx += texture2D(ground_dirt, pass_TextureCoord).rgb * colors1.r;
tx += texture2D(ground_grass, pass_TextureCoord).rgb * colors2.r;
tx += texture2D(ground_rock, pass_TextureCoord).rgb * colors3.r;
tx += texture2D(ground_snow, pass_TextureCoord).rgb * colors4.r;
gl_FragColor = vec4(tx, 1.0);
}

Of course the whole mechanism remained unchanged so surely all is set correctly, but it is a significant loss of memory.





Offline Danny02
« Reply #1 - Posted 2013-04-08 19:33:40 »

one thing I do a lot when something is just not working in my shader. I visualize all the data I use, which helps a lot to find the problem.

you could for example do this
1  
gl_FragColor = vec4(colors.a);


and look if the .a value is what you think it should be
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #2 - Posted 2013-04-08 20:42:49 »

maybe you should use mix(a, b, float amount); ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ernest210

Senior Newbie





« Reply #3 - Posted 2013-04-08 21:19:36 »

you could for example do this
1  
gl_FragColor = vec4(colors.a);


and look if the .a value is what you think it should be

You're right.
I found a bug in my code (OMG!!!)
The bug was in the condition which checks if already beginning this fourth texture.

maybe you should use mix(a, b, float amount); ?
Yes this is a very cool feature but my solution allow to me obtain nice effects e.g texture splatting.


Thanks for help.
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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (46 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (32 views)
2014-07-23 20:56:16
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
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!