The shader is not a program, better call it a filter, it takes some input (vertex, fragment) and modifies it. I suppose that these are the data inputs:

        varying vec3  Normal;
        varying vec3  EyeDir;
        varying vec4  EyePos;
        varying float LightIntensity;

the output is then:

        gl_FragColor

All of these should be special registers in the HW.

Daniel


Nicolas Boulay wrote:
Very interresting !

This one has very few texture access and a lot of partial access to the vector element. There is no sin, cos, tan calcul.

This could be a good example for any GPU architecture.

I don't really understand how the shader is used. There is "some" implicit variable. So it's like having register with the good value inside.

But basicaly what is input and what is output of a shader ? (the real input and output of the "void main()" fonction ) and how it is scheduled ?

Le mardi 18 Avril 2006 20:20, Timothy Baldridge a écrit :
How's this:

//
// Fragment shader for environment mapping with an
// equirectangular 2D texture and refraction mapping
// with a background texture blended together using
// the fresnel terms
//
// Author: Jon Kennedy, based on the envmap shader by John Kessenich, Randi
Rost //
// Copyright (c) 2002-2005 3Dlabs Inc. Ltd.
//
// See 3Dlabs-License.txt for license information
//

const vec3 Xunitvec = vec3 (1.0, 0.0, 0.0);
const vec3 Yunitvec = vec3 (0.0, 1.0, 0.0);

uniform vec3  BaseColor;
uniform float Depth;
uniform float MixRatio;

// need to scale our framebuffer - it has a fixed width/height of 2048
uniform float FrameWidth;
uniform float FrameHeight;

uniform sampler2D EnvMap;
uniform sampler2D RefractionMap;

varying vec3  Normal;
varying vec3  EyeDir;
varying vec4  EyePos;
varying float LightIntensity;

void main (void)
{
    // Compute reflection vector
    vec3 reflectDir = reflect(EyeDir, Normal);

    // Compute altitude and azimuth angles

    vec2 index;

    index.y = dot(normalize(reflectDir), Yunitvec);
    reflectDir.y = 0.0;
    index.x = dot(normalize(reflectDir), Xunitvec) * 0.5;

    // Translate index values into proper range

    if (reflectDir.z >= 0.0)
        index = (index + 1.0) * 0.5;
    else
    {
        index.t = (index.t + 1.0) * 0.5;
        index.s = (-index.s) * 0.5 + 1.0;
    }

    // if reflectDir.z >= 0.0, s will go from 0.25 to 0.75
    // if reflectDir.z <  0.0, s will go from 0.75 to 1.25, and
    // that's OK, because we've set the texture to wrap.

    // Do a lookup into the environment map.

    vec3 envColor = vec3 (texture2D(EnvMap, index));

    // calc fresnels term.  This allows a view dependant blend of
reflection/refraction
    float fresnel = abs(dot(normalize(EyeDir), Normal));
    fresnel *= MixRatio;
    fresnel = clamp(fresnel, 0.1, 0.9);

        // calc refraction
        vec3 refractionDir = normalize(EyeDir) - normalize(Normal);

        // Scale the refraction so the z element is equal to depth
        float depthVal = Depth / -refractionDir.z;

        // perform the div by w
        float recipW = 1.0 / EyePos.w;
        vec2 eye = EyePos.xy * vec2(recipW);

        // calc the refraction lookup
        index.s = (eye.x + refractionDir.x * depthVal);
        index.t = (eye.y + refractionDir.y * depthVal);

        // scale and shift so we're in the range 0-1
        index.s = index.s / 2.0 + 0.5;
        index.t = index.t / 2.0 + 0.5;

        // as we're looking at the framebuffer, we want it clamping at
the edge of the rendered scene, not the edge of the texture,
        // so we clamp before scaling to fit
        float recip1k = 1.0 / 2048.0;
        index.s = clamp(index.s, 0.0, 1.0 - recip1k);
        index.t = clamp(index.t, 0.0, 1.0 - recip1k);

        // scale the texture so we just see the rendered framebuffer
        index.s = index.s * FrameWidth * recip1k;
        index.t = index.t * FrameHeight * recip1k;

    vec3 RefractionColor = vec3 (texture2D(RefractionMap, index));

    // Add lighting to base color and mix
    vec3 base = LightIntensity * BaseColor;
    envColor = mix(envColor, RefractionColor, fresnel);
    envColor = mix(envColor, base, .0);

    gl_FragColor = vec4 (envColor, 1.0);
}

On 4/18/06, Nicolas Boulay <[EMAIL PROTECTED]> wrote:
Look up into texture seems complicated.

http://oss.sgi.com/projects/ogl-sample/registry/ARB/GLSLangSpec.Full.1.10
.59.pdf

show function as :
vec4 texture1DProj (sampler1D sampler, vec4 coord [, float bias] )

That's quite complexe.

Inside http://www.lighthouse3d.com/opengl/glsl/index.php?texture we see :
      uniform sampler2D tex;

        void main()
        {
                vec4 color = texture2D(tex,gl_TexCoord[0].st);
                gl_FragColor = color;
        }

So, texture2D take a pointer and a vector. That's a lot more simple than
previous function. But what is used today ?
GLSL propose a lot of functionalities. What is needed is real world
example. I
need to know what is performance critical in current shader.

Nicolas Boulay

Le lundi 17 Avril 2006 17:03, Timothy Miller a écrit :
I've been thinking about programmable shaders and what we should
implement.  If we have some reasonable way to load immediate values
into vectors, then we can subsume all of the following into a single
dot product primitive:
- scalar adds and subtracts
- scalar multiplies
- vector dot product
- matrix multiply

We'll need a few other things like computing reciprocols (for
divides), vector sums and vector multiplies.  (Later today, when I
have time, I'll produce a more formal and precise description of the
primitives I have in mind.)

Anyhow, it seems to me that we should look at some examples.  There
are two things we can do here.  Some people with experience can write
out, in high-level pseudo-code, some simple shader programs.  And
someone else could look at the OGA "model" and convert that into the
pseudo code corresponding to how it would be fully implemented in a
programmable shader (some details can be left out).

This will help us figure out which primitives we need.  And from
experience later, we can figure out where we might benefit from adding
a few more and optimizing some things.
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)
--
I think computer viruses should count as life. I think it says
something about human nature that the only form of life we have
created so far is purely destructive. We've created life in our own
image. (Stephen Hawking)
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)

_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)

Reply via email to