Paint onto a mesh? Fps questions.

Blitz3D Forums/Blitz3D Beginners Area/Paint onto a mesh? Fps questions.

Kiyoshi(Posted 2011) [#1]
Hey y'all, a quick question (or 2). First is, how would I go about painting a color onto a mesh? I'm making an FPS, and I'm using Camerapick to determine where the bullets hit. Basically:

Camerapick(camera,mousex(),mousey())
If Pickedentity()=e\mesh e\health-1


What I would like is for the section of the body that's hit to turn a reddish color, like blood seeping through the clothes (Goldeneye 64-ish). How would I find the section that's hit, and paint some red onto it; if thats even possible.

My next question is, if my previous question is possible, can the same be done with sprites? I.e. bulletholes in the wall? Note that I don't mean lining up a sprite with the picked coordinates, but rather actually painting the sprite onto the mesh that is my building.

Thanks for taking the time to read this! :D


jfk EO-11110(Posted 2011) [#2]
Depending on the UV mapping of your mesh, this might be possible. What you need is PIckedU() and PickedV(), I've seen this in the archives as well as on the Blitz3D CD in one of the samples. You will then have to paint directly to the texture. If other meshes are useing the same texture, they will bleed a well.

Painting to a texture is rather slow. Furthermore, DrawImage directly to a texture may not work on every machine. It might be better to keep a copy of the texture as an image, then draws the blood to the image, then copyrect the image to the texture.

If your NPCs are using the same texture (which is likely) then you maybe need to force them to use individual ones, eg. by using individual texture filenames. (I guess a Zipper can shrink this redundant data).

Basicly for wall decals, and often for blood as well, sprites are used (Or better: quads, due to some recent sprite problems). But I do agree, some nice "blood seeping through the clothes" fx canbe achieved when painted directly to the texture. But the UVMapping must be predestinated for this usage. For example you cannot use the same texture space for the two legs of the NPC (something that is common). Every Triangle must be UV-mapped to its own texture space, like in a (unoptimized) lightmap.

BTW. There may be a problem with Linepicking animated Meshes (B3D), as far as I know they will pick the initial pose only and not the current animation frame. Maybe that's not really important for the effect.

Last edited 2011


Kryzon(Posted 2011) [#3]
Goldeneye for the N64 used vertex-coloring - that's why you get that smooth blending of the red color.
Find out the closest vertices to the picked point and paint them progressive shades of red.

EDIT: I meant 'progressive' because if you shoot an area repeatedly, that spot will turn redder and redder.

Last edited 2011


jfk EO-11110(Posted 2011) [#4]
I've got to agree, VertexColor is a better solution. Although with a very low poly model it might be rather unrealistic, and the vertices need to be shared, it's a cheap solution that doesn't slow things down. I never played goldeneye, but I think it's looking really nice when you slowly and progressively increase the red-ness of a vertex after one bullet hit, and of course increase the speed after further bullet hits on the same vertex.

See PickedTriangle Function http://www.blitzbasic.com/b3ddocs/command.php?name=PickedTriangle&ref=goto , from that one it's gonna be easy to find the closest of 3 Vertices of the triangle. Then VertexColor it: http://www.blitzbasic.com/b3ddocs/command.php?name=VertexColor&ref=goto

You probably best hold an array for every NPC, storing the current blood factor for every vertex, so you can increment the values. But maybe you can also utilize VertexRed# ( surface,index ) instead.

Depending on the original vertex color you may need to A: in case of original color 255,255,255 decrease green and blue, B: in case of eg. 127,127,127 decrease green and blue and increase red at the same time and C: in case of 0,0,0 increase red only. Blendmode and FX need to be set right. (entityfx 2 )


Kiyoshi(Posted 2011) [#5]
Thanks a lot, guys! This really helps! :D