Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Lens grit effect?

Author
Message
Southside Games
15
Years of Service
User Offline
Joined: 1st Jan 2010
Location: Don\'t tell me what to do!
Posted: 7th Feb 2014 06:20 Edited at: 7th Feb 2014 06:23
Hello!

How can I make a camera have "grit" on it? The hard part for me is to have only a part or parts to be displayed. what would cause it to be displayed would be a light source.

I don't plain on using an actual light because DarkBasic can only have seven. But I would like to be able to place an object that when looked at would show the part of the grit image that is around it.

I think I might be looking for something like a bump map. But I have not really used them yet and have no idea on were to began



Thanks.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th Feb 2014 12:09 Edited at: 7th Feb 2014 14:56
Well, maybe you can just pick the main light source - like in that image, the strip lights are the main source, so you could work out the camera angles, and affect the alpha of an overlay sprite with that. So, when you look at the light source the alpha of the sprite will be at maximum, then when you look away the sprite would fade out.

Like... say your light source is at lx#,ly#,lz#

dx#=camera position x()-lx#
dy#=camera position y()-ly#
dz#=camera position z()-lz#

Now, the next bit can be simplified, solved by different methods, really it's a matter of how accurate it needs to be. Like, I'd probably check the distance between the camera and light source, then move the camera forward 1 unit, and calculate the distance again - so I end up with a difference between -1.0 and 1.0 - anything >0.0 is closer to the camera. Anyway, to work out the distance using dx#,dy#,dz#

d#=sqrt((dx#*dx#)+(dy#*dy#)+(dz#*dz#))

Then move the camera forward 1 unit:

Move camera 1.0

Get the distance again, store it in d2# for example, then the difference between them is what to use for the alpha of your dirt sprite.

Then move the camera back -1.0 so it isn't flying forward the whole time.

Alp=(d2#-d#)*255
if alp<0 then alp=0
if alp>255 then alp=255

Set sprite alpha dirtsprite,alp


The dirtsprite, would be just dirt, greasy fingerprints even, but something that can overlay on top of the 3D stuff with that sort of texture. Maybe you could even do a ray collision check to the light source and include that - so the light has to actually hit the camera to affect the lens dirt.

I think a plain old sprite would be better than a normal map - you can make it subtle with a sprite, but a normal map might not let you fade and stuff the way you'd like. The sprite technique is easy to test at least, easier than having to make a normal map for dirt!

I am the one who knocks...
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 7th Feb 2014 14:49 Edited at: 7th Feb 2014 22:30
The best way (or the way they actually do it) is using scene luminance to modulate the dirt texture. You do a bright pass on the scene, blur it and blend it with the dirt image.

EDIT:


After testing, the method I suggested works (no blurring in this btw).

"Get in the Van!" - Van B

Attachments

Login to view attachments
wattywatts
15
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 8th Feb 2014 01:24
Getting an idea for an easier method.. what about a textured plain, locked to the camera, with semi transparent dirt, ghosted? Wouldn't it only show up around bright objects anyway? Have to test it out now.

New sig coming soon..
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 8th Feb 2014 04:04
I think a textured plain is basically the same thing. You could easily do what your saying with a basic post-process shader. just use a plain pass in the scene camera as image and then pass in your dirt as an overlay texture in the final computed output. using the scene brightness as your blend value.
Southside Games
15
Years of Service
User Offline
Joined: 1st Jan 2010
Location: Don\'t tell me what to do!
Posted: 8th Feb 2014 05:49 Edited at: 8th Feb 2014 05:50
@ Sasuke

wow how did you do that? that looks great. I've never even heard of a bright pass.

Login to post a reply

Server time is: 2025-05-15 05:05:17
Your offset time is: 2025-05-15 05:05:17