I'm trying to apply a cel or toon effect to an image. I got the HLSL effect from
http://rbwhitaker.wikidot.com/toon-shader[
^].
The thing is, when I'm compiling the effect using SharpDX Toolkit I'm having two error types. I'm trying to compile with net40 SharpDXToolkit, use following instruction.
C:\Projects\SharpDXBin\Bin\DirectX11_1-net40>tkfxc.exe /ICToon.tkfxo ToonColore
d.fx
Errors are:
1. Converting float3 to float4. (type casting worked once)
2. X4502: invalid ps_4_0_level_9_1 output semantic 'COLOR0'
Here's the code.
float4x4 World;
float4x4 View;
float4x4 Projection;
float4x4 WorldInverseTranspose;
float3 DiffuseLightDirection = float3(1, 0, 0);
float4 DiffuseColor = float4(1, 1, 1, 1);
float DiffuseIntensity = 1.0;
float4 LineColor = float4(0, 0, 0, 1);
float LineThickness = .03;
struct AppToVertex
{
float4 Position : POSITION0; float3 Normal : NORMAL0; float4 Color : COLOR0; };
struct VertexToPixel
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float3 Normal : TEXCOORD1;
};
VertexToPixel CelVertexShader(AppToVertex input)
{
VertexToPixel output;
float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
output.Normal = normalize(mul(input.Normal, (float3x3)WorldInverseTranspose));
output.Color = input.Color;
return output;
}
float4 CelPixelShader(VertexToPixel input) : COLOR0
{
float intensity = dot(normalize(DiffuseLightDirection), input.Normal);
if(intensity < 0)
intensity = 0;
float4 color = input.Color * DiffuseColor * DiffuseIntensity;
color.a = 1;
if (intensity > 0.95)
color = float4(1.0,1,1,1.0) * color;
else if (intensity > 0.5)
color = float4(0.7,0.7,0.7,1.0) * color;
else if (intensity > 0.05)
color = float4(0.35,0.35,0.35,1.0) * color;
else
color = float4(0.1,0.1,0.1,1.0) * color;
return color;
}
VertexToPixel OutlineVertexShader(AppToVertex input)
{
VertexToPixel output = (VertexToPixel)0;
float4 original = mul(mul(mul(input.Position, World), View), Projection);
float4 normal = mul(mul(normalize(mul(float4(input.Normal.xyz, 0),World)), View), Projection);
output.Position = original + (mul(LineThickness, normal));
return output;
}
float4 OutlinePixelShader(VertexToPixel input) : COLOR0
{
return LineColor;
}
technique Toon
{
pass Pass1
{
VertexShader = compile vs_2_0 OutlineVertexShader();
PixelShader = compile ps_2_0 OutlinePixelShader();
CullMode = CW;
}
pass Pass2
{
VertexShader = compile vs_2_0 CelVertexShader();
PixelShader = compile ps_2_0 CelPixelShader();
CullMode = CCW;
}
}
I've changed these lines from the original one:
output.Normal = normalize(mul(input.Normal, WorldInverseTranspose));
float4 normal = mul(mul(mul(input.Normal, World), View), Projection);
for these others, just to try a sucessfull compilation:
output.Normal = normalize(mul(input.Normal, (float3x3)WorldInverseTranspose));
float4 normal = mul(mul(normalize(mul(float4(input.Normal.xyz, 0),World)), View), Projection);
Compiler throw these errors:
SharpDX Toolkit Effect Compiler - 2.5.0.0
Copyright © 2010-2013 Alexandre Mutel
Compile Effect File [C:\Projects\SharpDXBin\Bin\DirectX11_1-net40\ToonColored.f
x]
Error when compiling file [ToonColored.fx]:
error X4541: vertex shader must minimally write all four components of SV_Positi
on
C:\\Projects\\SharpDXBin\\Bin\\DirectX11_1-net40\\ToonColored.fx(124,51-58): er
ror X4502: invalid ps_4_0_level_9_1 output semantic 'COLOR0'
error X4541: vertex shader must minimally write all four components of SV_Positi
on
C:\\Projects\\SharpDXBin\\Bin\\DirectX11_1-net40\\ToonColored.fx(77,47-54): err
or X4502: invalid ps_4_0_level_9_1 output semantic 'COLOR0'
But now I'm stuck, any help would be appreciated.