Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Examples shaders

Mika
Guest
Quote
2014-10-19 14:34:33


Please help to convert one of these shaders for directx GLSL to HLSL to get a template for directx


mrmdesign
Registered User
Quote
2014-10-20 11:50:27

Well done everyone!
Your work in this thread just made me upgrade to CC5.

Does anyone know how to get these all working in WebGL?

Many Thanks in advance.


mrmdesign
Registered User
Quote
2014-10-20 12:59:08

I just found Mozilla Firefox's Shader Editor which may help.
You can use it to inspect an element in the same way you would if looking at a pages css, html or javascript and make changes on the fly.

This could be an invaluable resource for WebGL Shaders in Coppercube.


Specularmap
Guest
Quote
2014-10-20 14:12:28

This could be an invaluable resource for WebGL Shaders in Coppercube

Yes. It's interesting.
https://developer.mozilla.org/en...


mrmdesign
Registered User
Quote
2014-10-20 14:47:06

@Niko
What are the key differences in the shader code when targeting WebGL?

For instance, what needs to be done to get the skull example from this thread working in WebGL?

Thanks in advance for your assistance.


mrmdesign
Guest
Quote
2014-10-20 17:08:39

Hi Guys, Me again.
I was wondering if anyone here could offer assistance.
I am trying to get this shader: http://www.mathematik.uni-marbur... working in coppercube webgl export as a start but it is just making the soldier invisible.

var vertexShader =
"attribute vec3 inputPosition; \n" +
"attribute vec2 inputTexCoord; \n" +
"attribute vec3 inputNormal; \n" +
" \n" +
"uniform mat4 projection, modelview, normalMat; \n" +
" \n" +
"varying vec3 normalInterp; \n" +
"varying vec3 vertPos; \n" +
" \n" +
"void main(){ \n" +
" gl_Position = projection * modelview * vec4(inputPosition, 1.0); \n" +
" vec4 vertPos4 = modelview * vec4(inputPosition, 1.0); \n" +
" vertPos = vec3(vertPos4) / vertPos4.w; \n" +
" normalInterp = vec3(normalMat * vec4(inputNormal, 0.0)); \n" +
"} ";

var fragmentShader =
"precision mediump float; \n" +
" \n" +
"varying vec3 normalInterp; \n" +
"varying vec3 vertPos; \n" +
" \n" +
"uniform int mode; \n" +
" \n" +
"const vec3 lightPos = vec3(1.0,1.0,1.0); \n" +
"const vec3 ambientColor = vec3(0.1, 0.0, 0.0); \n" +
"const vec3 diffuseColor = vec3(0.5, 0.0, 0.0); \n" +
"const vec3 specColor = vec3(1.0, 1.0, 1.0); \n" +
" \n" +
"void main() { \n" +
" vec3 normal = normalize(normalInterp); \n" +
" vec3 lightDir = normalize(lightPos - vertPos); \n" +
" vec3 reflectDir = reflect(-lightDir, normal); \n" +
" vec3 viewDir = normalize(-vertPos); \n" +
" \n" +
" float lambertian = max(dot(lightDir,normal), 0.0); \n" +
" float specular = 0.0; \n" +
" \n" +
" if(lambertian > 0.0) { \n" +
" float specAngle = max(dot(reflectDir, viewDir), 0.0); \n" +
" specular = pow(specAngle, 4.0); \n" +
" } \n" +
" gl_FragColor = vec4(ambientColor + \n" +
" lambertian*diffuseColor + \n" +
" specular*specColor, 1.0); \n" +
" \n" +
" // only ambient \n" +
" if(mode == 2) gl_FragColor = vec4(ambientColor, 1.0); \n" +
" // only diffuse \n" +
" if(mode == 3) gl_FragColor = vec4(lambertian*diffuseColor, 1.0); \n" +
" // only specular \n" +
" if(mode == 4) gl_FragColor = vec4(specular*specColor, 1.0); \n" +
" \n" +
"} ";

var newMaterial = ccbCreateMaterial(vertexShader, fragmentShader, 0, null);

var cube = ccbGetSceneNodeFromName('soldier');
ccbSetSceneNodeMaterialProperty(cube, 0, 'Type', newMaterial);
ccbSetSceneNodeMaterialProperty(cube, 1, 'Type', newMaterial);
ccbSetSceneNodeMaterialProperty(cube, 2, 'Type', newMaterial);
ccbSetSceneNodeMaterialProperty(cube, 4, 'Type', newMaterial);
ccbSetSceneNodeMaterialProperty(cube, 5, 'Type', newMaterial);


mrmdesign
Registered User
Quote
2014-10-25 15:25:51

I can not be the only one who wants to see Coppercube able to at least compete with verold or sketchfab in the webgl shader department.
Sketchfab will have PBR soon as will Unity.

Please, please can you at least create a few better default shaders for webgl Niko? Even if it is just some more examples to follow.
This is your engine and you know it inside out. Surely nobody can create better examples than you.

I really need a normal map shader with specular map support.

Also, will coppercube get dynamic shadows some time soon?

I know you have done a lot of work in other areas but a lot of other WebGL export options have caught up and surpassed Coppercube in terms of visual performance. What Blend4Web have done is amazing and their scenes even perform well on IOS


karmacomposer
Registered User
Quote
2015-02-08 01:58:36

Where do we put these to make them work in a Coppercube scene?

I am interested in cell shading the entire scene, not just one character. How would I do this?

Where do I place the javascript file and shader files?

A brief tutorial would go a LONG way.

Thank you so much for this incredible thread!

Mike


niko
Moderator
Quote
2015-02-08 09:02:27

More advanced shaders are planned, but it might take a while still.


karmacomposer
Registered User
Quote
2015-02-08 15:16:09

wrote:
More advanced shaders are planned, but it might take a while still.


But HOW do you code a full scene shader (like a toon shader) and WHERE do you put it and HOW do you get it working in your scene?

Mike


pmax
Registered User
Quote
2015-02-08 17:01:54

Have you tried this plugin?
link:http://www.ambiera.com/forum.php...
only works on individual objects, not the whole scene.


karmacomposer
Registered User
Quote
2015-02-11 15:02:41

Can anyone just inform me where to put these scripts and how to choose them?

Do they go in /MyDocuments/Coppercube/Extensions?

Do I call them using a scripted behavior -> when Javascript is called . . .

Just a bit of hand holding is all I need. I appreciate it if anyone who knows how to do this would explain it to me so I can test it in a example scene to see if it will work, frame-rate-wise and if it looks any good.

Thank you.

Mike


theneffness
Registered User
Quote
2015-02-11 18:26:52

I am getting a vec3 error. Do you know what the issue is for this?

CopperCube Debug Console
HLSL vertex shader compilation failed:
(1): error X3000: syntax error: unexpected otken 'vec3'

Thanks for any info, I'd really like to play around with this script.


niko
Moderator
Quote
2015-02-12 05:25:55

If you are using D3D as renderer, then you cannot use GLSL shaders (those with vec3). Either use a HLSL shader instead, or set the target to OpenGL.


pmax
Registered User
Quote
2015-02-14 17:32:14

@ karmacomposer

Copy the plugin into the folder "Documenti-> Coppercube-> Extensions".
Start CopperCube load the object specifically for the scene to be created.
Select "New 3D scenes 1" go to the "Behaviour", add the entry "Before drawing first do something" click on "Action", Add new undertake action "Scripted actions-> Assign shaders".
From this point you can go and read how the plugin in his post.
link:http://www.ambiera.com/forum.php...

PS: translation by Google


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact