openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Openexr-devel] half and hardware shading


From: Drew Hess
Subject: Re: [Openexr-devel] half and hardware shading
Date: Wed, 5 Mar 2003 11:39:08 -0800 (PST)

Yes, I've been playing with it.  With Nvidia's help, I have a version of
exrdisplay that uses a Cg shader to do all the exposure/defog/knee/gamma
math on the GPU.  It binds the image to a texture and draws a textured
quad.  Here's the Cg shader:

// exrdisplay pipeline

half3 knee (half3 x, half f)
{
    return log (x * f + 1) / f;
}

fragout main(vf30 In,
             uniform texobjRECT image,
             uniform float3 defog,
             uniform float exposure,
             uniform float gamma = 1.0/2.2,
             uniform half3 zerovec = {0,0,0},
             uniform half grayTarget,
             uniform half kneeLow,
             uniform half kneeF
             )
{
    fragout Out;

    half3 c = h3texRECT(image, In.TEX0.xy);

    c = max(zerovec, c - defog);

    c *= exposure;

    // knee

    c = (c > kneeLow) ? kneeLow + knee (c - kneeLow, kneeF) : c;

    // gamma correction
    // could use texture lookups for this

    c = pow(c, gamma);

    // scale middle gray to the target framebuffer value

    c *= grayTarget;

    Out.col.xyz = c;

    return Out;
}


You need an NV30 or a driver capable of NV30 emulation to make this work 
because it uses half values in a fragment shader.

Anyway, on an NV30 the Cg version of exrdisplay is faster than the
software version, and can probably be made faster still.  The software
version of exrdisplay precalculates the math and uses LUTs to do the
display conversion, but as you can see, this Cg shader does per-pixel
math.  I'll probably write one that does texture lookups to see how much
faster it gets.

As is, it's fast enough that I can set the sliders to update using
FL_WHEN_CHANGED, and it's real-time for all the images that come with the
OpenEXR sample image distribution.  For 2k images it's not quite
real-time, but it's definitely useable.

Right now this is kinda hacked into exrdisplay in my local tree, but when
I get something that cleanly integrates the Cg version with the software
version, I'll update the CVS.


-dwh-



 On Wed, 5 Mar 2003, Nafees Bin Zafar wrote:

> Has anyone implemented anything using the half data format and NVidia Cg 
> shaders?
> 
> -n
> 
> 







reply via email to

[Prev in Thread] Current Thread [Next in Thread]