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 6 of 6

Thread: Size of specular Highlight changes with camera distance

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Intern Newbie
    Join Date
    Oct 2016
    Posts
    46

    Size of specular Highlight changes with camera distance

    I dont know if this is supposed to be that way, but it doesnt seem realistic. My specular highlights stay the same size on my screen no matter how far away the camera is from the surface/vertex. I would like it to stay the same size.
    here is my Fragment shader
    Code :
    #version 430
    #define PI 3.1415926535897932384626433832795
    uniform vec3 lightColor;
    uniform sampler2D tex;
    uniform vec3 ambientLight;
    uniform vec3 lightPosition;
    uniform vec3 cameraPosition;
     
     
    in Vertex{
    	vec4 rawPosition; // Vertex Position only multiplied by the transformationmatrix. ( gl_Position is also multiplied by the projection and view matrices)
    	vec2 uv;
    	vec4 normal; // the normals have also been multiplied by the transformationmatrix ( is this correct? my normals have a w-value of 0.0f but the transformationmatrix makes a difference. without it the reflections dont seem be in the right place.
    }vertexIn;
     
    out vec4 color;
     
    void main(){
    	vec3 normal = normalize(vec3(vertexIn.normal.x, vertexIn.normal.y, vertexIn.normal.z));
    	vec3 worldPosition = vec3(vertexIn.rawPosition.x, vertexIn.rawPosition.y, vertexIn.rawPosition.z);
     
    	vec3 lightVector = normalize(lightPosition - worldPosition);
    	vec3 reflection = normalize(reflect((-1.0)*lightVector, normal));
    	vec3 cameraVector = normalize(cameraPosition - worldPosition);
     
    	float lightAngle = clamp(dot(lightVector, normal), 0.0, 1.0);
    	float cameraAngle = clamp(dot(cameraVector, reflection), 0.0, 1.0);
    	float specular = pow(cameraAngle, 100);
     
     
    	vec4 actColor = texture(tex, vertexIn.uv);
    	vec4 diffuseLight = vec4(lightColor, 1.0) * lightAngle;
    	vec4 specularLight = vec4(lightColor, 1.0) * specular;
    	color = actColor * clamp(diffuseLight, vec4(ambientLight, 1.0), vec4(1.0, 1.0, 1.0, 1.0)) + specularLight;
    	}

    here is an imgur link to visualize what i mean. the lightsource is the small cube above the middle of the grid

    thanks for the help
    Last edited by stimulate; 10-18-2016 at 12:18 PM.

Tags for this Thread

Posting Permissions

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