I need help debugging this Spotlight implementation

I’m hoping someone can help me debug this wacky implementation of a Spotlight done in Java LWJGL that I found online. Basically, I found the bug, but I cannot figure out how to fix it so that the math makes sense.

The bug is that the code takes an angle and converts it radians and takes the cosine TWICE before passing it to an Open GL fragment shader. The value that the shader gets for the spotlight’s cutoff angle is like 0.99991065.

The first part of the bug appears in this class on lines 93-94: https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter12/c12-p2/src/main/java/org/lwjglb/game/DummyGame.java

    float cutoff = (float) Math.cos(Math.toRadians(140));     SpotLight spotLight = new SpotLight(pointLight, coneDir, cutoff); 

The value being passed to with “cutoff” is -0.76604444. So that’s the cosine of 140 degrees in radians… so far I’m ok.

The second part of the bug is in the constructor of the Spotlight class itself: https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter12/c12-p2/src/main/java/org/lwjglb/engine/graph/SpotLight.java

public SpotLight(PointLight pointLight, Vector3f coneDirection, float cutOffAngle) {     this.pointLight = pointLight;     this.coneDirection = coneDirection;     setCutOffAngle(cutOffAngle); } 

Combined with its setCutOffAngle method:

public void setCutOff(float cutOff) {     this.cutOff = cutOff; }  public final void setCutOffAngle(float cutOffAngle) {     this.setCutOff((float)Math.cos(Math.toRadians(cutOffAngle))); } 

Do you see the wackiness I’m talking about??? It’s treating the radian angle like degrees, converting it to radians again, and then setting the actual cutoff value to the cosine of that! That value is like 0.99991065 and that is what is passed to the fragment shader’s code.

This is the code in the actual fragment shader that uses the resulting value(line 112): https://github.com/lwjglgamedev/lwjglbook/blob/master/chapter12/c12-p2/src/main/resources/shaders/fragment.fs

vec4 calcSpotLight(SpotLight light, vec3 position, vec3 normal) {   vec3 light_direction = light.pl.position - position;   vec3 to_light_dir  = normalize(light_direction);   vec3 from_light_dir  = -to_light_dir;   float spot_alfa = dot(from_light_dir, normalize(light.conedir));    vec4 colour = vec4(0, 0, 0, 0);    if ( spot_alfa > light.cutoff )    {       colour = calcPointLight(light.pl, position, normal);       colour *= (1.0 - (1.0 - spot_alfa)/(1.0 - light.cutoff));   }   return colour;     } 

So I understand the concept of the Spotlight and it’s cutoff angle, but I’m not good at math or linear algebra. I’m hoping to learn how to use dot products and normalization from good examples. But this has got me totally confused. Yes, I can jury rig it to work by making my degree angle run through this bizarre double cosine(toRadians()) logic, but I’d rather do the math correctly…

Can anyone tell me how to fix this? This particular repository has been dormant for a couple years but it is still my top google search result and many people have recommended it online.

I really appreciate any expert help.

edit: maybe “bug” isn’t the right word for this. But I consider it a bug if the implementation intends for you to pass it an angle in degrees, but actually requires you to pass the value in radians…

[GET][NULLED] – Rocket Genius Gravity Forms WordPress Plugin v2.4.11.4


[GET][NULLED] – Rocket Genius Gravity Forms WordPress Plugin v2.4.11.4

[GET] Free Instagram bulk downloader


I would like to share FREE one of my software.

It is an Instagram bulk downloader. Easy to use, and working automaticly.


It necessary to add one working Instagram username with password. In my opinion, you just add one never use account, or register one fresh.

Just add the instagram account username, select video or images or both, and push start. When its ready, you can find images in the root folder of the program, or just push…

[GET] Free Instagram bulk downloader

Substance Designer: How to target the corners of random tiles

I’m trying to figure out a way to target the corners of randomly generated tiles so that I can place details there. Take for example putting bolts at every corner of a series of metal plates, for example. You want the bolts to be a consistent distance from the corner, and not to be skewed.

enter image description here

I have been able to create the following effect by a series of combined blurs, so this is generated just from the tile grid.

enter image description here

Here is the method: enter image description here

But this couldn’t really be used to actually place any complex designs in the same locations. How would I go about placing more complex details in those same locations?

Loading resources on OnLoad function

I am trying to load a json file using the cc.loader.load function in onLoad() function as shown below, I also have used some console.log() functions to see the order of execution.

