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 / Set camera clip with objects using shaders?

Author
Message
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 25th Mar 2013 22:52
As was pointerd out here way back in 2006, set camera clip doesn't appear to work with objects that has shaders dictating their rendering.
Is there anyway around this? I'm guessing you might have to handle it from your shader yourself and simply not draw pixels beyond the clipping plane, but does somebody have a more rigid idea? Or if I'm on the right track, perhaps some code that actually accomplishes this - one thing I've learnt when messing around with shaders is that their coordinates does not seem to match those of DBPro...


"Why do programmers get Halloween and Christmas mixed up?"
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Mar 2013 00:21
Is it not set camera range?

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Mar 2013 01:50
No, this sets a special clipping plane that doesn't care about distance from the camera. It can be useful in reflection shaders to cut out anything behind the reflecting surface from the beholder's point of view to reduce rendering time for example.


"Why do programmers get Halloween and Christmas mixed up?"
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Mar 2013 20:23
Ahh, my bad.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 27th Mar 2013 11:47 Edited at: 27th Mar 2013 11:47
You can manipulate it in a Vertex Shader, i did it something like this.

Assuming "pos" in the struct is vertex position (float4 pos : POSITION; )
NearClipPlane and FarClipPlane are float variables.

Then in the VS you return:

float Clip=any((Out.pos.z>NearClipPlane)*(Out.pos.z<FarClipPlane));
Out.pos *=Clip;

/Regards
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 27th Mar 2013 13:36
Ah, thanks; I changed my water shader to a non-reflecting one for a bit but I'll try your solution soon


"Why do programmers get Halloween and Christmas mixed up?"
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Mar 2013 14:33
Quote: "float Clip=any((Out.pos.z>NearClipPlane)*(Out.pos.z<FarClipPlane));
Out.pos *=Clip;"


Won't that cause horrible distortions on models that stretch far into the scene? You're essentially snapping the vertices beyond the FarClipPlane to 0,0,0, or am I misinterpreting that?

I think it would be better to do the clipping in the fragment shader, and use the command clip(). Something like this (no guarantee this will work, it's off the top of my head):



http://msdn.microsoft.com/en-us/library/windows/desktop/bb204826

TheComet

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Mar 2013 02:12
Quote: "Won't that cause horrible distortions on models that stretch far into the scene? You're essentially snapping the vertices beyond the FarClipPlane to 0,0,0, or am I misinterpreting that?"


My bad, I had something messed up in my head. I now see that your method could work perfectly.

TheComet

Login to post a reply

Server time is: 2026-07-07 18:21:59
Your offset time is: 2026-07-07 18:21:59