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 / Recalculating normals in a shader

Author
Message
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 16th Aug 2011 08:25
Sorry for not doing a big search, but, I'm sure this can be easily answered by the shader gurus. I'm working on a DGDK.net project, and, I need to recalculate normals every frame. The DGDK.net command, GenerateObjectNormals(), is an FPS killer. Not just inside the DGDK object, but anything else I might have running alongside it. Does anyone know of a simple shader to recalculate normals?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Aug 2011 10:48
Quote: "I need to recalculate normals every frame"


Why do you need to do that?

Quote: "Does anyone know of a simple shader to recalculate normals?"


I doubt it - unless you are talking about animated boned models where the existing normals can be updated using the transformation matrices from the object's bones. If that's the case take a look at this demo posted by Van B some time back. If I recall correctly the size of the boneMatrix array in the shader can be increased from 32 to 64 now.
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 20th Aug 2011 06:51
I'm working with the Kinect and Microsoft's Kinect SDK. The fastest, easiest way to get up and running was by using DarkGDK.net. I can display an 80x60 mesh and deform it in realtime, using the Kinect as source data. Since the mesh changes every frame, so should the normals. Just calling the GenerateObjectNormals() function in DGDK.net is very slow. It drops fps from like 44 to 15 or so. So, I was hoping to offload this to the gpu. Since its a fixed grid of 80x60 points, this should be doable. I suppose it would be the very bare bones of maybe what a water shader is. Or, a faster function to recalc the normals on the cpu.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Aug 2011 11:48
Quote: "Since its a fixed grid of 80x60 points, this should be doable. I suppose it would be the very bare bones of maybe what a water shader is. Or, a faster function to recalc the normals on the cpu."


Do you mean something like a flat terrain where only the Y coordinate changes? If so then a fast update procedure should be possible. As you say, 80x60 points shouldn't be too much for the CPU to handle each frame.

I don't know of a simple way of doing it on the GPU unless you are using a known function, such as cos() or sin() to do the deforming.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Aug 2011 15:33 Edited at: 20th Aug 2011 15:34
dbSetObjectNormals(obj) is a GDK & DBP function which I've used recently which saved me the time of googling and writing a piece of code to do it.

EDIT: If your mesh only goes through so many deformations would it not be better to store it as an animation instead and just pick a frame...

Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-10 17:18:52
Your offset time is: 2026-07-10 17:18:52