Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Imposter Sphere

  1. #1
    Newbie Newbie
    Join Date
    Dec 2013
    Posts
    3

    Imposter Sphere

    Hello,

    I've been following the tutorial on arcsynthesis.org:

    Chapter 13 is about drawing imposter spheres. Basically you render a sqare and perform this in the fragment shader:
    Code :
    #version 330
     
    //in vec3 vertexNormal;
    in vec3 modelSpacePosition;
    in vec3 modelSpaceLightPos;
    //in vec3 lightIntens;
     
    out vec4 outputColor;
     
    //uniform vec3 modelSpaceLightPos;
     
    void Impostor(out vec3 cameraPos, out vec3 cameraNormal)
    {
        vec2 mapping = vec2(modelSpacePosition);
        float lensqr = dot(mapping, mapping);
        if(lensqr > 1.0)
            discard;
     
        cameraNormal = vec3(mapping, sqrt(1.0 - lensqr));
        //cameraPos = (cameraNormal * sphereRadius) + cameraSpherePos;
        cameraPos = (cameraNormal * 1.0f) + modelSpaceLightPos;
    }
     
    void main(void)
    {
        vec3 cameraPos ; vec3 cameraNormal;
        Impostor(cameraPos, cameraNormal);
     
        vec3 lightDir = normalize(modelSpaceLightPos - modelSpacePosition);
     
        float cosAngIncidence = dot(lightDir, normalize(cameraNormal));
        cosAngIncidence = clamp(cosAngIncidence, 0, 1);
     
        outputColor = vec4((cosAngIncidence * vec3(0.8f) + vec3(0.2f)), 1.0f);
    }
    I've gotten this to work with my own code but I want to know if the best course of action to creating 3d sphere in world space (rotate the camera around arbitrarily) is to have the sphere always facing you; doom model style (face the sphere to the camera on every iteration of display) or is there a better way?

    Thanks in advance. I'd post pics if the new register limit wasn't in effect.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101
    Imposters are best used for objects that will render to a small number pixels on the screen. This can be because the objects are inherently small or are a long way from the camera.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •