Outlined 3D object - how to do it ?

Blitz3D Forums/Blitz3D Programming/Outlined 3D object - how to do it ?

semar(Posted 2009) [#1]
All,
how to make a 3D object outlined ?

From what I've tryed, a way would be to modify the texture and add the desired outline to it, before applying it to the 3D model.

But that's means to have to edit all the models textures.

Is there any other way to accomplish this ?

Regards,
Sergio.


Yasha(Posted 2009) [#2]
You mean a black line around the outside of an object, as though it were outlined with a pen on paper?


semar(Posted 2009) [#3]
No, an outline of any other color; like the players in this video:
http://www.youtube.com/watch?v=VVIdHPG0wYI
the players and the pickable objects are outlined in blue.


Yasha(Posted 2009) [#4]
Hmmm...

I think there's no way to do something like that without at least three render passes; more if you haven't got FastExtension or some other library that'd let you do blurring in hardware. But one possible way:

1) Colour your objects/players the shade of the outline. Render these objects, and not the rest of the world, and do so without textures.

2) Apply a fairly heavy blur filter to the result. Disable colour clearing and render the objects again, but this time coloured black (so they chop holes out of the blurs).

3) Store the result somehow.

4) Render the scene as normal, with the previous render overlaid by some means.

There's more than one valid way of going about these steps, hence the "somehow". There's probably also a much better way of doing this altogether, but this is what comes to mind immediately. I'm not sure how you could do this if you don't have a DLL to let you use postprocess effects.


EDIT: Here's an example (dump it in the FastExt examples folder):



RifRaf(Posted 2009) [#5]
perhaps you could do somthing like this ro remove multiple renders and the need for fastlibs.

1.remove texture / color outline color / blend multiply x2 / entityorder to draw last
2.copy the entity color it black. move it away from the camera a few units. normal blend, entityorder to draw last
3. renderworld
4.hide/remove black copy , reset entities normal texture,entityorder, and blendmode


Rroff(Posted 2009) [#6]
It might not be perfect but...

Make a copy of the model entity, scale it up slightly, use flipmesh to flip the normals, and use entityfx and colors, etc. to make the copy a colored outline.


RifRaf(Posted 2009) [#7]
you dont have to flip it, since orders will have to be changed on the fly anyway just put the dark one in front of the main mesh and order it last.or scale it up and keep it in the same place.. (but i would think that movement would be less costly than scaling every frame on several entities but i could be wrong there)


Nate the Great(Posted 2009) [#8]
what if you do a normal render of your scene then hide everything but the objects you want the glow for... then you color them black, copy them flip the copies and scale/color blue/alpha them appropriatelythen render that with a different camera mode set to not overwrite the previous render...


Nate the Great(Posted 2009) [#9]
what if you do a normal render of your scene then hide everything but the objects you want the glow for... then you color them black, copy them flip the copies and scale/color blue/alpha them appropriatelythen render that with a different camera mode set to not overwrite the previous render...


semar(Posted 2009) [#10]
Thanks all, your suggestions were very inspiring; EntityOrder does the trick, even with animated meshes:

Graphics3D 1024,768
cam = CreateCamera()

Global zombie = LoadAnimMesh("C:\Projects\BLITZ\models\zombie\zombie.b3d")

ShowEntity zombie
ScaleEntity zombie,.5,.5,.5

Global pivot = CreatePivot()
EntityParent zombie,pivot
PositionEntity pivot,0,-3,12


zo = CopyEntity(zombie,pivot)
ScaleEntity zo,.54,.5,.54

EntityColor zo,0,0,255
EntityOrder zombie,-1
EntityParent zo,pivot

tex = CreateTexture(2,2)
EntityTexture zombie,tex

sp# = .5
Animate zombie,1,sp
Animate zo,1,sp

light = CreateLight()
TurnEntity light,0,45,0

While Not KeyDown(1)


TurnEntity pivot,0,.5,0

UpdateWorld
RenderWorld
Flip

Wend
End


It works ! try also to comment the entitytexture thing.
The black inner model will cover any background though. Perhaps I should investigate about the command CaptureWorld.

Regards,
Sergio.


D4NM4N(Posted 2009) [#11]
What you could do is:
- copy the object 3 times.
- color one total black, one light blue with 50%alpha and one darker blue with 25%alpha, use fullbright entityFX on all (may need a recursive set if mesh has children).
- scale/zposition the blue ones so they appear slightly larger respectively and
- then Zorder the lot so all appear in front of everything but the black one in the front of the other two.

I reckon that will be very close to what you want. With some adaption you could even make it trail slightly :)


Bobysait(Posted 2009) [#12]
As the entity will be animated, you 'll have to animate the outline too.

An other way ( for non animated - simple objects ) could be to calculate the outline :
1/ find edge of the outline
+> for each edges find if one vertex is z+ or z- from the camera and the other is z- or z+ ( or two are "0" or almost )
2/ push the edges
+> using the camera projection, you can find the normal of the edge that is the cross vector from egde and camera vector
+> build a second edge that will be the projection of the edge found along the vector with the size you setted up.
3/ build a single surface with all outline and texture it with a simple alpha texture


D4NM4N(Posted 2009) [#13]
Not if you use my method above because the copies will animate. Plus, if you did want static trailing effects you could keep the black one and one blue transparent one animated and freeze the fading blue trail copies at their current frame when drawn. I reckon that would look wicked.


Mike0101(Posted 2009) [#14]
Yasha sample is the perfect solution. With some tweek (entity visible or something) this gives the left4dead effect. You need the fastext library.


semar(Posted 2009) [#15]
@Yasha,
hey what a cool piece of code - thank you !

I've tried it just now, and resembles exactly what I had in my mind.

It seems that this FastExtension library is quite good indeed. A nice add-on to the Blitz3D arsenal.

Cheers,
Sergio.


neoshaman(Posted 2009) [#16]
i would the simpler one of having:
1) copy model
2) flip mesh and set it to additive blend
3) aply an en environment texture with black outline and whatever color gradient toward the center

No Z ordering to do
No library nor dll

and plus entity order work on an empty scene but not featured one (the draw would be behind the z sorted geometry or in front)


Ross C(Posted 2009) [#17]
The enviroment map fails on very "sharp" edges though. Saying that, you'll never get the perfect solution in blitz, as scaling an entity doesn't each vertex along it's normal, but rather scales from the middle, which isn't ideal.


ZJP(Posted 2009) [#18]
@Yasha,Thx.

JP