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 / Shader: Object Specific Viewport Clipping

Author
Message
MegaByte
15
Years of Service
User Offline
Joined: 1st Nov 2010
Location:
Posted: 1st Nov 2010 15:24
I'm new here, so hi guys! I've got a shader for you.

The problem started like this: I needed a way to "clip" particular objects to regions on the screen. i.e Things would only render in certain specified areas of the viewport.

There didn't seem to be much information about this on the forum, so I decided to write a shader for it (attached).

How to use:

You need to load ONE effect for EACH CLIPPING REGION. Then set the region for each effect using:

set effect constant float effectnumber, "x1", #somevalue
set effect constant float effectnumber, "y1", #somevalue
set effect constant float effectnumber, "x2", #somevalue
set effect constant float effectnumber, "y2", #somevalue

where x1,y1 is the top-left corner and x2,y2 is the bottom-right. (Only rectangular clipping regions are supported)

To clip object x to the region specified for effect y, simply apply effect y to object x

"set object effect, x,y"

IMPORTANT:

For efficiency reasons, the Co-ordinate system for the rectangles is independent of resolution and is defined as follows:

using [x,y]

0,0 is the BOTTOM LEFT of the screen

x increases to the right, and y increases upwards

2,2 is the TOP RIGHT of the screen

(hence 1,1 is the center of the screen)

Good luck! and hope it's useful to some of you.

Do you ever feel, in your caves of steel, The chill of an ancient fear?
Do you shudder and say, when you pass this way,
A human once walked here?
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Nov 2010 17:01
Could be handy for anyone making a level editor or similar. I'll have to try this one. Thanks!

MegaByte
15
Years of Service
User Offline
Joined: 1st Nov 2010
Location:
Posted: 1st Nov 2010 18:35
No problem.

I just thought I'd include a screenshot for people who like that sort of thing.

Here we see two identical objects (textured planes in this case), one of which is leaving the specified clipping area.

Do you ever feel, in your caves of steel, The chill of an ancient fear?
Do you shudder and say, when you pass this way,
A human once walked here?

Login to post a reply

Server time is: 2026-07-22 04:37:18
Your offset time is: 2026-07-22 04:37:18