Can't see lights working openGL ES 2.0 -


i have set lighting in code , in shader cannot see apart quad have @ moment. lighting doesn't work , can't see have gone wrong.

i have quad texture on in quad rotated 90 degrees lying flat , in code have done lighting this...

    // set light direction in model space pvrtvec4 vlightdirmodel; vlightdirmodel =  modelview.inverse() * pvrtvec4(0.57735f, 0.57735f, 0.57735f, 0);  gluniform3fv(m_shaderprogram.auiloc[elight], 1, &vlightdirmodel.x);  // set eye position in model space pvrtvec4 veyeposmodel; veyeposmodel = modelview.inverse() * pvrtvec4(0, 0, 0, 1);  gluniform3fv(m_shaderprogram.auiloc[eeyepos], 1, &veyeposmodel.x); 

and here shaders

vert shader:

attribute highp   vec3  invertex; attribute mediump vec2  intexcoord;   uniform highp   mat4  mvpmatrix; uniform mediump vec3  lightdir; uniform mediump vec3  eyepos;  varying mediump vec3  eyedir; varying lowp    float  specintensity; varying mediump vec2  texcoord;  const mediump float  cshininess = 10.0;  void main() {     // transform position     gl_position = mvpmatrix * vec4(invertex,1.0);      // calculate direction eye position in model space     mediump vec3 eyedir = normalize(eyepos - invertex);          // specular lighting     // ignore n dot l negative (light coming      // behind surface)     mediump vec3 halfvector = normalize(lightdir + eyedir);     lowp float ndoth = max(dot(innormal, halfvector), 0.0);          specintensity = pow(ndoth, cshininess);      texcoord = intexcoord; } 

and here frag shader

uniform sampler2d reflectiontex;

varying mediump vec2  texcoord; varying lowp    float specintensity;    //this gets updated within main code uniform highp float time;  void main() {        lowp vec3 refcolor = texture2d(reflectiontex, texcoord).rgb;     gl_fragcolor =  vec4(refcolor + specintensity, 1.0); } 

you mixing lighting calculations. in comments you're calculating specular lighting term. flat surface, hope see code small white area somewhere on quad, if light angled just-so. calculation wrong not calculating reflected light vector.

the basic phong lighting model includes 2 other terms, diffuse (which varies colour reference angle between normal , light vec, i.e. greater angle, darker colour) , ambient (which adds uniform light every fragment simulate ambient light).

i suggest read excellent tutorial , adapt es: http://www.ozone3d.net/tutorials/glsl_lighting_phong.php


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -