Fake Edge Shader

Blitz3D Forums/Blitz3D Programming/Fake Edge Shader

Big&(Posted 2004) [#1]
I was trying to think of a way to do a edge shader like you see in many PC demos.
Its basically an effect that makes models look like they are been viewed with an electron microscope. Well, that's how I would describe it anyway.

After messing around for ages with variations on toon shading from the archive, I had a go with negative light...

And it worked.



Bigger version here!

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

bug=LoadMesh("bug.b3d")

cam=CreateCamera()
lig=CreateLight(1,cam)

MoveEntity(cam,0,0,-150)
CameraZoom(cam,2)

;The bit that does the effect
LightColor(lig,-255,-255,-255)
AmbientLight(128,255,64)

Repeat
	TurnEntity(bug,0,0.5,0)

	UpdateWorld()
	RenderWorld()

	Flip()

Until KeyDown(1)
End

Could it be any simpler...
(Not earth-shattering I admit but a nice effect.)


jhocking(Posted 2004) [#2]
That's an interesting effect and useful to know. I've been doing a similar effect Mustang explained using a texture of a blurry black dot on a colored background, spherical environment mapping, and add blend mode. The difference between that effect and yours is opacity; in yours objects occlude each other like an electron microscope, whereas his effect is more like see-through shimmery energy.


CyberHeater(Posted 2004) [#3]
Another one to add to the archive I think. Great effect.


Techlord(Posted 2004) [#4]
I can see the effect being used with a red filter for an Infrared effect. With additional colors I can see a 'Thermal' effect. Good Work!


Pinete(Posted 2004) [#5]
Fantastic!
completely original!
Great job!


sswift(Posted 2004) [#6]
That's a neat effect... Are you using my toon shading stuff? I forget if I put it in the code archives or not. I did that sort of effect myself in my Tank Game. I think it's a pretty well known trick one can do with spherical environment maps. In my Tank Game, I used the effect on an add blended object to make a hemispherical energy sheild, like one might see on Star Trek.


It doesn't really look like an infrared effect though. It looks more like an X-Ray. Infrared looks more like a bright red person with orange spots around their eyes and such and blue coloration on cold stuff in the room around them. It doesn't make the edges light up like that. Of course I'm talking about a full color infrared view. It would look better to have a red color as you said and just use a black and white image. Or maybe some kind of hybrid. I wonder what mixing an infrared view with a color view might look like.


jhocking(Posted 2004) [#7]
If you glance at his code the effect is mostly due to setting a negative light color. Does this effect work on various video cards? This seems like exploiting a bug in the DX implementation on your video card.


Skitchy(Posted 2004) [#8]
That is REALLY nice - and so simple too! Lateral thinking in action :)


fredborg(Posted 2004) [#9]
Almost the same with sphere mapping instead, so you haven't got the negative light affecting other stuff:
Graphics3D(800,600,0,2)
SetBuffer(BackBuffer())

bug2 = CreateCylinder(32)
tex = CreateTexture(256,256,1+64)
MakeGradMap(tex)
EntityTexture bug2,tex
EntityFX bug2,1
PositionEntity bug2,2,0,0

cam=CreateCamera()
lig=CreateLight(1,cam)

MoveEntity(cam,0,0,-10)
CameraZoom(cam,2)

Repeat
	TurnEntity(bug2,0.5,0.5,0)
	
	UpdateWorld()
	RenderWorld()

	Flip()

Until KeyDown(1)
End

Function MakeGradMap(tex,a#=0.3,b#=0.8)

	If a<0 		Then a = 0
	If a>0.99	Then a = 0.99

	If b=0.0	Then b = 1.0

	cx = TextureWidth(tex)/2
	cy = TextureHeight(tex)/2

	div# = Sqr(cx*cx + cy*cy)

	For x = 0 To TextureWidth(tex)-1
		For y = 0 To TextureHeight(tex)-1
			g# = Sqr(Float(x-cx)*Float(x-cx) + Float(y-cy)*Float(y-cy))/div
			g = (g-a)/(1.0-a)
			g = g^b
			red = (g*255)-128
			grn = (g*255)
			blu = (g*255)-192
			If red<0 Then red=0
			If grn<0 Then grn=0
			If blu<0 Then blu=0
			If red>255 Then red=255
			If grn>255 Then grn=255
			If blu>255 Then blu=255
			WritePixel x,y,blu + grn*256 + red*65536,TextureBuffer(tex)
		Next
	Next

End Function



N(Posted 2004) [#10]
Neeeeeeaaaat......


slenkar(Posted 2004) [#11]
Hey SSwift. have you got a demo of the spherical shield? it sounds good


sswift(Posted 2004) [#12]
Slenkar:
I don't have a demo of my game with enabled right now, but it's pretty simple to make.

1. Make a sphere.
2. Make a texture that is black in the center and some saturated color at the edges.
3. Load said texture and set it to a spherical environment map.
4. Apply to sphere.
5. Set sphere to add blend.
6. Place in level. Voila, force shield.


It'll pretty much look like the eye of that bug up there. You can control how thick the edges are by adjusting the gradient.


sswift(Posted 2004) [#13]
"If you glance at his code the effect is mostly due to setting a negative light color. Does this effect work on various video cards? This seems like exploiting a bug in the DX implementation on your video card."

You're right. :-) I simply assumed he used the spherical environment map method cause he said he was messing aorund with toon shading.

Will it work on other cards? I'm pretty sure it does. You can probably also get the same effect by simply inverting your objet's normals.

What he's doing here wouldn't allow you to apply the effect on a per object basis like spherical mapping would. Then again, do you need to?

Mis method might work nicely on levels too, whereas spherical mapping may not work well with flat surfaces... Or maybe it works better than this with flat surfaces, I'm not sure.


Mustang(Posted 2004) [#14]
My "bug" with spherical map looked like this:



Whole thread about it (including the actual sphere map) is here:

http://www.blitzbasic.com/Community/posts.php?topic=24135


Picklesworth(Posted 2004) [#15]
wow those are nice effects!
It's amazing how much you can do with such little code.


Big&(Posted 2004) [#16]
Thanks guys.

I dont think its an exploit its just the maths of the light, if you know what I mean. I imagine all DX is doing is adding the light value and with it been negative, it just takes light away.

It also holds true if you give your objects a negative color, they get brighter again.

Some more experiments:

The effect only seems to work well with smooth objects but then Mustangs "bug" would come in useful.


sswift(Posted 2004) [#17]
Those last two images look real cool.


Mustang(Posted 2004) [#18]
When I still used DarkBasic (sorry 'bout that but I didn't know that Blitz3D existed! :)) I used negative light in my chess-like board game I was doing then (Archon rip-off)... My "evil wizard" had one negative light attached to him/her/it and it looked pretty cool when he/she/it moved across the board and "sucked" light out of the Neighborhood... looked VERY evil indeed! >:)


Doiron(Posted 2004) [#19]
It doesn't really look like an infrared effect though. It looks more like an X-Ray. Infrared looks more like a bright red person with orange spots around their eyes and such and blue coloration on cold stuff in the room around them. It doesn't make the edges light up like that. Of course I'm talking about a full color infrared view. It would look better to have a red color as you said and just use a black and white image. Or maybe some kind of hybrid. I wonder what mixing an infrared view with a color view might look like.

What you are talking about is a heat-seeker display. An infrared display only translates the invisible spectrum (infrared frequencies, that is) to the one visible to the human eye, usually resulting in green monochrome shades. Of course if used in a bright ambient the screen goes blind, since it also adds the visible spectrum to the final result. A good representation is the effect achieved when using the Marine in Alien vs Predator (after enabling the infrared display of course).


Ross C(Posted 2004) [#20]
Very nice!


Big&(Posted 2004) [#21]
If you are interested, there is an EXE for the above black and white images here. (~700k) It just cycles through the four effects.

It's not optimised or anything so may run dog slow if you have an older machine/gfx card. It was done just to check some ideas.

The bloom effect was taken from the thread where it was discussed (the one that uses sswift's blur).


Rob(Posted 2004) [#22]
Very mysterious noir demo. I really liked it!


simonh(Posted 2004) [#23]
Very nice demo.

Can you submit that picture to the gallery Big&?


aCiD2(Posted 2004) [#24]
big& any chance of source? thats incredible....


jhocking(Posted 2004) [#25]
Holy hell, that demo looks nice. How do you do the film grain effect?


Picklesworth(Posted 2004) [#26]
that looks great! It made me finally give in to my friends nagging at me to do half the programming for a game they are designing... They would like to pass on their thanks.

That first demo is pretty cool in the way that the fog seems to be constantly changing, and then the second to last one is just great!
The film grain effect is also very nice by the way. I would love to know how that is done.


sswift(Posted 2004) [#27]
Is it supposed to be so bright? The second effect is almost pure white most of the time with the occasional darker thing that can be seen rotating. It doesn't look like the screenshot above. And the second and third effects are also quite a bit brighter than they appear in the above screenshots.

In addition, the camera in the first effect seems choppy when it rotates. It's perfectly smooth most of the time but it suddenly gets real choppy when rotating at certain angles, and it doesn't seem like the result of a low framerate, but rather because the camera itself is rotating in steps instead of smoothly. The other stuff still moves smoothly in other words.


Big&(Posted 2004) [#28]
The source for the "spikey ball" bit is here.

No commets I am afraid. *shame on me*

The film grain is done with a simple noise texture with its uv's been set randomly each frame, on an alpha'd cube just in front of the camera.

Not sure why you are getting it so bright sswift. The demo appears the same on my comp as it does in the screenshots.
The choppy-nes of the camera is probably due to the frame limiting code. Its in the above zip. Its just a basic setup I got off here ages ago. The demo doesnt usualy drop below 100fps on my setup, so it could be something to do with that.


Rob(Posted 2004) [#29]
sswift you seem jealous man.


Bug Face(Posted 2004) [#30]
Truely amazing demo, out of this world on a number of levels!


jhocking(Posted 2004) [#31]
Brightness is fine for me too, but I've noticed that brightness is off on a lot of machines if you leave the default gamma settings. Usually adding these two lines immediately after Graphics3D solves the problem:

SetGamma 255,255,255,255,255,255
UpdateGamma


DJWoodgate(Posted 2004) [#32]
Using Millisecs with Sin and Cos may be to blame for some jumpiness. Millisecs can get very large and Sin and Cos start returning very iffy results when used with very large numbers due to lack of floating point precision. The result of this is that the value returned does not change at all over the course of many Milliseconds and then jumps suddenly. Not sure if thats to blame here, not too much maybe as you are dividing millisecs() down somewhat, but it is going to depend on machine uptime.


sswift(Posted 2004) [#33]
"sswift you seem jealous man."

I already said it looked cool. I was just trying to be helpful pointing out the bugs. Obviously he wants it to run the same on every system.

In fact, I'm interested to know why it DOESN'T run the same on my system. The big feature of Blitz is that your game should run and look the same on every system... and until now that has held true, so why does this demo behave differently?

Very strange.


"but it is going to depend on machine uptime."

Interesting... So he's just using raw millisecs to update his sin and cos? (I always use the difference in time between two frames to calculate the number of degrees to move something.)

And my system HAS, very surprisingly, not crashed for a day or two.

PERHAPS that also explains why his bright effect is too bright.

I'm not gonna reboot right now to find out though. My system rarely stays stable this long, and I don't want to muck it up. I'll run it again when my system crashes again. :-)


Neochrome(Posted 2004) [#34]
Oh WOW! Im sure that demo of yours will give you an idea of a game thats been out before.. Microcosm for the CD32 along while back, i saw this and im SURE Microcosm would be able to make an EXTREME come back with the stuff that blitz can doo!!!

Big& i must ask tho, Can i borrow your idea??


Big&(Posted 2004) [#35]
@Necromancer
Yeah, sure man, thats why I stuck it up on here.. :)


Ross C(Posted 2004) [#36]
Tis very impressive. Thanks man, you've brought my attention to negative lights, which can be used to generate normal maps in blitz!

Good work ;)


Neochrome(Posted 2004) [#37]
its real cool, that Bio example was the best!
iv played about with it and i think iv mannaged to come out with some wierd effects!

Again, thanks.


Bouncer(Posted 2004) [#38]
Looks really nice... ecspecially the spiky ball part.

Ross C: what do you mean generate normal maps with negative light?


Neochrome(Posted 2004) [#39]
"but it is going to depend on machine uptime."


i found that too, sorted it by making my models load in to a Int model% solves the problem right up


jfk EO-11110(Posted 2004) [#40]
Very nice stuff. I never realized that negative lights are possible so easily! Now it seems one could do a painkiller negative view mode without any DX9 shaders


sswift(Posted 2004) [#41]
I rebooted my machune but the problem didn't go away. I wonder if one has to actually shut the machine OFF to reset the milliseconds timer?


Neochrome(Posted 2004) [#42]
what happening sswift?


sswift(Posted 2004) [#43]
Scroll a quarter of the way up the page and read my post about it being too bright.


fredborg(Posted 2004) [#44]
Nice stuff. Finally a demo with style :)


Picklesworth(Posted 2004) [#45]
what happening sswift?

sswift is afraid of turning off his computer...


Caff(Posted 2004) [#46]
That's a cool effect


Panno(Posted 2004) [#47]
fine


sswift(Posted 2004) [#48]
"sswift is afraid of turning off his computer... "

Not my fault my ram is bad. :-)


Neochrome(Posted 2004) [#49]
We all have to turn off our computers some time :( most of it not by choice! my wife complains if i leave it on!


Koriolis(Posted 2004) [#50]
Really neat!
I put this on the top of my "cool FX cook list"


JohnMil(Posted 2004) [#51]
This is awesome. The third demo reminds me of Metroid Prime's title screen. It ran perfectly on my 8mb graphics card... Easily the best demo I have seen from blitz. Even better is that it runs on my computer. ;)


Picklesworth(Posted 2004) [#52]
it's my screen saver now :D


big10p(Posted 2004) [#53]

This is awesome. The third demo reminds me of Metroid Prime's title screen.



Heh, exactly what i thought. ;)

Great, atmospheric effect. Well done!


Erroneouss(Posted 2004) [#54]
sorry for bringing this thread up again....
i know this thread is like, fifty years old.....
but does anybody still happen to have the source
for the spikey ball part that was linked to up here?
the link is dead... and it looks cool and i wanted to
see how he did those stuff...


Erroneouss(Posted 2004) [#55]
anybody still have this?