Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (223)
games submitted by our members
Games in WIP (813)
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  
  LibGDX Radial fading shader effect within a moving area  (Read 1147 times)
0 Members and 1 Guest are viewing this topic.
Offline devinjv

Junior Newbie


Exp: 4-6 months



« Posted 2014-05-07 00:51:42 »

I'm relatively new to graphics and the magic that happens behind the scenes so I'm probably jumping ahead of myself here.

With that said I am trying to achieve the shader effect shown in this picture, where the grey broken line fades from visible (closer to player) to invisible (further from player).

While the broken line fades, the background items are always visible

I followed mattdesl's guide and was able to create a flashlight type vignette effect which is close, but I didn't have much luck because the only way I know to call the shader effects my whole sprite batch.

1  
2  
3  
4  
5  
ShaderProgram.pedantic = false;
shader = new ShaderProgram(Gdx.files.internal("data/vignette.vsh"), Gdx.files.internal("data/vignette.fsh"));
if(!shader.isCompiled())
         System.out.println(shader.getLog());
      batcher.setShader(shader);


My main question would be what type of sprite batch and shader calls in LibGDX. player circle's radius fade in / out of view. I know this can be achieved with a vignette type effect but my situation is a little more specific. I want the rest of the screen fully visible at all times and only a select layer of textures to be effected.

As I inch my way closer, your tips will help a lot!
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #1 - Posted 2014-05-07 00:55:42 »

Draw the background with normal shading, and do the grey line stuff in a separate pass with shaders on.

Simply make alpha a function of y position with an inverse relationship, so that pixels closer to 0 in Y (near bottom of screen) are low-alpha, and far away ones are opaque.


EDIT: made a quick example on shadertoy:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
void main(void)
{
   vec2 uv = gl_FragCoord.xy / iResolution.xy;
   
   vec4 c = vec4(uv.x, uv.x, uv.y, 1.0);  // consider this the background image
   
   // draw grey boxes, multiplying by Y coord to provide alpha effect
   if(mod(uv.x, 0.1) < 0.02 && mod(uv.y, 0.1) < .05) {
      c += 0.3 * uv.y * uv.y; // squaring for more intense effect
   }
   
   gl_FragColor = vec4(c);
}
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

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

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

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

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

Archive (629 views)
2017-04-27 17:45:51

buddyBro (737 views)
2017-04-05 03:38:00

CopyableCougar4 (1266 views)
2017-03-24 15:39:42

theagentd (1246 views)
2017-03-24 15:32:08

Rule (1221 views)
2017-03-19 12:43:22

Rule (1274 views)
2017-03-19 12:42:17
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!