Toon shading

9 posts Page 1 of 1
newaged
Posts: 31
Joined: Sat Feb 14, 2015 12:27 am
by newaged » Fri Feb 12, 2016 6:23 am
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
Janders
Posts: 45
Joined: Wed Sep 02, 2015 12:41 am
by Janders » Mon Feb 22, 2016 8:15 pm
Looking good! Are there options in the editor, or it works only on code?

Can't wait for the outlines!
Steve_Yorkshire
Posts: 299
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Tue Feb 23, 2016 3:08 am
Here's an old outline shader, incase it helps.
http://yorkshirerifles.com/random/outline_shader.zip
;)
doc
Posts: 17
Joined: Thu Feb 05, 2015 9:14 am
by doc » Thu Feb 25, 2016 11:40 am
Nice! Thank you!
Going to tweak my light attenutation in 3..2..1..
TorqueFan
Posts: 87
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Fri Jul 15, 2016 6:51 pm
Anyone get this working in any of the newer T3D builds under DX11? The shader code is a bit different now.
TorqueFan
Posts: 87
Joined: Thu Apr 30, 2015 5:35 am
  by TorqueFan » Sat Jul 16, 2016 7:03 pm
Ah, nevermind. The one-line change is still relevant - I just didn't search well enough for it the last time! :oops:
Timmy
Posts: 366
Joined: Thu Feb 05, 2015 3:20 am
by Timmy » Sun Jul 17, 2016 1:47 am
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.
TorqueFan
Posts: 87
Joined: Thu Apr 30, 2015 5:35 am
by TorqueFan » Thu Jul 21, 2016 1:46 am
@
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.
Timmy
Posts: 366
Joined: Thu Feb 05, 2015 3:20 am
by Timmy » Thu Jul 21, 2016 4:37 am
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; };
9 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests