Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (595)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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 735 times)
0 Members and 1 Guest are viewing this topic.
Offline ernest210

Senior Newbie

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

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:
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
0.6f, 0.0f, 0.0f, 0.0f,
0.0f, 0.6f, 0.0f, 0.0f,

and my binding buffer looks like
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.
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 17: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
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 18: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 19:19:36 »

you could for example do this
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.

Riven (22 views)
2015-07-03 11:22:16

deepthought (47 views)
2015-06-30 15:39:44

deepthought (49 views)
2015-06-30 15:39:09

deepthought (62 views)
2015-06-30 15:36:52

Za\'Anzabar (34 views)
2015-06-29 05:44:54

TritonDreyja (46 views)
2015-06-24 17:10:40

CopyableCougar4 (46 views)
2015-06-23 00:34:45

BurntPizza (51 views)
2015-06-21 20:36:46

cookiecompiler (93 views)
2015-06-11 15:42:53

cookiecompiler (55 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

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 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!