Cool Ice Effect
Here's a cool effect I don't know why I didn't think of this sooner. This shader uses parallax occlusion and a trick similar to that in the weeper (22a_weeper). The idea is that you can get a cheap refraction effect by multiplying the texture coordinates of the diffuse texture with the normals (naturally you'd have to establish the diffuse "outcolor" after you establish the normals). It looks something like this:
float amplitude = 0.1; vec4 outcolor = texture(texture0,ex_texcoords0 + normal.xy * amplitude);
That's pretty much the gist of it. What this does is it warps the diffuse texture coordinates by the normals. But adding the normals to the texture coordinates pushes the effect to one side so I took it a step further by subtracting the ex_normal from that and the difference creates a nice centered refraction effect against the diffuse texture.
vec2 n1 = normal.xy * amplitude; vec2 n2 = ex_normal.xy * amplitude; vec4 outcolor = texture(texture0,ex_texcoords0 + n1 - n2);
In the weeper shader I added time to the normal texcoords and that makes an effect like water dripping down a wall. Here I didn't need that because this is ice. It's stuck in place.
Once I got that established I added parallax to the diffuse texture. I used texture4 in this shader for my "outcolor" because I reserved texture0 for the little scratch marks on the surface of the ice.
vec4 refractcol = texture(texture4, parallaxed_texcoords.xy + n1 - n2);
After this I finished the color by mixing the outcolor and the refractcol by a "lighten" blend mode I found on Github.
If you look at the normals and the outcolor in the shader you'll notice I didn't use the parallaxed texcoords because I wanted the surface to remain where its at and give the impression that there is something sort of encasing the "ice" i.e., the surface of the object - what the light bounces off of. The whole "ice" effect happens under some surface, right?
I also z-sorted the object, which gets rid of the shaded sides (like ice doesn't really have a shadowed side does it?) and because of that I lost the specular so I added a blinn-phong to replace it. Also I added a cubemap to simulate reflection.
I think this would work great as a frozen lake or an iceberg. Maybe even as ice cubes. It doesn't take the screen into consideration like the creek refraction does so you still technically have an opaque object. It's also parallax which notoriously has trouble with curves. I've added a few tricks so that the parallax can work on gentle slopes. You can adjust the texture sizes, the light, the cubemap fresnel, the parallax depth, the refraction amount, and the ice "contrast." If you put it on your own model you'll have to adjust the texture sizes and stuff but it's set up to work on a Leadwerks box brush so you can just slap it on one of those to quickly see it in action. The picture doesn't do it justice you have to move it around to see the effect. Anyway it's something fun.
- 8
9 Comments
Recommended Comments