🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Phone Lighting?

Started by
1 comment, last by JohnnyCode 5 years, 3 months ago

Any sage advice for me available? I am trying to get a phone shader up and working, although I am running into some sad blocks in OpenGL ES 2.0.

 

I have used this article as a starting point:

https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/lighting.php

 

Do I just need MORE polygons, or am I fundamentally misunderstanding something? Please help me, very sorry.

 

Vertex Shader:

uniform mat4 ProjectionMatrix;

uniform mat4 ModelViewMatrix;

uniform mat4 NormalMatrix;

 

attribute vec3 Positions;

 

attribute vec3 Normals;

 

attribute vec3 TextureCoords;

varying vec2 TextureCoordsOut;

 

varying vec3 N;

varying vec3 v;

 

void main(void) {

    v = vec3(NormalMatrix * vec4(Positions[0], Positions[1], Positions[2], 1.0));

    

    N = normalize(vec3(NormalMatrix * vec4(Normals[0], Normals[1], Normals[2], 1.0)));

    

    gl_Position = ProjectionMatrix * ModelViewMatrix * vec4(Positions[0], Positions[1], Positions[2], 1.0);

    

    TextureCoordsOut = vec2(TextureCoords[0], TextureCoords[1]);

}

 

 

 

Fragment Shader:

 

varying mediump vec3 N;

varying mediump vec3 v;

 

uniform lowp vec4 ModulateColor;

varying lowp vec2 TextureCoordsOut;

uniform sampler2D Texture;

 

//r, g, b, [ambient intensity]

uniform lowp vec4 Ambient;

 

//dirX, dirY, dirZ, [diffuse intensity]

uniform lowp vec4 Diffuse;

 

//Shininess, Specular Intensity

uniform lowp vec2 Specular;

 

void main (void) {

    

    mediump vec3 Direction = vec3(-Diffuse[0], -Diffuse[1], -Diffuse[2]);

    //highp vec3 SpotlightPosition = vec3(Specular[0], Specular[1], Specular[2]);

    

    //highp vec3 L = normalize(SpotlightPosition - v);

    mediump vec3 L = Direction;//normalize(SpotlightPosition - v);

    

    mediump vec3 E = normalize(v); // we are in Eye Coordinates, so EyePos is (0,0,0)

    mediump vec3 R = normalize(-reflect(L,N));

    

    //calculate Diffuse Term:

    lowp float Idiff = max(dot(N,L), 0.0) * Diffuse[3];

    Idiff = clamp(Idiff, 0.0, 1.0);

    

    // calculate Specular Term:

    lowp float Ispec = pow(max(dot(R, E), 0.0), Specular[0]) * Specular[1];

    Ispec = clamp(Ispec, 0.0, 100.0);

    lowp float Ilight = Ambient[3] + Idiff + Ispec

    gl_FragColor = vec4(Ilight, Ilight, Ilight, 1.0);   

}

 

 

 

 

 

oddities.jpg

Advertisement

Try to normalize N varying vector, it should help a bit.

Direction vectors do not interpolate good so on the edges there is artifact always, but should not be this big.

 

This topic is closed to new replies.

Advertisement