simple lighting of 3d meshes

strontiumDog's picture

Hello I've created a 3d open ended cone using the quad structure patch (thank you for creating all these patches btw - deluxe) and i can't seem to light it using the std lighting patch. the spot is only used for images and i've got a number of 3d structures moving in space which i want to make look shiny.

i've seen discussions about glsl, but don't know enough about obj-c yet to make it count, and wondered if there was a specific method i'd need to use to get the same kind of result when a primitive sphere is included [image attached].

thanks in advance s

coneUnlit.gif32.78 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture

Lighting in OpenGL (either standard lighting via the lighting patch, or fancy lighting via GLSL) requires vertex normals (A normal is a unit vector that points the direction the face is facing at that vertex).

The quad/triangle structure patches support normals, but you have to calculate/supply them yourself.

gtoledo3's picture
I was going to reply to this

I was going to reply to this yesterday, and hesitated because I wrote this long winded thing, and then realized that it may not apply...

What exactly do you mean by shiny? Metallic looking?

If you just want to enhance the lighting effect and get it to "pop" more, you may want to consider going into the setting on the patch inspector for your lighting, and add more than one lighting source... it looks like there is only one source from the picture. That will at least give a little gradient of light to dark on the curves of the object.

Here is an example that uses a GLSL shader instead of the standard light patch- simply for lighting effect. When you use the "environment map" GLSL without an image, it can make looks very similar to the stock lighting... but it can sometimes be cooler to control it like this because of the "blend" control on the shader and the "look" that it gets. You could also add individual shaders to your objects, then place them all in a two or three point lighting. If you are clever with it, that can be used to insinuate the feeling of spot lighting in conjunction with global lighting.

The blend is one part that I haven't put "automation" on, so you might want to go in and tweak it up and down and see if any of that gets you closer to what you are looking for..... It seems like I have a decent "porcelain" looking shader somewhere but I can't find it. It may have been this image map with a particular image input. If you were to get a fisheye looking image that had a nice sheen to it, and connect it to this shader, you may be able to get a truly "shiny" look.

GLSL Lighting Example.qtz4.58 KB
GLSL Lighting Example 2.qtz4.61 KB

cwright's picture

Note that both of these examples only work if the mesh has normals (they both require gl_Normal for useful output), so make sure you've taken care of that first, or this won't help :/

(OP's picture showed a lighting patch parameters thing in the back, so he should be getting something light-wise if he had normal data, hence my assumption that this is what he currently lacks)

gtoledo3's picture


strontiumDog's picture

thanks for the help, but i got lost when you started talking about glsl shaders as i'm only familiar with what glsl is and know almost nothing of it's language or setup.

i guess, in the most simple terms, i'd like to setup this cone item in space with the most simple normal setup which means points (pointing) of light means - say - that as it rotates around x,y,z, you can see the object appears shiny. i can then apply the principle to what i'm doing.

cheers s

cwright's picture

You don't need to know anything about GLSL to accomplish this.

You do need to understand how lighting works, and the basics of geometry.

Lighting an object (either by the Lighting patch, or by your own GLSL shader, it doesn't matter) requires the surface normal at each vertex to calculate the light. The Surface Normal is a unit vector (length = 1) that points the direction the surface is facing at that vertex. Typically one uses a cross product to calculate this (using 2 sides of each triangle as the two source vectors). This will give you a faceted look under lighting, but it's a start. Then you can bend the vertices at each vertex to make the mesh more smooth.

If the above doesn't make any sense at all, then you should take a night off and curl up with a good math/geometry book. It sounds a bit rough, but there really isn't much we can do to make it more friendly (we could auto-calculate face normals, but the meshes would all look faceted and lame most of the time, and the patch would be considerably slower).

strontiumDog's picture

i have such a book, so i'll have a look. i guess i was hoping as with many posts someone will come back with an early test patch they had mothballed as i find it often easier to grasp a concept by reading other peoples code.