Sphere-mapping just PART of a model explained

Blitz3D Forums/Blitz3D Programming/Sphere-mapping just PART of a model explained

Miracle(Posted 2003) [#1]
Someone complained several months ago that they couldn't sphere-map just the shiny bits of a model (like jewels on a stone idol etc.). Well, I stumbled across a way to do it which involves multiple surfaces in a mesh.

I've tested this in Milkshape and Unwrap3D and it seems to work fine. YMMV in other modelers.

1. Open a model or just create a sphere to test.
2. Create a new material. Call it "Shiny". Make sure this material has a bitmap in it, even if you don't intend to use this particular map on this model. You don't need to set any other attributes.
3. Select your shiny surfaces (you'll probably need to Group them, depending on your software) and apply the "Shiny" material to them.
4. Export the file as B3D. I call it "shinything.b3d" below.

Now all you need to do in Blitz3D is toss together a little routine like this:

Graphics3D 800,600,0,2
SetBuffer BackBuffer()

cam = CreateCamera()
PositionEntity cam,0,0,-80
lgt = CreateLight()
AmbientLight 64,64,64

tex = LoadTexture("shiny.png",64)
sph = LoadMesh("shinything.b3d")

brs = CreateBrush()
BrushTexture brs,tex
BrushShininess brs,0.4
BrushFX brs,1

PaintSurface GetSurface(sph,2),brs

While Not KeyHit(1)

	TurnEntity sph,0.5,0,0
	RenderWorld()
	Flip

Wend
End

If your item has multiple surfaces, you may need to sniff around a little to get the right number for the GetSurface() command. I made the brush fullbright (BrushFX brs,1) to simulate the brightness of reflected light; not doing so gives the shiny stuff an interesting oil-sheen-y feel.

You can also load other, non-sphere-mapped textures into your brush and apply them at the same time.

The downside, of course, is that you now have two surfaces to render, so using this on dozens of objects can be trouble.


jhocking(Posted 2003) [#2]
It's interesting that you "stumbled" across this technique. I've been doing this for quite some time; I do the same thing but for isolating alpha maps because alpha transparency doesn't work with the z-buffer. In other words have two surfaces, one which won't have alpha transparency and which will thus be z-buffered correctly and another surface just for transparent bits.


RetroBooster(Posted 2003) [#3]
yup, very common practice, been doing this for environment mapped reflective areas just about forever, same with alpha.