Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sin

macrumors regular
Original poster
Jun 25, 2007
152
0
Not London
I'm just starting to dabble in graphics programming on the Mac (having been doing it on other platforms for quite a while, I might add...) - I've run into a bit of a problem.

As soon as I put a discard statement into the fragment shader, everything disappears. If I replace it with a more benign operation, such as altering the pixel colour, everything is fine - the pixels I'd expect to be culled change and everything else looks normal. With the discard statement in the shader, nothing is visible at all.

There are no errors being reported, and compiling the shader by hand outputs a correct looking listing (and it's identical to that generated under Windows).

This is on a shiny new MBP with the 8600 in it. AFAIK I can't update video drivers on a Mac, so I was hoping the ones that ship would be reasonably stable, at least as far as basic shaders - so hopefully I'm just missing something obvious.

Here's a very simple shader that doesn't work - all I feed it is a single triangle with pure red, green, and blue at the 3 vertices... with discard in, it won't display anything, but substituting with a change of colour shows what I'd expect (an inscribed circle).

Code:
struct input
{
       float4 position : POSITION;
       float4 color    : COLOR0;
};


float4 main(input IN) : COLOR
{
       float m = IN.color.x * IN.color.x + IN.color.y * IN.color.y +
IN.color.z * IN.color.z;

       if(m > 0.5)
       {
//              m = 0; // This line works!
               discard; // This line doesn't!
       }

       return float4(m,m,m,1);
}

Any ideas?
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Maybe this is of no help but, have you tried Software Update? I seem to remember reading that there was a recent update to the new MacBook Pros which included new nvidia drivers.

b e n
 

Sin

macrumors regular
Original poster
Jun 25, 2007
152
0
Not London
Maybe this is of no help but, have you tried Software Update? I seem to remember reading that there was a recent update to the new MacBook Pros which included new nvidia drivers.

b e n

Hmm.. I think it's a driver issue, but there aren't any new updates so I guess I'm stuck with it.

I ported the code over to GLSL instead of Cg and it's doing the right thing. The strange thing is that it seems to generate the same instructions as the Cg, but some part of the driver is obviously unhappy with the Cg code.

Oh well, I'll have to go back to my PC for now and shelve the Mac stuff for a bit.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.