@Livelyivy @MattThorson I never asked for these powers (Today)

RT @MattThorson: How did kpulv get so gud at the falling tower game? You… — When Kyle won his 3rd world championship in a row, I ra… https:… (Today)

@castpixel @floatvoid maybe some of the freely available talks from GDC this year? t.co/jTvHbLCLip :O feel better soon! (Today)

@infinite_ammo @TommyRefenes maaaaybeeee is there a way to play prepatched left 4 dead 1? ;p (Yesterday)

@ZackBellGames wait for canada to invade and we become south canada thats probably the easiest way (Yesterday)

@gmvsv Invincibility also comes to mind, that feels more like getting a star in Mario though vs post getting hit. Mercy frames is new to me! (Yesterday)

@gmvsv damage/hit stun, invulnerability frames, or iframes usually is what I hear and use (Yesterday)

RT @MattThorson: Oh hey TowerFall's in a Humble Bundle with some very good games ⭐️ you might like it t.co/MnLnYTuDrb (Yesterday)

@thenicklask oh hey I'm really bad at twitter DMs usually so I recommend just shooting me an email at hi@kpulv.com (2 days ago)

@kinifi Offspring Fling ain't exactly a huge hit or anything. I never had any issues serving out the levels on shared hosting. (2 days ago)

@kinifi They're just XML I believe. You should be able to open one with a text editor. Online they're just in a database. (2 days ago)

@NoelFB twitter wants you to start personally telling people that you enjoyed their tweet (2 days ago)

@endshark YEAH I would post a gif but every time I try it's way too huge for twitter :I (2 days ago)

@MANvsGAME I ended up using that GWX control panel thing and since then I haven't heard a peep about windows 10 YEAH!! (2 days ago)

working on some completely reasonable attack patterns for this sky sisters boss fight t.co/OiEEfbxyie (2 days ago)

@kirlosev OHHH Yeah Aleksey's game I am super excited about this (2 days ago)

@konjak @Jonochrome 3 buttons is tough on a keyboard but I much prefer jump buttons over hitting up on the arrows. (2 days ago)

@ADAMATOMIC if it was an ancient cursed foam sword that demanded the blood of his enemies then it probably wasnt his fault (3 days ago)

@TylerGlaiel "has anyone ever experienced this obscure openGL problem?" "what no you're doing it wrong here's how to render a triangle" (4 days ago)

@ChevyRay wow dang that could be you except the crows become a giant wearable murder mech suit (5 days ago)

follow
search

2014 - 6 - 11 / 4:06 pm / general

Dev Log: Shader Follow Up

Dev Log: Shader Follow Up

My last post went over some of my recent shader developments with displacement maps, and using gradient maps to recolor portions of the screen. I had a couple of questions of what exactly was going on behind the scenes with the render textures that I was using to tell the shader how to actually manipulate the image, so I thought I would address that now!

Here's an example image from the game with a lot of explosions going on:

Image

Each explosion has a shockwave ripple coming out of it which distorts the area around it. The explosion also changes the color of the screen around to a gradient map with pink and yellow. This makes it look like an intense heat, or something.

For reference, here's the shader again (it's been slightly modified since yesterday.)

uniform sampler2D texture;
uniform sampler2D displacementMap;
uniform sampler2D paletteMap;
uniform sampler2D gradientMap;

void main() {
// Get the pixels off of the maps.
vec4 displacementPixel = texture2D(displacementMap, gl_TexCoord[0]);
vec4 palettePixel = texture2D(paletteMap, gl_TexCoord[0]);

// Read the pixel from the displaced position.
vec2 pos = gl_TexCoord[0];
pos.x += (displacementPixel.r * 2.0 - 1.0) * 0.025;
pos.y -= (displacementPixel.g * 2.0 - 1.0) * 0.025;

// Get the displaced pixel.
vec4 pixel = texture2D(texture, pos);

// Proper grayscale conversion.
float gray = dot(pixel.rgb, vec3(0.299, 0.587, 0.114));

// Get the color from the gradient.
float gradientPos = mod(gray + palettePixel.g, 1);

// Get the actual color from the gradient.
vec4 gradientMapPixel = texture2D(gradientMap, new vec2(gradientPos, palettePixel.r));

// Mix the gradient with the pixel color based on the palette pixel.
pixel = mix(pixel, gradientMapPixel, palettePixel.a);

// Apply the final color multiplied by the gl color.
gl_FragColor = pixel * gl_Color;
}

From this point on there's going to be a lot of images and some hefty animated gifs, so I'll hide the rest of this post behind the read more button!

Now here's what the displacement map actually looks like:

Image

And here's the image that I'm using to get the shockwave displacement:

Image

The displacement map is filled with gray (127, 127, 127) each frame, and then that shockwave image is rendered to it, much like how each frame for the game window is cleared and then rendered to with many different graphics. After the displacement map has been rendered to, I pass its texture to the shader to use for the displacement.

The gradient mapping is a little simpler. The explosions just render a blue glow to the surface that determines how to remap the colors. Here's how that looks behind the scenes:

Image

And now when it all comes together!

Image

And of course here's a quick look at the shock wave animating:

Image

5 Comments
Avatar

2014 - 6 - 12 4:57 AM

Abel Toy

Woah.

I'm amazed at what you can do with shaders, really. That effect is so powerful, and with a really small ammount of code.

I can't wait to experiment with shaders as well, cause that looks fantastic.

Thanks for sharing this insightful post, great job! Can't wait to play with your game :)

Avatar

2014 - 6 - 22 6:50 AM

Maria

This looks really rad makes my tummy go crazy :')

Avatar

2014 - 6 - 22 12:38 PM

Kyle

Thanks! :)

Avatar

2014 - 9 - 10 1:46 PM

Cranky

That's really amazing.
I wanted to play around with that shader a little bit, so I ported it over to HLSL. I found that the line where you mod the u pos to get the gradientPos was creating artifacts, because it causes the u value to jump to 0 when reaching 1 (which results in jumping from an onscreen white to black on the gradient map). When I removed the line the effect was working a lot better.

Is it cool if I steal the idea with the gradient map for my own projects? :D

Avatar

2014 - 9 - 11 2:54 PM

Kyle

Oh weird about the mod issue! Maybe that is a difference with how mod works on HLSL? I don't think I've noticed this on my experiements so far.

Feel free to "steal" the technique! I posted it so that hopefully people would use it on their own stuff ;)

Avatar

Post your comment!

POST COMMENT

about

About

Hi! My name's Kyle, and I make video games most of the time in Denver, Colorado. Here you will find my thoughts, games, websites, doodles, and other stuff like that. I worked on Snapshot, Offspring Fling, and a whole bunch of other games. I also created and maintain Otter, a 2d game making framework. If you want to get a hold of me use the form on the bottom of the page, leave a comment, or just tweet at me. I try to post three times a week. Thanks for stoppin' by! You're the coolest.

blog stuff

categories

tags

archives

facebook

videos

Do you want to make a Let's Play of one of my games, or a just a video featuring footage of my games? You have my full permission to do so! Even if you are monetizing your videos, you still have my full permission to use any footage from any of my games. Go for it!

contact

Your message has been sent! Thanks :)
SEND MESSAGE