Half-Life 1 Electricity and Beams

Started by
6 comments, last by Fahrenheit451 19 years, 3 months ago
Does anybody know how Valve did the Electricy and Beams in Half-Life 1. They are very versitle and look different in a lot of cases. They also seem to be 3D. I have experimented with triangle strips so far but they look no where near as good. I am going to experiment with lines and line size changing next.
____________________________________________Graphics Edge - A CG programmer's web journalhttp://ahewgill.blogspot.com
Advertisement
I can't remember the precise details offhand, but here's what I recall.

The electricity beams were usually actually made up of many electricity beam entity type things placed in the level editor, to give the overall effect. These had parameters like amplitude, frequency, diameter, colour etc. which the mapper would set for the desired effect. As for actually rendering them I'd be fairly sure they used texture tri strips between the two end points, maybe they had two at 90 degrees to each other to give it a more 3D look.

-Mezz
Yeah, firing up Hammer and examining the properties on the env_beam entity will clue you into how it works quite a lot.

The beam itself is basically just a function that takes a parameter between 0 and 1 (start and end), and returns a position in 3D (based on an offset from the straight line between the endpoints). I'm pretty sure it renders by sampling that function at regular intervals and drawing a screen-aligned quad between each sampled point.

Of course, if you're really interested, I believe the relevant code is in the HL1 SDK. Check through the client DLL, that's where special effect rendering is handled for mods.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I've looked into using translucent lines but (in OpenGL) the maximum line width is pretty weak and the lines don't join well causing broken elbow syndrome. It must be something different as you guys suggest for the curvy lines to work and look nice.

These simple touches along with the excellent looking HUD in the game are why I enjoyed it for so long. Thanks for the help.

I think I'll look into quad strips next to replace lines.
____________________________________________Graphics Edge - A CG programmer's web journalhttp://ahewgill.blogspot.com
- Generate a bunch of disturbed points along two points (start and end). You'll have an electricity beam line.
- Now calculate the normals, relative to the screen, for each point, by averaging the normal of the two line segments connected to that point.
- Using the normals, you can generate a series of screen aligned quads. Pseudocode:
for (n = 0; n < beam.vertexCount-1; n++) {quad[0] = beam.vertex[n] - beam.normal[n]*beam.widthquad[1] = beam.vertex[n] + beam.normal[n]*beam.widthquad[2] = beam.vertex[n+1] + beam.normal[n+1]*beam.widthquad[3] = beam.vertex[n+1] - beam.normal[n+1]*beam.width}


- Now give your quads a nice texture. It should be a linear gradient with the following colors (from left to right): black->blue->white->blue->black
- Draw those quads with additive blending.
- Fade out the beam quickly, while you draw new beams (with randomly disturbed points) every few milliseconds.
The beams in HL1 did have 'elbow syndrome' as you call it - the joints were often darker because two lines (or quads or whatever) would overlap some, and the problem was worse if you made the beam more noisy. Usually, they were there and gone so fast, and far enough away, that you couldn't tell. I only really noticed when I tried to make a mod that had some persistent beams. When the beams stick around, the effect is extremely noticable especially if you're close to the beams.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
@M3d10n
thanks for the nice info,
but can you please explain
Quote:- Now calculate the normals, relative to the screen, for each point, by averaging the normal of the two line segments connected to that point.

a bit more, i don't really understand what you do
rob
Check the electric spheres demo here.

This topic is closed to new replies.

Advertisement