jit.gl.material and jit.gl.shader questions
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.
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. ;-)
----------begin_max5_patcher---------- 680.3ocyVE0biBBD94zY5+AFeNwQQiI4dx62wM2jgnDCcPvCvFa6b+2uEHwl l4RhoSaZ0QVYYE91O1cwWt+tQAqjcTc.5GnegFM5EPyHmNqlQ6ULJnlzUvIZ mgAB5V4pGBFuaLCsy3z+.yDVwCqTrR8FRCEk2H0LCSJPSvgonHzj4n7BIWpf 2isO8Shr0voFySMTOVrS1xZhQw5BFiBBP+dukqkBifT6rK3mJFg2OIrRmR.b Sl0qrgXJ1vDUKUzBiexwoyCiFiRwIVAdVpSDEF85pHZqYB.QNON9v0Vyd1s1 wX3qd0ZuC3LG6z926uyJAw3OJlsgSLRTttfvonnvo8O4d9lUH0DTNm7DUA7a 9JNUTtjJHvK19jVizRpTKqAzeNmUswX4lWsAFdYIa85VMzMDl8LLzLOAZRW3 GlVyzZ6tZztamVcCsnkSrKr+1okTuhQEl8l16ZblfVHaEN+C+YEEjctnf3Et ffrHqHKJ1JRR+5CBra1MaYhR41SmdbDcbfOOcHQ991zogIvUZJ33CwyuQg4J HpkpNsuuhHpdWgC3yQMycEChmMyJlE8cujfAsBQUDM8x7j2rqkrhG.YkL0Jl N66NY8mZpQIQIQWfrtVNJ8xbzBG4jkbAJBecTT76lhLxpJ9YBZX1Rx+u5JIW 1Wy5CDFV3PCQATLbbztyerC9g6vDiQ0xNSkzqNwHZ.mpfwtDjEevoF8la8JG hTRCbfd2SOGbDC4WP2AsG++cNXaG3HdSKaUE64k8tJ5.nWR0vuKPr+R2AVk8 Vi1vJKoh2rWVxz18WGGFc5cxAiqjg.qzaNrRGBrhu4vJdHvB+k.q3OWXsKGf zz7HUo2MydDAEIdP5RgxF66yD999br.E8Q19OYmIDEjsafT8VkuFQ27LaZma Agl+AP56IrH -----------end_max5_patcher-----------
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:
----------begin_max5_patcher---------- 1031.3oc6Y0saaBCE95jmBDWmFgAye6prmiooJGvIwU.lYaZS5zd22w1PZ25 BvZSHQZKQfC1GLG+4yOeGx2mOycMeOU557Imu3La12mOaloKcGyZudlaIYeV AQZDysjJkjsT2E1wTz8JS+aXETmRhZ4VsnKeXurSjplRVUAUYte+1N2vqTR1 yTceH+kduHKuQ0ILpsWaWpC0Tql555701gpIprcrps2KnYJ6n9XX5b7CSzMo o5yH32GuEVtQg4qe3tf.2WoOUjRyCv8yBFovUOvOlOWeZwGDb.bgZlyqDjfB QKCW3fQHMZDFzGl3mNsXhS4A3mWKjI1yfHgFalz9AljyKvTQeBl12fKOvz9P K2JX4xcjZpyFJcM3asRlQfFuk9GOVYEPVuiJ.AJHGnBGOmUf3U42SqH56C4r hzn32eDuAAJXa2oz.wKx.CeeNaylFIb4RX5izOij.3DN0NLsjIkLdELC1uld k0zrlBh.lD6WSujx0LZkpSztUYAqhlwapLK0f+zdN5uYO2+T64.HpWvB1d2E iJbQjm0PHJR2fiOgIP7+HwKRRdkaw.wKh9WJdABaPlf3zQDvHXJCXbDeVoeR 8fRImEOrA8qvXSxFruEihLM9dm.p7lRnxD9y8CG848YAEf8s3hoILtOXAMQ4 hg7H4Tw0xmJzFy0RNAG2mKEJZJsS1QpxK5R.6d4xVMrujI4DBYBGi752lweJ sYbjfpd3ZY4Xwk1fww8R0GglRKmVvoi51aKNpMJ8oQuqDOnf1pmrD.NkM1Uh I7pZtjozLPuyeIF3UdWhypLdAWy5EoOtQfRKiIbjw7zOF2GVFOkXYcAQweSE EgGOZqnfkwkjtBJP+ufh2giDN0DkNDG1WAEm4zY5c45mXU47m50S3bkWJvKr yzFVivRM.9fwPXj.7edAGdTu5VrsYWO6l5Bvj8XH3KXbg0jpsCBTnvT8KfAY o5f7h5kL7jDQP4r1gJHxo.arOmw.PVJNCvJdRvmuURUBNXheAI2XvmQ.KwF6 k9KgBedQEEe61A7aF4hjoCNO7ZDG8RnjSsFOVPcMQ.qPH+SaBGsDduiUIQoD MryWof54yLwBtBROt+vytef2gMNzRoMse2gybsyWLLocq5iT0bPpoAE1qYBJ bbHh4dMTH9s+BDiBn6+WgIIuQj0otcOHmWTgbpDHAQzLTesPo+hP6X44Ty3c vVNSpAl7SaDOV8Q+t3FTezuDyoReRtszG8+2yf5SxjoN3wX8LcfyHzF7joMn wX4LoZC51Qa7FA3DMcpC51RchtoTG+faK0I81Zyx+B5mayuSpqejJjsSoQS. BOOvMjRhVXtjUYuzvYwUPej0IuU.h.Hjn.1HMBKWh8IQ.SB347i4+Dz6KZaB -----------end_max5_patcher-----------
any idea why this is? something to do with the normals?
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.
----------begin_max5_patcher---------- 800.3oc0WE0ihBCD9Y8WQCO6Zn.hx8j2eh6kKWLUXT6Fnkqsrq6tY+ueSaAW uKttnwPNkPKc5.8a9lNyXea7nf0x8fNf7MxOIiF813QibhrBF0NdTPEaedIS 6TKP.OKW+XvD+TFXuwI9QtYJSvqlJjEP2rhlJYioDLtWMpUZsBzfvvLboXkB xM9kOMbZ3DRbVjsKrsg7qtWhYx2wEaO5EhbJMy2QCccQzidGdgCZHbefF0go MRgQvp.2T+.TELA6H7xEcvk1JzaAlWpA+xFDLAuOrH1uml+paRJhcqz2GO11 LY3nzOicR5G6PuyYGxRcNqDvcLy5tuRBKNqkohOGgkcexWaKmVWxLRjt1wpA BOWpYjkkrW.EgRVttDDEq.ACevNl0XjqpXFPwYkjPTS91cFKs8gN3zqJ3a1z nwgSQlOMBaVDiMIY9ogJtViA63Wve4jpqg7lRlcg8WNorp0bL4vGph5TtZCK GHQGPZmwUxEPtrQXN10dgN7YybcogTm6O9zN7Emzg+cKubYtazMXYTEe+.63 2p3Edu9xZolaS9RdHZZBxwOr.oYYoTgOSs2WdrSxBe1FeTy7DWW3o4x428b4 cbPDsCoQ2lfHZlywm1mfnz6.Gu0CW+LWTHe9xiBZq45aSlMMF+kjXIjjSyHy tpZE278yJbGKntX6cgKZmNetsad34h4itUt90Lw1gJZ2PVS.ESCWKyDOyUgY 94XF5slY7Hd.nmeWAFkjDGdZ5g9UzSliWRiOG6jbgrSzYYmaIoXja2VBWoom dXKwma5wAG9JJzvw5GsELrZDdQaM31j6WSZClwnZ3m2Hs53TVIwyzA6e40fu 7OY6SQRyNejQ3sJznWNdmNtpg+y4gclgU9eSTZYiJuaEZOT.4CCo.zXQd2gb ORG64PORoc7hBPbrCsfqs9XGKb5sk8EN+yRcZ7rX3fSXOfS1fAmd4rnCG6P6 AdRGN3fqD8KPSzfhlv+aPSRe14LXnItGnI4JQiOiHqt9IPoa+jNffEIdT5R5 mNwMjK7CcYfCTvS7N88JvTXg.CVEnQ4ShueQZvX65793+zrchiC -----------end_max5_patcher-----------
Thank you, rob, for this neat trick
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.
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.