Jump to content

Is cel shading supported?


yorke
 Share

Recommended Posts

Hi all. I'd like to know if BJS supports cel (toon) shading? Didn't find anything about that.

My scene is exported from Blender, the goal would be to apply cel shading on all meshes. Lurking the code i saw that there's a mesh.convertToFlatShadedMesh() function, but nothing similar about cel shading. Any ideas?

Tnx, cheers

Link to comment
Share on other sites

Many tnx for your link adam. Shader's code is clear, but it's not clear to me how to apply the shader on materials exported form blender. If I apply this code:

        var amigaMaterial = new BABYLON.ShaderMaterial(...custom vertex and pixel shader )
        scene.materials[n] = amigaMaterial;
every material in the scene would be overwitten (I think), so it would loose what i've defined in blender for that material (texture, diffuseColor etc).
On the opposite, I'd like every material to preserve its original properties and change only the shader. Is it possible to achieve this in some way or I have to create every time a new ShaderMaterial and "manually" append the properties from the original material to it?
Tnx in advance
Link to comment
Share on other sites

Couldn't you just run a function for every mesh that needs the cell shader, and do something like:


      mesh.material.subMaterials[1] = createCellShader(mesh.material.subMaterials[1]);

      var createCellShader = function(material){
      var cMaterial = new BABYLON.ShaderMaterial(...custom vertex and pixel shader );
      if(material){
         if(material.diffuseColor){
            cMaterial.diffuseColor = material.diffuseColor; 
         } 
         if(material.diffuseTexture){
            cMaterial.diffuseTexture = material.diffuseTexture; 
         }    
      }
         return cMaterial;    

      }

Or did you have something else in mind?

 

 

Link to comment
Share on other sites

Up. I tried to mix cel shader from the link posted by adam with raggar's code but meshes are now rendered totally black, here is what I did:

<script type="application/vertexShader" id="vertexShaderCode">

[...]

<script type="application/fragmentShader" id="fragmentShaderCode">

[...]


mesh.material.subMaterials[0]=createCellShader(mesh.material.subMaterials[0].clone("CLONEMAT"),scene);

[...]

function createCellShader (material,scene)
{
      var cMaterial = new BABYLON.ShaderMaterial
      (
            "amiga", scene,
        {
            vertexElement: "vertexShaderCode",
            fragmentElement: "fragmentShaderCode",
        },
        {
            attributes: ["position", "normal", "uv"],
            uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"]            
        }            
      );

      if(material)
      {
         if(material.diffuseColor)
            cMaterial.diffuseColor = material.diffuseColor;

         if(material.diffuseTexture)
            cMaterial.diffuseTexture = material.diffuseTexture;
      }

      return cMaterial;    
}

Any ideas? I also tried to change light position in shaders but nothing changed. I don't know how to investigate this

Link to comment
Share on other sites

I haven't had the pleasure to play with the shaderMaterial yet, si I really can't tell.

Can you manually apply the texture and color to the shader, without the black effect?

And I don't think cloning of materials is supported. You'll have to create a new material, using something along the lines of the same function you are using now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...