I found a per-pixel spotlight shader here: http://www.lighthouse3d.com/opengl/glsl/index.php?spotlight and put it in the BGE. To my surprise it actually works, although there are serious issues. The shader only works when 3d view is maximized and spotlightās beam gets strange distortions when it hits polygon edges. I thought per-pixel lightning is fully independent from vertex/edge positions. Perhaps some shader guru here could make it work betterā¦ my experience with shaders is quite limited. I didnāt modify the actual shader code, just copypasted mainloop from Blender graphics demos.
With this shader things like flashlights, headlights etc. would be easy to do. BGE has always supported vertex lightning but it is dependent from vertex positions. So it looks awful if the faces of the lighted mesh arenāt evenly distributed or if the mesh is very low poly. Hereās a comparison of the spotlights lightning a subdivided plane. That cone in the center marks the position of the lamp. Left is vertex spotlight and right is per-pixel spotlight:
Hereās the FPS template with flashlight using the shader: http://users.tkk.fi/~pkangass/blender/FPSTemplateFlashLight.blend
Too bad all objects lose their textures when the shader is assigned to them. I guess texture handling must be added to the shader. Unfortunately I donāt know how.
At least shader version 2.0 capable graphics card is required (GeForce FX and newer, Radeon 9500/9700 and newer). I donāt think that shader is very useful unless textures can be used with it. Untextured game might not look very professionalā¦
Of course it COULD work with textures if someone (I donāt have the skills, yet) modified the shader code. Such lights are used in many commercial games like Doom 3, Far Cry etc. and they certainly have textures too :eyebrowlift2:
Just because commercial games do it doesnāt mean blender is capable of it.
There is also some major distortion when the faces are more parallel with the spotlight, versus the more accurate lighting when the faces are perpendicular to the spotlight.
I donāt see a good reason why it wouldnāt be possible when basic per pixel lamps can be used with textures (see āsebublaā blend in graphics demos). I am more worried about the distortion because the shader worked perfectly in other engine. Oh well, another reason to hope for Ogre integrationā¦
have you seen this site about how to use the GLSL inside of blender http://snailrose_dir.home.bresnan.net/material.html
half of the problem is the room/level uses Texface with different maps on different polysā¦ looks like there is a problem with using texface and GLSLā¦ the crates use blender materials without tex face and they appear in GE with textures and the per pixel light works fine on thoseā¦
āthe light affects the specular settings of the objectsā¦ so turn up the specular and set it to blinn and you will see the affect of the lightā¦ like you would do for a renderingā¦ also, flat objects like crates generally arnāt that reflectiveā¦ so put in a normal map and get specular on the bump edgesā¦ or put in a sphereā¦
also crank up the light intensityā¦ it might actually be doing vertex shading on the boxesā¦ canāt really tellā¦ but you can make lights that attenuateā¦ there are some examples of that on the ozone3d site
hereās a pic with the changed specular settings the real question would be how do you add in more lights? I tried doing that and it didnāt work out so well
Unfortunately itās just vertex light on the crates. All objects which are affected by the shader must be listed in the shader script. Look for line called āShaderObjectsā.
I too couldnāt succeed adding more lights. I tried to give each shader unique gl_LightSource[], but only the last added lamp worked. I guess I should start studying those GLSL docsā¦
Unfortunately itās just vertex light on the crates. All objects which are affected by the shader must be listed in the shader script. Look for line called āShaderObjectsā.
hmmm then we should somehow be able to load all the objectsā¦ anyone who knows python better know how to do thisā¦ it is possibleā¦ it should make the pixel shader work on all objectsā¦