Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Shader not rendering correctly  (Read 4529 times)
0 Members and 1 Guest are viewing this topic.
Offline ags1

JGO Kernel


Medals: 356
Projects: 7


Make code not war!


« Posted 2014-07-17 05:55:51 »

This is driving me mad... I have a fragment shader that generates up to 4 ripples on the screen, but it doesn't render correctly. The ripples go about halfway, then flash to the edge of the screen.

I used to have all the code (repeated 4 times) in main(). In that version, only one of my waves would render incorrectly. After moving the code to a function they all do. Also, performance is much worse with the function...

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  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
precision mediump float;

uniform vec4 u_Wave0;
uniform vec4 u_Wave1;
uniform vec4 u_Wave2;
uniform vec4 u_Wave3;

varying vec3 v_Position;
varying vec4 v_Color;

vec4 getColor(in vec4 wave, in vec3 coord, in vec4 vcolor) {
   vec4 newColor = vec4(0.1, 0.2, 0.4, 1.0);
   vec4 white = vec4(1, 1, 1, 1);
   float distance = distance(coord.xy, wave.xy);
   float wave1 = abs(distance - wave.z);
   wave1 = clamp(wave1, 0.0, 25.0);  
   wave1 = (25.0 - wave1) / 35.0;
   vec4 color = mix(vcolor, white, newColor.rrra);
   color = mix(vcolor, color, wave1);
   return color;
}

void main()                          
{
   vec3 coord = gl_FragCoord.xyz;
   
   vec4 color = getColor(u_Wave0, coord, v_Color);
   vec4 color1 = getColor(u_Wave1, coord, v_Color);
   vec4 color2 = getColor(u_Wave2, coord, v_Color);
   vec4 color3 = getColor(u_Wave3, coord, v_Color);
   
   color3 = max(color3, color);
   color3 = max(color3, color1);
   color3 = max(color3, color2);
   
   gl_FragColor = color3;                                  
}                                                                        

Offline trollwarrior1
« Reply #1 - Posted 2014-07-17 06:20:37 »

I would guess that you need to interpolate them, instead of maxing them. (a+b) / 2 should do the trick I think Cheesy
Offline ags1

JGO Kernel


Medals: 356
Projects: 7


Make code not war!


« Reply #2 - Posted 2014-07-17 06:47:36 »

I changed to max() only to see if that had an effect, before that I was doing another mix(). There is no difference between the two versions, they both show the flash to edge bug.

EDIT: It is definitely a bug in my Asus Memo Pad HD GPU. simply duplicating the function changes the behavior (the copied function behaves correctly)... In this I cut it down to two ripples, with a duplicate function only one has the flash bug.

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  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
precision mediump float;

uniform vec4 u_Wave0;
uniform vec4 u_Wave1;
uniform vec4 u_Wave2;
uniform vec4 u_Wave3;

varying vec3 v_Position;
varying vec4 v_Color;

vec4 getColor(in vec4 wave, in vec3 coord, in vec4 vcolor) {
   vec4 newColor = vec4(0.1, 0.2, 0.4, 1.0);
   vec4 white = vec4(1, 1, 1, 1);
   float distance = distance(coord.xy, wave.xy);
   float wave1 = abs(distance - wave.z);
   wave1 = clamp(wave1, 0.0, 25.0);  
   wave1 = (25.0 - wave1) / 35.0;
   vec4 color = mix(vcolor, white, newColor.rrra);
   color = mix(vcolor, color, wave1);
   return color;
}

vec4 getColorD(in vec4 wave, in vec3 coord, in vec4 vcolor) {
   vec4 newColor = vec4(0.1, 0.2, 0.4, 1.0);
   vec4 white = vec4(1, 1, 1, 1);
   float distance = distance(coord.xy, wave.xy);
   float wave1 = abs(distance - wave.z);
   wave1 = clamp(wave1, 0.0, 25.0);  
   wave1 = (25.0 - wave1) / 35.0;
   vec4 color = mix(vcolor, white, newColor.bbba);
   color = mix(vcolor, color, wave1);
   return color;
}

void main()                          
{
   vec3 coord = gl_FragCoord.xyz;
   
   vec4 color = getColor(u_Wave0, coord, v_Color);
   vec4 color1 = getColor(u_Wave1, coord, v_Color);
   //vec4 color2 = getColor(u_Wave2, coord, v_Color);
   //vec4 color3 = getColor(u_Wave3, coord, v_Color);
   
   vec4 color3 = max(color, color1);
   //color3 = max(color3, color1);
   //color3 = max(color3, color2);
   
   gl_FragColor = color3;                                  
}                              

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #3 - Posted 2014-07-18 01:19:29 »

Are you sure it's a bug? The duplicate function is not the same

vec4 color = mix(vcolor, white, newColor.bbba);

vs

vec4 color = mix(vcolor, white, newColor.rrra);

I don't think that caused your problem though. Could you post a pic?

Every village needs an idiot Cool
Offline ags1

JGO Kernel


Medals: 356
Projects: 7


Make code not war!


« Reply #4 - Posted 2014-07-18 10:17:53 »

I introduced that small difference to ensure the compiler didn't optimize out the duplicate. Since then I optimised the function like this:


vec4 float getColorWave(in vec4 wave, in vec3 coord, in vec4 vcolor) {
   vec4 newColor = vec4(0.1, 0.2, 0.4, 1.0);
   vec4 white = vec4(1, 1, 1, 1);

   float distance = distance(coord.xy, wave.xy);
   float wave1 = abs(distance - wave.z);
   wave1 = return clamp(wave1, 0.0, 25.0);  
   wave1 = (25.0 - wave1) / 35.0;
   vec4 color = mix(vcolor, white, newColor.rrra);
   color = mix(vcolor, color, wave1);
   return color;

}


So all the color processing is only done once in main()... which gets me 5fps more on my tablet, but which also means the two functions really are identical now.

I have it working now - I call the duplicate function, discard its results then call the real function and it all works ok.

Offline thedanisaur

JGO Knight


Medals: 59



« Reply #5 - Posted 2014-07-18 16:47:47 »

Hmmmm, that's a bummer Undecided. Well cool that you got it working!

Every village needs an idiot Cool
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (21 views)
2017-11-21 16:21:00

xxMrPHDxx (14 views)
2017-11-21 16:14:31

xxMrPHDxx (16 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (150 views)
2017-09-26 18:23:31

cybrmynd (260 views)
2017-08-02 12:28:51

cybrmynd (250 views)
2017-08-02 12:19:43

cybrmynd (247 views)
2017-08-02 12:18:09

Sralse (260 views)
2017-07-25 17:13:48

Archive (880 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!