const {ccclass, property} = cc._decorator;  @ccclass export default class NewClass extends cc.Component {  // LIFE-CYCLE CALLBACKS:  objectFromResource: Object  onLoad () {     console.log("Starting onLoad() Function")     var url = cc.url.raw('resources/json_resource.json')     cc.loader.load(url, (err, res) => {         cc.log(res)         this.objectFromResource = res         console.log("Loaded URL")     });     console.log("Ending onLoad() Function") }  start () {     console.log('Starting start() Function')     console.log(this.objectFromResource) //logging as null     console.log('Ending start() function') }  update (dt) {  }  } 

The output is as following:

Cocos Creator v2.1.1 JSONReader.ts:16 Starting onLoad() Function JSONReader.ts:33 Ending onLoad() Function JSONReader.ts:37 Starting start() Function JSONReader.ts:38 undefined JSONReader.ts:39 Ending start() function JSONReader.ts:22 {__type__: "cc.JsonAsset", _name: "json_resource", _objFlags: 0, _native: "", json: Array(784)} JSONReader.ts:24 Loaded URL 

The resource is loaded after the onLoad() and start() functions are completed. How to load the resource on OnLoad() function before the start() method is called?

Accessing scripts from inside a sub-folder in Unity

For a Unity project I am using this ROSBridgeLib from GitHub. There weren’t any clear instructions for how to import the library, so I just cloned the repository into my Scripts folder inside my project’s Assets folder. This causes Unity to throw an error CS0234: The type or namespace name 'ROSBridgeLib' does not exist in the namespace 'ROSBridgeLib' (are you missing an assembly reference?). How can I fix this issue?

I want to be able to organize my Scripts folder so I can keep C# files inside sub-folders. How can a script in the root of my Scripts folder access the ROSBridgeWebSocketConnection.cs script inside the folder Scripts/ROSBridgeLib?

Thank you for your help!

[GET][NULLED] – AdForest – Classified Ads WordPress Theme v4.1.3


[GET][NULLED] – AdForest – Classified Ads WordPress Theme v4.1.3

Ezytone Detox@>>>>http://www.worldfitnessshop.com/ezytone-detox/

p { margin-bottom: 0.25cm; line-height: 120%; }a:link { }

Ezytone Detox

Ezytone Detox@>>>>http://www.worldfitnessshop.com/ezytone-detox/




Ezytone Detox@>>>>http://www.worldfitnessshop.com/ezytone-detox/

2.5D z-buffering doesn’t work properly

I’m currently making a 2.5D FPS game in Java. And because I want to make more diverse maps I made taller walls but I have no idea how to change z-buffer code to handle walls with different heights. The taller blocks are using the same renderwall method as the smaller ones.

Weird z-buffering bug

As you can see my problem is that the smaller walls are covering the taller walls.

public void renderWall1(double x0, double y0, double x1, double y1, int tex, double xt0, double xt1, double height1) {

double xc0 = ((x0 - 0.5) - xCam) * 2; double yc0 = ((y0 - 0.5) - yCam) * 2; double xx0 = xc0 * rCos - yc0 * rSin; double u0 = ((-height1 - 0.5) - zCam1) * 2; double l0 = ((+0.5 - height1) - zCam1) * 2; double zz0 = yc0 * rCos + xc0 * rSin; double xc1 = ((x1 - 0.5) - xCam) * 2; double yc1 = ((y1 - 0.5) - yCam) * 2; double xx1 = xc1 * rCos - yc1 * rSin; double u1 = ((-height1 - 0.5) - zCam1) * 2; double l1 = ((+0.5 - height1) - zCam1) * 2; double zz1 = yc1 * rCos + xc1 * rSin;  xt0 *= size * 2; xt1 *= size * 2;  double zClip = 0.2;  if (zz0 < zClip && zz1 < zClip)     return;  if (zz0 < zClip) {     double p = (zClip - zz0) / (zz1 - zz0);     zz0 = zz0 + (zz1 - zz0) * p;     xx0 = xx0 + (xx1 - xx0) * p;     xt0 = xt0 + (xt1 - xt0) * p; }  if (zz1 < zClip) {     double p = (zClip - zz0) / (zz1 - zz0);     zz1 = zz0 + (zz1 - zz0) * p;     xx1 = xx0 + (xx1 - xx0) * p;     xt1 = xt0 + (xt1 - xt0) * p; }  double xPixel0 = xCenter - (xx0 / zz0 * fov); double xPixel1 = xCenter - (xx1 / zz1 * fov);  if (xPixel0 >= xPixel1)     return; int xp0 = (int) Math.ceil(xPixel0); int xp1 = (int) Math.ceil(xPixel1); if (xp0 < 0)     xp0 = 0; if (xp1 > width)     xp1 = width;  double yPixel00 = (u0 / zz0 * fov + yCenter); double yPixel01 = (l0 / zz0 * fov + yCenter); double yPixel10 = (u1 / zz1 * fov + yCenter); double yPixel11 = (l1 / zz1 * fov + yCenter);  double iz0 = 1 / zz0; double iz1 = 1 / zz1;  double iza = iz1 - iz0;  double ixt0 = xt0 * iz0; double ixta = xt1 * iz1 - ixt0; double iw = 1 / (xPixel1 - xPixel0);  for (int x = xp0; x < xp1; x++) {     double pr = (x - xPixel0) * iw;     double iz = iz0 + iza * pr;      int xTex = (int) ((ixt0 + ixta * pr) / iz);      double yPixel0 = yPixel00 + (yPixel10 - yPixel00) * pr - 0.5;     double yPixel1 = yPixel01 + (yPixel11 - yPixel01) * pr;      int yp0 = (int) Math.ceil(yPixel0);     int yp1 = (int) Math.ceil(yPixel1);     if (yp0 < 0)         yp0 = 0;     if (yp1 > height)         yp1 = height;      double ih = 1 / (yPixel1 - yPixel0);     for (int y = yp0; y < yp1; y++) {         double pry = (y - yPixel0) * ih;         int yTex = (int) (size * 2 * pry);          if (zBufferWall[x] > iz)             continue;          zBufferWall[x] = iz;          int color = Art.walls.pixels[((xTex) + (tex % size) * size * 2)                 + (yTex + tex / size * size * 2) * sheetSize];          if (color != 0xffff00ff) {             pixels[x + y * width] = color;             zBuffer[x + y * width] = 1 / iz * 4;         }     } }