Jump to content
  • Advertisement
Sign in to follow this  
AndyV

Textured Beam

This topic is 4822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, Is there any source code available for the Textured Beam demo in the projects section. If you don't want to release the source code, can you suggest the best way to project a texture like a spot light ? Andy

Share this post


Link to post
Share on other sites
Advertisement
I actually wondered the same thing... pay attention to the demo he says he based it off of. That demo IS available, WITH source code. I don't know how to do the (supposedly simple) updates, but it may give clues. Good luck

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi, whilst waiting for my registration to be fixed by gamedev I've been reading around & saw this. Looking briefly at both demos (without looking at the source) I have a suggestion for you:

Breaking the spinning blocks demo down, it draws the line boxes at the bottom and then draws blended polygons (likely triangles) to make up the rays. Two of the coordinates for each triangle correspond to a side of the line boxes (can't think of a better name for that), creating a wall around the boxes. The final third coordinate for each "ray" is the same for every one of them, the result being all the rays converge on the same point (at the top). The blending values remain constant for each coordinate.

As for the textured beam demo, I suspect a similar thing is being done, except you're not looking at a single quad or something for the cd texture. Instead it's probably a grid of smaller quads/triangles (probably quads), with the texture coordinates divided up.

For a single quad the tex coords would be as you'd expect:
A = glTexCoord2f(0.0, 0.0)
B = glTexCoord2f(1.0, 0.0)
C = glTexCoord2f(0.0, 1.0)
D = glTexCoord2f(1.0, 1.0)
Or however you choose to place the texture

So if there were a grid of 9x9 quads (Sounds like a weird number to choose but it means 9+1 grid points per side = easy calculations to explain ;) ), the tex coords for a single quad would be something like

A - B ....
| |
C - D ....
. .
. .
. .

A = glTexCoord2f(0.0/10.0 + 0.0, 0.0/10.0 + 0.0)
B = glTexCoord2f(1.0/10.0 + 0.1, 0.0/10.0 + 0.0)
C = glTexCoord2f(0.0/10.0 + 0.0, 1.0/10.0 + 0.1)
D = glTexCoord2f(1.0/10.0 + 0.1, 1.0/10.0 + 0.1)

where the original texture coordinates are divided up according to the grid, and offsets added where needed.

The rays are drawn from each quad in the same way as the spinning blocks (i.e. drawing a wall around the quad)
So if you're drawing a wall on side A-B, then you'd use the texcoords for A&B for the ray for the side which is touching the texture.
As for the third point that makes it look like it's coming from a light source, you'd have to play around but it'd probably use the same y texture coordinate and halfway between A & B's x coordinate. For the side B-D it's the opposite, leaving the x coord alone and going in between on the y scale.

The neat specular effects are achieved because of the blending used. Look back over the particle effect tutorial, I think the blending function used there is similar but can't remember what it was off the top of my head.

You'll notice that as the beams come closer together they fade out slightly.
Just use a low alpha value for the points nearest the "lightsource" (ps I don't think lighting is actually used in this), and higher ones for the points nearest the textured quads.
When up/down is pressed, modify the alpha values of the points near to the texture, you can probably leave the one at the top alone.

Looking back over that explanation I think it's probably not very clear but the best I can do at 1 in the morning :D If you need clarification I'm happy to try. Obviously it's more fun for you to figure the code out for yourself but I could probably post some if I'm making absolutely no sense!

Still awake?!

Cheers,
Drew

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!