Jump to content

Toon shading


newaged

Recommended Posts

This resource changes the shading on most objects, making them look like this http://i.imgur.com/slbN28E.png.


Changes:

shaders\common\lighting\advanced\vectorLightP.hlsl, line 203

   float dotNL = dot(-lightDirection, normal); 

to

   float dotNL = clamp(smoothstep(0.4, 0.43, dot(-lightDirection, normal)), 0.2, 1.0); 

 

shaders\common\lighting\advanced\pointLightP.hlsl, line 163

   float nDotL = dot( lightVec, normal ); 

to

    float nDotL = clamp(smoothstep(0.4, 0.43, dot( lightVec, normal )), 0.2, 1.0); 

 

shaders\common\lighting\advanced\spotLightP.hlsl, line 99

   float nDotL = dot( normal, -lightToPxlVec ); 

to

   float nDotL = clamp(smoothstep(0.4, 0.43, dot( normal, -lightToPxlVec )), 0.2, 1.0); 

 

A more difficult to install version that includes object outlines is currently in progress.

http://i.imgur.com/fjN6ebA.png

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 months later...

For the most part, changes in the hlsl shaders you need are (glsl remain the same)


Texture Sampling:

// Old Code
uniform sampler2D textureMap : register(S0);
float4 color = tex2D(textureMap,uv);
//New code
TORQUE_UNIFORM_SAMPLER2D(textureMap,0);
float4 color = TORQUE_TEX2D( textureMap, uv);

 

Pixel Shader targets:

//Old code
COLORn
//New code
TORQUE_TARGETn

 

Semantics (vertex shader output and pixel shader input only. Vertex shader input remains the same as does all other semantic names)

//Old code
POSITION
//New code
TORQUE_POSITION

 

There are a few other things so just ask if you have troubles with any shader conversions.

Link to comment
Share on other sites

Also just beware when using custom shaders, with DX11 it is very, very fussy that the vertex format matches exactly the same as the shader.


E.G


Bad (AppData in the vertex shader doesn't match vertex format):

 

//C++
GFXVertexBufferHandle<GFXVertexPCT> verts;

// Vertex Shader

struct Appdata
{
float3 position   : POSITION;
float4 color      : COLOR;
};

 

Bad(order is incorrect in the vert shader:

 

//C++
GFXVertexBufferHandle<GFXVertexPCT> verts;

//Vertex Shader

struct Appdata
{
float3 position   : POSITION;
float2 texCoord   : TEXCOORD0;
float4 color      : COLOR;
};

 

Good:

 

//C++
GFXVertexBufferHandle<GFXVertexPCT> verts;

//Vertex Shader

struct Appdata
{
float3 position   : POSITION;
float4 color      : COLOR;
float2 texCoord   : TEXCOORD0;
};

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.

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.

×
×
  • Create New...