olzcharge.blogg.se

Opengl es 2.0 apps
Opengl es 2.0 apps





opengl es 2.0 apps opengl es 2.0 apps opengl es 2.0 apps

I do some more advanced per-pixel lighting in my open source Molecules application, where each sphere and cylinder is really a raytraced impostor residing within a rectangle. This light intensity is then interpolated between the vertices in each triangle to give you the intensity at each fragment. The dot product of the light direction and the normal at that vertex is used to calculate the light intensity hitting the eye of the viewer from that vertex. Gl_FragColor = vec4((yellow * lightIntensity * 0.2).rgb, 1.0) With the matching fragment shader: varying highp float lightIntensity LightIntensity = max(0.0, dot(newNormal.xyz, lightDirection)) Vec4 newPosition = modelViewProjMatrix * position Vec4 newNormal = modelViewProjMatrix * normal The vertex shader used here is the following: attribute vec4 position You can see an example of this in this sample application I slapped together for one of my classes. That said, you can replicate OpenGL ES 1.1's fixed function lighting capabilties by doing something like providing a light direction and calculating the light intensity at each vertex. It will depend on how you want to present your content. The difficulty with OpenGL ES 2.0 is that since you can write your own shaders pretty much how you want, there's no one set way to provide lighting to an object.







Opengl es 2.0 apps