Forums > Jitter

jit.gl.material and jit.gl.shader questions

December 6, 2013 | 10:32 am

Hi

I have a couple of questions I try to find answers:

1. jit.gl.material has a "shader" attribute, but so far I was unable to see any effect on the material when applying a jit.gl.shader reference to it. Are there any use cases for this attribute? I would like to apply some customized shader on to objects that have a material attached. Is this possible?

2. I have found no way to shade an object flat (smoothing_enable = 0), that has a reference to a jit.gl.material. I tried to use the attribute on the object and the material without success. If I want to render a shiny diamond for example (width sharp edges) how should I do that?

thanks for any hints.


December 6, 2013 | 11:08 am

Sure
1. Ignore the @shader attribute on the jit.gl.material. It does nothing and is a remnant of being an OB3D. You are not able to successfully apply a jit.gl.shader and a jit.gl.material to the same 3D object (OB3D).

2. jit.gl.material *is* a shader. Its a shader that is pre-written and easy to use. Therefore, when you apply a jit.gl.material to an OB3D, it uses the shader pipeline and *not* the OpenGL standard pipeline shading (e.g. smooth/not shading).

IF you want an simple transparent diamond attached is an example of one approach. There are many other simple ones…and better looking ones. ;-)

<code>

– Pasted Max Patch, click to expand. –

</code>


December 6, 2013 | 11:55 am

dale, thanks for your reply. both you answers were what I expected, but I wanted to be sure I didnt miss something here.

and thanks for your diamond. lovely. but have you noticed that it doesnt do its diamondy thing from all the angles? I played a bit further and also noticed that it is possible to apply materials to the jit.gl.plato object without having it smooth shaded (contrary to my assumption in my previous post), but when I try to do the same thing with a jit.gl.gridshape object, applying a material will shade it smooth:

<code>

– Pasted Max Patch, click to expand. –

</code>

any idea why this is? something to do with the normals?


December 9, 2013 | 11:20 am

if you want to have a transparent object that is rotated, and has back facing polygons, you should link two copies of the object, set @cull_face 1 and @cull_face 2 for the two layers, and sync their transforms.

<code>

– Pasted Max Patch, click to expand. –

</code>


December 10, 2013 | 1:56 am

Thank you, rob, for this neat trick


December 11, 2013 | 6:13 am

When working with shaders (gl.shader or gl.material), the phrase "smooth shading" becomes almost…meaningless. I write that because the shaders are a program calculating math to create red, green, blue, alpha values. The meaning of "smooth" then becomes extremely dependent on the shader’s logic/code.

OpenGL objects are primarily draw with triangles. Over the years of OpenGL, different ways of passing the triangles x,y,z location have been created. And each way can have substantial affect on how it looks (blocky, faceted, smooth, etc.) In addition, many shaders uses the normals for these triangles which are created by the main OpenGL program and passed into the shader as data. The shader can then use, modify, interpolate, or ignore them.

All that combined together can then result in…well…anything really. You are seeing different shading smoothness looks on the gridshape sphere and the plato icosa because of the way those two objects pass in their triangles and their normals and the way the shader interprets the data.

Using your patch example and applying the mymat material to both, I see smooth shading on both. Notice as you rotate each of them, that you can see the light reflection and a center point of intensity as it travels across a single facet. I believe, that this demonstrates a typical meaning of smooth shading. Its all what you want it to be.


December 11, 2013 | 7:09 am

My concern was about how these two objects deal with the sharp edges. the jit.gl.gridshape has smooth edges (the light reflection spot never dissapears but moves smoothly from one face to the next), while the jit.gl.plato has sharp edges – but both with the same settings and the same material applied.

I made some test with my own dodecaeder, exported from blender, and in order to get a sharp edged object with a jit.gl.material one has to include the normals (when exporting to a obj-file), otherwise it gets smooth-edged.

So it looks as if gridshape doesnt generate any normals, and thats the main difference. (I might be corrected on this)

Thanks again both of you for clearify these issues.

cheers

martin

Attachments:
  1. diamond.zip

Viewing 7 posts - 1 through 7 (of 7 total)