Cel shading in Neoaxis1.0



Users browsing this forum: No registered users and 2 guests

Next topic
Previous topic
Post new topic Reply to topic  NeoAxis Forum Index » General » General Discussion
Search for:
Author Message
Unlimited License
Unlimited License

Joined: Sun Sep 11, 2011
Posts: 29
Country: Japan (jp)
PostPosted: Sun Sep 11, 2011 1:12 am Post subject: Cel shading in Neoaxis1.0
Bottom of Page Back to top
Hi.

How can the cel shading material be found in NeoAxis1.0?
Isn't there means to achieve the cel shading?
I retrieved the log of the forum.
However, the cel shading material seemed to have only a past version in me.

Thanks.

 
 Profile  
Administrator
Administrator
User avatar

Joined: Wed Oct 11, 2006
Posts: 5059
Location: Kazan
Country: Russia (ru)
PostPosted: Sun Sep 11, 2011 9:03 am 
Bottom of Page Back to top
Hi,

No Cel-shading support in SDK.
You can add it.

You can look shader code from Ogre Demo:
http://cft3.igromania.ru/upload/article ... e_cell.jpg

Cel shading can be divided to three tasks:

1. change color of lighting in the pixel shader
Need to change Data\Materials\Common\ShaderBase.cg_hlsl
You can Ogre cel shading demo. Check out \Samples\Media\materials\programs\Example_CelShading.cg from Ogre SDK.
Code: Select all   Expand view

/* Cel shading vertex program for single-pass rendering
   In this program, we want to calculate the diffuse and specular
   ramp components, and the edge factor (for doing simple outlining)
   For the outlining to look good, we need a pretty well curved model.
*/
void main_vp(float4 position   : POSITION,
          float3 normal      : NORMAL,
          // outputs
          out float4 oPosition : POSITION,
          out float  diffuse       : TEXCOORD0,
          out float  specular    : TEXCOORD1,
          out float  edge       : TEXCOORD2,
          // parameters
          uniform float3 lightPosition, // object space
          uniform float3 eyePosition,   // object space
          uniform float4  shininess,
          uniform float4x4 worldViewProj)
{
   // calculate output position
   oPosition = mul(worldViewProj, position);

   // calculate light vector
   float3 N = normalize(normal);
   float3 L = normalize(lightPosition - position.xyz);
   
   // Calculate diffuse component
   diffuse = max(dot(N, L) , 0);

   // Calculate specular component
   float3 E = normalize(eyePosition - position.xyz);
   float3 H = normalize(L + E);
   specular = pow(max(dot(N, H), 0), shininess);
   // Mask off specular if diffuse is 0
   if (diffuse == 0) specular = 0;

   // Edge detection, dot eye and normal vectors
   edge = max(dot(N, E), 0);
}

void main_fp(float diffuseIn    : TEXCOORD0,
          float specularIn   : TEXCOORD1,
          float edge      : TEXCOORD2,
         
          out float4 colour   : COLOR,
         
          uniform float4 diffuse,
          uniform float4 specular,
         
          uniform sampler1D diffuseRamp,
          uniform sampler1D specularRamp,
          uniform sampler1D edgeRamp)
{
   // Step functions from textures
   diffuseIn = tex1D(diffuseRamp, diffuseIn).x;
   specularIn = tex1D(specularRamp, specularIn).x;
   edge = tex1D(edgeRamp, edge).x;

   colour = edge * ((diffuse * diffuseIn) +
               (specular * specularIn));
}


2. Detect edges
Usually need highlight edges. You can see simple implementation of edge detection in ogre example.
Exists many advanced edge detection techniques.

3. Post effect
Post effects also can be used for cel shading rendering.

_________________
Founder, lead developer of NeoAxis Group Ltd.
News on Twitter, Google+, Facebook, VK
 
 Profile  
Administrator
Administrator
User avatar

Joined: Wed Oct 11, 2006
Posts: 5059
Location: Kazan
Country: Russia (ru)
PostPosted: Sun Sep 11, 2011 9:14 am 
Bottom of Page Back to top
_________________
Founder, lead developer of NeoAxis Group Ltd.
News on Twitter, Google+, Facebook, VK
 
 Profile  
Unlimited License
Unlimited License

Joined: Sun Sep 11, 2011
Posts: 29
Country: Japan (jp)
PostPosted: Mon Sep 12, 2011 9:40 am 
Bottom of Page Back to top
Quote:
Thank you for the reply.
I examined the ShaderBase shader (and the ShaderBaseMaterial class) according to advice.
I thought the method of inserting "#ifdef CEL" in main_vp and main_fp.
Is this idea correct?

This is good. You can add "bool CelShading" property to the class.

Quote:
However, I did not understood the CreateDefaultTechnique method of the ShaderBaseMaterial class.
I will make the class that succeeds to ShaderBaseMaterial.
I want to add vp and fp of the edge drawing.
How should I change the CreateDefaultTechnique method?
(The tutorial of the addition of the posteffect was found.
Isn't there tutorial of the material shader addition?)

No need new class.
I think better add code to the ShaderBaseMaterial class.
- Add property "bool CelShading"
- Specify #define CEL into CreateDefaultTechnique() when property is true.

 
 Profile  
Unlimited License
Unlimited License

Joined: Sun Sep 11, 2011
Posts: 29
Country: Japan (jp)
PostPosted: Tue Sep 13, 2011 9:28 am 
Bottom of Page Back to top
Hi betauser.

It is thought that one technique pass is necessary for the edge drawing.
That is, it is necessary to increase pass in the CreateDefaultTechnique method of the ShaderBaseMaterial class.

//for Shader Model 2 or for stencil shadows
//pass 0: ambient pass
//pass 1: directional light
//pass 2: point light
//pass 3: spot light
//pass 4: edge draw (new!!)

//for Shader Model 3
//pass 0: ambient pass
//pass 1: ambient pass + first directional light
//pass 2: directional light (ignore first directional light)
//pass 3: point light
//pass 4: spot light
//pass 5: edge draw (new!!)

Is this correct?

 
 Profile  
Administrator
Administrator
User avatar

Joined: Wed Oct 11, 2006
Posts: 5059
Location: Kazan
Country: Russia (ru)
PostPosted: Tue Sep 13, 2011 9:56 am 
Bottom of Page Back to top
Hi,

Maybe. Please tell what technique you want to implement. Maybe papers?
As example in the Ogre Demo available easy implementation.

By the way, since NeoAxis 1.1 (which planned soon) we will add access to depth buffer from pixel shaders.
This is useful feature when you need access to depth of scene.
As i know some edge detection techniques uses depth buffer.

_________________
Founder, lead developer of NeoAxis Group Ltd.
News on Twitter, Google+, Facebook, VK
 
 Profile  
Unlimited License
Unlimited License

Joined: Sun Sep 11, 2011
Posts: 29
Country: Japan (jp)
PostPosted: Tue Sep 13, 2011 10:50 am 
Bottom of Page Back to top
Hi betauser.

I want to implement the technique of the cel shading and the edge drawing.
It gives examples. Exactly, it is the same one as the website that you taught.
It is an output that is more beautiful than the sample of Ogre Demo.
http://www.cadrick.com/2011/05/shader-t ... ing-2.html
And..I want to make to an individual property of the edge drawing and the cel shading, and to enable either only one use.
(The edge drawing and the cel shading are used at the same time usually. )

I look forward to the new features included of NeoAxis1.1.
It will become easy to implement various shaders from the new features included.

 
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  NeoAxis Forum Index » General » General Discussion

Jump to:  

Next topic
Previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


All times are UTC




Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group