# Using ofLight with ofVbo results in strange line on surface

Hello,

I’ve been experimenting with lighthing on a surface mesh made with ofVbo (I need to use such object to modify vertices and colours on compute shaders for a project) and while experimenting I realised that there might be some problem with how lighting is calculated.
Take the following basic example, just a plane mesh that I make via the following for loop, setting up normals, indices and colours:

``````	originalColor = ofFloatColor::yellowGreen;

myIndices = new ofIndexType[myWidth * myHeight * 6];

int iteratorIndices = 0;

for (int y = 0; y < myHeight; y += 1) {
for (int x = 0; x < myWidth; x += 1) {

myVertices.push_back((float)x - myWidth / 2);
myVertices.push_back((float)y - myHeight / 2);
myVertices.push_back((float)0);
myVertices.push_back((float)1);

myNormals.push_back((float)0);
myNormals.push_back((float)0);
myNormals.push_back((float)1);
myNormals.push_back((float)1);

myVertColours.push_back(originalColor);

if (x < myWidth - 1 && y < myHeight - 1) {

myIndices[iteratorIndices] = x + y * myWidth;
myIndices[iteratorIndices + 1] = (x + 1) + y * myWidth;
myIndices[iteratorIndices + 2] = x + (y + 1) * myWidth;

myIndices[iteratorIndices + 3] = (x + 1) + y * myWidth;
myIndices[iteratorIndices + 4] = (x + 1) + (y + 1) * myWidth;
myIndices[iteratorIndices + 5] = x + (y + 1) * myWidth;

iteratorIndices += 6;
}
}
}

vertexBuffer.allocate(myVertices, GL_DYNAMIC_DRAW);
colorBuffer.allocate(myVertColours, GL_DYNAMIC_DRAW);
normalBuffer.allocate(myNormals, GL_DYNAMIC_DRAW);

myVBO.setVertexBuffer(vertexBuffer, 4, 4 * sizeof(float));
myVBO.setColorBuffer(colorBuffer, sizeof(ofFloatColor));
myVBO.setNormalBuffer(normalBuffer, 4);
myVBO.setIndexData(myIndices, myWidth * myHeight * 6, GL_STATIC_DRAW);

``````

I’m using buffer just to be able to bind them and modify them on compute shaders but in this example I am just drawing the ofVbo straight away without drawing it.
Notice how the normals are just set up with 4 dimensions (somehow doesn’t work with just 3) but what matters here is that z = 1 so the normal is facing upward perpendicularily to the surface.

The ofLight is just setup this way:

``````	pointLight.setSpecularColor(ofColor(255.f, 255.f, 255.f));
pointLight.setPosition(myWidth / 2, myHeight / 2, 0);
``````

Then the draw function is pretty easy:

``````	ofBackgroundGradient(ofColor(64), ofColor(0));

ofEnableLighting();
pointLight.enable();
cam.begin();
myVBO.drawElements(GL_TRIANGLES, (myWidth - 1) * (myHeight - 1) * 6, 0);
cam.end();
ofDisableLighting();
``````

Here’s what I see when running the program:

Any idea why those lines appear while they have no reason to?

Thanks

This is a sort of a corrected and light version of:

I just managed to narrow down and isolate the problem to ofVbo and ofLight.

Full code available here:
ofApp.zip (2.0 KB)
{"ft_lang_label":"__label__en","ft_lang_prob":0.680901,"math_prob":0.9604531,"size":2748,"snap":"2022-05-2022-21","text_gpt3_token_len":765,"char_repetition_ratio":0.14285715,"word_repetition_ratio":0.074742265,"special_character_ratio":0.27510917,"punctuation_ratio":0.19919518,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9665356,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-22T05:13:01Z\",\"WARC-Record-ID\":\"<urn:uuid:88ae33f3-bebf-4fbe-a7e7-0107fb58f8e3>\",\"Content-Length\":\"20001\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f948c771-5d4e-4942-8fd5-625d2a3af500>\",\"WARC-Concurrent-To\":\"<urn:uuid:79fdae97-5b15-4b19-8376-5aed427f0b87>\",\"WARC-IP-Address\":\"192.237.163.93\",\"WARC-Target-URI\":\"https://forum.openframeworks.cc/t/using-oflight-with-ofvbo-results-in-strange-line-on-surface/39794\",\"WARC-Payload-Digest\":\"sha1:LGEET6HZIUZ6DGNZCXSDDEOB67A4FCNZ\",\"WARC-Block-Digest\":\"sha1:2IEZAN6ATVFXLIRGYNXEX53JUOL2WYBL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662543797.61_warc_CC-MAIN-20220522032543-20220522062543-00716.warc.gz\"}"}