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:
#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.