Page 1 of 1

Toon shading

Posted: Fri Feb 12, 2016 6:23 am
by newaged
This resource changes the shading on most objects, making them look like this Image.

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

Code: Select all

float dotNL = dot(-lightDirection, normal);
to

Code: Select all

float dotNL = clamp(smoothstep(0.4, 0.43, dot(-lightDirection, normal)), 0.2, 1.0);
shaders\common\lighting\advanced\pointLightP.hlsl, line 163

Code: Select all

float nDotL = dot( lightVec, normal );
to

Code: Select all

float nDotL = clamp(smoothstep(0.4, 0.43, dot( lightVec, normal )), 0.2, 1.0);
shaders\common\lighting\advanced\spotLightP.hlsl, line 99

Code: Select all

float nDotL = dot( normal, -lightToPxlVec );
to

Code: Select all

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.
Image

Re: Toon shading

Posted: Mon Feb 22, 2016 8:15 pm
by Janders
Looking good! Are there options in the editor, or it works only on code?

Can't wait for the outlines!

Re: Toon shading

Posted: Tue Feb 23, 2016 3:08 am
by Steve_Yorkshire
Here's an old outline shader, incase it helps.
http://yorkshirerifles.com/random/outline_shader.zip
;)

Re: Toon shading

Posted: Thu Feb 25, 2016 11:40 am
by doc
Nice! Thank you!
Going to tweak my light attenutation in 3..2..1..

Re: Toon shading

Posted: Fri Jul 15, 2016 6:51 pm
by TorqueFan
Anyone get this working in any of the newer T3D builds under DX11? The shader code is a bit different now.

Re: Toon shading

Posted: Sat Jul 16, 2016 7:03 pm
by TorqueFan
Ah, nevermind. The one-line change is still relevant - I just didn't search well enough for it the last time! :oops:

Re: Toon shading

Posted: Sun Jul 17, 2016 1:47 am
by Timmy
For the most part, changes in the hlsl shaders you need are (glsl remain the same)

Texture Sampling:

Code: Select all

// 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:

Code: Select all

//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)

Code: Select all

//Old code POSITION //New code TORQUE_POSITION
There are a few other things so just ask if you have troubles with any shader conversions.

Re: Toon shading

Posted: Thu Jul 21, 2016 1:46 am
by TorqueFan
@
User avatar
Timmy
- Nice, thanks. Will be converting a class I based off of ScatterSky soon, and if I run into trouble I'll post about it. The class did pass some new shader values around.

Re: Toon shading

Posted: Thu Jul 21, 2016 4:37 am
by Timmy
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):

Code: Select all

//C++ GFXVertexBufferHandle<GFXVertexPCT> verts; // Vertex Shader struct Appdata { float3 position : POSITION; float4 color : COLOR; };
Bad(order is incorrect in the vert shader:

Code: Select all

//C++ GFXVertexBufferHandle<GFXVertexPCT> verts; //Vertex Shader struct Appdata { float3 position : POSITION; float2 texCoord : TEXCOORD0; float4 color : COLOR; };
Good:

Code: Select all

//C++ GFXVertexBufferHandle<GFXVertexPCT> verts; //Vertex Shader struct Appdata { float3 position : POSITION; float4 color : COLOR; float2 texCoord : TEXCOORD0; };