Force field around a model and pushing vertices outwards in shader.

Started by
8 comments, last by FredrikHolmstr 11 years, 8 months ago
I've been working on a pretty simple "Force Field" shader which is supposed to wrap a model inside a slightly larger version of it self which is render using some alpha transparent material. My current progress looks like this:

2012-08-06%2016-54-27.jpg

My current approach looks like this:
[source lang="cpp"]
vertex_output o;

float4 world = mul(MATRIX_MVP, v_in.vertex);
float4 normal = mul(MATRIX_MVP, v_in.normal);
o.pos = world + (normal * 1.05f);

return o;[/source]

It's pretty obvious what it does, it offsets the vertex by a fraction of it's normal it works reasonably well for objects that don't have a lot of duplicate vertices to create sharp edges, like the blue around the solider for example. But it does not work at all around the weapon due to the sharp edge/duplicate vertices.

Now, my question is pretty simple: Is there a better way of achieving this effect, and more specifically offsetting the vertices in the shader.
Advertisement
I saw a nice talk on this on the Bungie website, because Halo has a LOT of force fields. I can't remember the exact talk but it's on that page somewhere sorry!
It looks preety decent for me. You can also add more glow to it and maybe some subtle distortion (like heat haze), It will make it more lively :)
(I know it's only 'visual' opinion which you weren't after :) )
You could try to move all vertices a little bit towards the camera. Though that won't cause model to look a little bigger.
Try something like this instead:float4 world = mul(MATRIX_MVP, v_in.vertex + v_in.normal * 1.05f);
Although you way want to try a value > 1.05, it's basically what Quake 2 did back in 1998, so it should work.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


It looks preety decent for me. You can also add more glow to it and maybe some subtle distortion (like heat haze), It will make it more lively
(I know it's only 'visual' opinion which you weren't after )
Thank you! I've been thinking about putting other effects on top of this, but both glow and heat haze would require a post-processing effect if i'm not mistaken?


You could try to move all vertices a little bit towards the camera. Though that won't cause model to look a little bigger.
Hmmm, I will try this and see what I come up with.

I saw a nice talk on this on the Bungie website, because Halo has a LOT of force fields. I can't remember the exact talk but it's on that page somewhere sorry!
I can't find the text you're talking about in any of the articles, you sure it's there?


Try something like this instead:float4 world = mul(MATRIX_MVP, v_in.vertex + v_in.normal * 1.05f);
Although you way want to try a value > 1.05, it's basically what Quake 2 did back in 1998, so it should work.
I've done the vertex movement in both local and world space without any major difference in end result.

Thank you! I've been thinking about putting other effects on top of this, but both glow and heat haze would require a post-processing effect if i'm not mistaken?

Yes, as glow shouldn't be a problem but heat haze can be more complicated :)
I am not a pro, more of a begginer, I still am more 'artist' than a graphics programmer :) (hope that will change soon :D )
I think you could achieve something similar with a rim lighting pixel shader.
You just highlight the pixels that are almost perpendicular to the view direction.
Okay I found it, sorry it wasn't on the publications page hope I didn't waste your whole night!

This link contains the ppt presentation, it's a whopping 433mb so thank goodness for broadband.
An overview of the talk is discussed here as well, with the shield stuff on page 3.

Pretty nice ideas about colorizing it with tiny colour palette ramps, and fading out the effect as a function related to the depth buffer.
Thank you for that presentation! That was great. As it turns out I was on the right way (using vertex normals to push the vertices outwards). I'm working on implementing the fading part of the technique they talk about it the presentation, more specifically this is said:

To make the character more visible, we sample the depth buffer and fade the shield as a function of the distance to the shell.
So the nearby areas (likely the character) become more transparent, while the farther areas (which are probably the background) get the full effect.[/quote]

The shield here is the enlarged mesh.
The shell means the original model (I assume).

I am well familiar with sampling the depth buffer, but how would I calculate the distance to the shell from my current pixel based on the value from the depth buffer? there is no way (I can think of) to know if the depth value comes from the original model or from another player, a wall, etc. ?

This topic is closed to new replies.

Advertisement