Skip to main content
GameDev.net gamedev.net
🔒 Locked

It seems that nobody here is smart enough, myself included...

Started by rob35 Jun 29, 2012 at 8:11 PM 6 replies 3.3k views
Original Post
rob35
rob35
There is a graphics maneuver that seems impossible to complete yet so basic... the very mention of it has put an end to this thread and this post on this forum.

I'll ask again: is there ANY way for Shader Model 2.0 cards to draw Contour Lines - not by crappily applying a 1d texture (that will look horrible... again, look at the first post here) but by using the screen-space derivative functions to do it properly? That functions (ddy, ddx, etc.) do NOT exist on SM 2.0 cards.

How do I proceed? I experimented using a derivative map that I passed along to the shader in a different texture channel, but there were two problems: 1. didn't completely standardize the widths of the lines and they became huge and pixelated when zoomed in (probably a precision problem) and 2. I am going to be animating datasets and interpolating along the time axis; perhaps I implemented it wrong, but it went bonkers when I tried this presumably because the derivate maps can't just be linearly interpolated.. (but shouldn't they be able to?)... there must be a simpler way to draw something as simple as contour lines over a texture! If I color the texture with a palette I can see the boundaries/edges where I want lines, so how do I get LINES?
Hodgman
Hodgman
Have you tried 1D texture approach, using a mip-mapped texture (with the line at ~1px width on every mip level), so when you zoom out, the line automatically gets thicker?

One old-school alternative to [font=courier new,courier,monospace]ddx[/font]/[font=courier new,courier,monospace]ddy [/font](which have been in GPUs going back 7 years now ;p) is to create a dummy texture, where each mip-level is a flat colour, which tells you which mip-level you've sampled.
e.g. if you had a 4x4 texture, the top (4x4) mip could be white, the middle (2x2) mip could be grey, and the bottom (1x1) mip could be black. When you sample the texture with mip-mapping enabled, if you get a black value, you know you're really zoomed in, and if you get a white value, you know you're more zoomed out.
If you do this with a larger texture (e.g. 256px instead of 4px), then you can more reliably get a 0-1 value that is based on the screen-space derivatives, allowing you to fudge your line thickness somewhat.

P.S. it would've been better to bump your old post rather that duplicating it.
TeaTreeTim
TeaTreeTim
You could just make the line narrower/thicker based on the normal and distance (ie if the slope is tangental to the plane of contour or camera is close, the line would be thicker so have a narrower criteria). I haven't tried this but I don't see why you couldn't mathematically work out the correct criteria.
21st Century Moose
21st Century Moose
Just set SM3 as your program's minimum hardware requirement and the problem goes away; you can then get on with being productive.

Seriously - SM2 is so old that you're doing yourself and your program a disservice by aiming so low. Even SM3 is quite ancient. 5 or 6 years ago this would have been a genuine problem, and that's an eternity in computing. Today SM3 capable hardware is ubiquitous (even Intel have had it since 2006); there's absolutely nothing that's "fancy" or "new" about it.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
6677
6677
My fairly low end laptop bought 4 years ago has SM3 still. Just use it.
rob35
rob35
Thank you everybody for your responses; Hodgeman - I had not thought of that and will try it, thank you. SM2.0 is unfortunately the minimum for my project, but I agree that that is stupid.


Render the world position to a second render target and calculate the contours in a screen space pass...

I am quite sure you seem to have more experience than I in this field; could you elaborate on this technique because it sounds to me like the best way of doing it. Thank you.
Zoner
Zoner
The games I am working on this year are probably the last two big SM3 projects we will be doing. its all D3D11 with SM5 and SM4 profiles going forward . . .
http://www.gearboxsoftware.com/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.