You can use them like regular Craft materials (though I think this has been a bit improved in the latest Codea beta — let me know if you want to join that)
Just drag and drop your Shade material or copy-and-paste it from Shade into the Codea documents directory in "On My iPad -> Codea" on your filesystem. Then they will show up in the material picker in Codea.
@iam3o5am You can define shaders in code yourself if you want. What you need to do is create a special shader definition table and add that to the shader system so it can be compiled.
To simplify some things there is a surface shader system where you can define functions to determine vertex and fragment shader outputs with simplified parameters. You can make stuff physically based or unlit. You can also write a shader from scratch but that's more complicated.
Unlike the old mesh system you need to specify the names of any uniforms you want to access as property materials. This allows you to specify default values as well. Options allow for different shader variants, some of which are special reserved names for things like lighting, and others can be defined and linked to properties. This lets you write shaders with lots of options, like the Standard material, which comes with craft.
I've also attached zipped up versions of these basic shaders that you could edit and then add as bundles to your projects or the documents folder.
Oh yeah in case you were wondering what is in Vertex, Input and SurfaceOutput, these are all structs which pass data between parts of the shader programs to determine the final appearance:
Note that some things are inside of #ifdef macros, which are used in conjunction with the options in the shader definition to turn certain features on and off.
Thanks @John - that’s very helpful. Between these examples and looking at the rest of the Shade examples, I’ve got plenty to go on.
A final question, then, is this: Is there a way to directly use the GLSL vertex and fragment shader code that can be used now on a mesh object? Basically, is there any way to use a Codea mesh shader (say from an older Codea project), as is, in Craft, or should I buckle up and just start mastering Shade? The latter option is exciting anyway, and potentially easier to create advanced materials, but just wondering if using direct GLSL is still a possibility. As a concrete example, could I, via Shade, set GLSL options, such as #GL_OES_standard_derivatives, etc.?
Thanks! Enough on this thread, just wanted to get a handle on where its all going and what possibilities there are.
@iam3o5am I would probably hold off on too much GLSL. One of the main reasons we started building Shade was to get away from GLSL because Apple has deprecated OpenGL and will be removing it from iOS in a couple years.
The plan with Shade is to have it generate Metal and Unity shaders. At the moment its GLSL code-gen is a temporary measure while Codea still runs on OpenGL.
@iam3o5am The API itself will remain very similar (some key things might change though). Things related to mesh, shader and the craft material system will undergo the most changes. The biggest one being the switch to Metal shader syntax.
Metal as a graphics API is much more modern and easier to work with than OpenGL but aside from the shaders this isn't going to be exposed to the end user all that much.
Comments
see https://codea.io/talk/discussion/8806/converting-meshes-to-models
No talk there of shaders (from what I read). I don’t see where on a Craft model I can apply shaders.
@iam3o5am
You can use them like regular Craft materials (though I think this has been a bit improved in the latest Codea beta — let me know if you want to join that)
Just drag and drop your Shade material or copy-and-paste it from Shade into the Codea documents directory in "On My iPad -> Codea" on your filesystem. Then they will show up in the material picker in Codea.
@Simeon Thanks. That was posted once before but you show it here before I was able to find it.
@iam3o5am dm me your Apple ID email
Any way to define the shader (as strings) directly in code, on the craft material, just as we do on mesh objects?
@iam3o5am You can define shaders in code yourself if you want. What you need to do is create a special shader definition table and add that to the shader system so it can be compiled.
To simplify some things there is a surface shader system where you can define functions to determine vertex and fragment shader outputs with simplified parameters. You can make stuff physically based or unlit. You can also write a shader from scratch but that's more complicated.
Here's an example project:
Unlike the old mesh system you need to specify the names of any uniforms you want to access as property materials. This allows you to specify default values as well. Options allow for different shader variants, some of which are special reserved names for things like lighting, and others can be defined and linked to properties. This lets you write shaders with lots of options, like the
Standard
material, which comes with craft.I've also attached zipped up versions of these basic shaders that you could edit and then add as bundles to your projects or the documents folder.
Oh yeah in case you were wondering what is in
Vertex
,Input
andSurfaceOutput
, these are all structs which pass data between parts of the shader programs to determine the final appearance:Unlit SurfaceOutput:
Physical SurfaceOutput
Note that some things are inside of #ifdef macros, which are used in conjunction with the options in the shader definition to turn certain features on and off.
Thanks @John - that’s very helpful. Between these examples and looking at the rest of the Shade examples, I’ve got plenty to go on.
A final question, then, is this: Is there a way to directly use the GLSL vertex and fragment shader code that can be used now on a mesh object? Basically, is there any way to use a Codea mesh shader (say from an older Codea project), as is, in Craft, or should I buckle up and just start mastering Shade? The latter option is exciting anyway, and potentially easier to create advanced materials, but just wondering if using direct GLSL is still a possibility. As a concrete example, could I, via Shade, set GLSL options, such as #GL_OES_standard_derivatives, etc.?
Thanks! Enough on this thread, just wanted to get a handle on where its all going and what possibilities there are.
@iam3o5am I would probably hold off on too much GLSL. One of the main reasons we started building Shade was to get away from GLSL because Apple has deprecated OpenGL and will be removing it from iOS in a couple years.
The plan with Shade is to have it generate Metal and Unity shaders. At the moment its GLSL code-gen is a temporary measure while Codea still runs on OpenGL.
Will the Codea API change considerably once OpenGL is gone? (Going now to read up on this (maybe not so new?) news from Apple...)
@iam3o5am The API itself will remain very similar (some key things might change though). Things related to
mesh
,shader
and the craft material system will undergo the most changes. The biggest one being the switch to Metal shader syntax.Metal as a graphics API is much more modern and easier to work with than OpenGL but aside from the shaders this isn't going to be exposed to the end user all that much.
@John will that mean that shadertoy shaders will no longer work (arghhh)?