changekasce.blogg.se

Java lwjgl spot lights
Java lwjgl spot lights












java lwjgl spot lights
  1. #Java lwjgl spot lights driver#
  2. #Java lwjgl spot lights code#

Potentially you add a big value with a small value in float32 space - this may be impossible, as you only have 7 significants to use. I may rather write the different parts separately. You calculate lightDirection twice for the spot light, once in calcSpotlight and once in calcPointlight.

#Java lwjgl spot lights driver#

Or maybe the GPU driver goes nuts there :-). Maybe you simply produce black where the dot product is 0.71 - may happen at only a few pixels, where the spotlight values are much on negative. Will be: 1 - (1 - 0.6) / (1 - 0.71) -> -0.379310345Īnd the breakpoint is ofc where the dot product and spotLight.cutoff are equal or close to equal.Īfter this i cannot guess what happens. Then color goes negative here (as you said spotLight.cutoff is 0.71): color = calcPointLight(spotLight.pointLight, normal) * If spotFactor becomes 0.6 at a specific pixel, from this float spotFactor = dot(lightDirection, spotLight.direction) Here, the black pixels are mostly at the edge of the spotlight Here, the black pixels can be seen at the bottom of the spotlight Here are some example images of the bug in game: And since debugging in GLSL is nearly impossible, I've decided that my last possible option is to post my question here.

java lwjgl spot lights

I checked to see if there was maybe some division by zero problem or something of the like, but I can't for the life of me figure out what the problem actually is. TotalLight += calcSpotLight(spotLights,normal) TotalLight += calcPointLight(pointLights,normal) TotalLight += calcDirectionalLight(directionalLight, normal) Vec4 textureColor = texture(sampler, texCoord0.xy)

java lwjgl spot lights

This is likely the problematic code, but I'm not 100 percent sureĬolor = calcPointLight(spotLight.pointLight, normal) * Vec3 lightDirection = normalize(worldPos0 - ) įloat spotFactor = dot(lightDirection, spotLight.direction) Vec4 calcSpotLight(SpotLight spotLight, vec3 normal) Vec4 color = calcLight(pointLight.base, lightDirection, normal) įloat attenuation = + LightDirection = normalize(lightDirection) Vec3 lightDirection = worldPos0 - pointLight.position įloat distanceToPoint = length(lightDirection) Vec4 calcPointLight(PointLight pointLight, vec3 normal)

java lwjgl spot lights

Return calcLight(directionalLight.base, -directionalLight.direction, normal) Vec4 calcDirectionalLight(DirectionalLight directionalLight, vec3 normal) SpecularColor = vec4(lor, 1.0) * specularIntensity * specularFactor SpecularFactor = pow(specularFactor, specularPower) Vec3 reflectDirection = normalize(reflect(direction, normal)) įloat specularFactor = dot(directionToEye, reflectDirection) Vec3 directionToEye = normalize(eyePos - worldPos0) Vec4 calcLight(BaseLight base, vec3 direction, vec3 normal)įloat diffuseFactor = dot(normal, -direction) ĭiffuseColor = vec4(lor, 1.0) * base.intensity * diffuseFactor Uniform DirectionalLight directionalLight I still don't know what the exact problem is, but that should narrow down the possible errors. It appears that the problem is indeed in the calcSpotLight function, but within the calcSpotLight function, the problem is the calcPointLight function. I just updated the driver and reran the program and indeed received no black pixels. Update: I have found that the problem was indeed in my graphics card's driver.

#Java lwjgl spot lights code#

What I believe to be the problematic code is marked with a comment below in the function calcSpotLight. This can only mean that there is a bug in the fragment shader itself. This has only occurred when I modified the fragment shader to include spotlights. When I run the game, when viewing the mesh at certain distances and angles, namely close distances and sharp angles, I run into this interesting bug when certain pixels just go black. The example game currently running in the engine is a spotlight that follows the camera and a plane mesh with a tile texture. I followed the tutorial for writing a fragment shader that utilizes spotlights in GLSL. I've recently been following a tutorial for writing a game engine in Java using LWJGL 2.














Java lwjgl spot lights