Hi-Pass Fur Shader - No Fuzz! (almost)

Posted By: Bright

Hi-Pass Fur Shader - No Fuzz! (almost) - 08/27/07 11:31

Hi there,
I'm new to the whole shader scene but I managed to hack and slice a fur shader I found with a Massive Shader Collection. I've added more passes to get rid of that anoying fuzz effect. It looks really nice however it is a major drop on performence so I don't think it would be much use to you guys. But maybe another couple of years down the track it'll be handy

Heres a screenshot:


To run the shader you will need a TGA image of noise (any size, I use 256x256). Save it as noise.tga.

Example:


Heres the script (orignal script by PHeMoX).
Save the following into a fur.fx file:
Code:

float4x4 matWorldViewProj;

void mainVS
(
in float4 position:POSITION,
in float4 normal:NORMAL,
in float2 texCoord:TEXCOORD0,
out float4 pos:POSITION,
out float2 oT0:TEXCOORD0,
uniform float offset
)
{
position.xyz+=normal.xyz*offset;
//scale vertexposition in normals direction
//changing the 100 value changes the 'distance' or height of the fur

pos=mul(position,matWorldViewProj);
oT0=texCoord*1; //scale for fur density 14--->original comment
//this is the amount of tiling of the fur texture
}

//Define the material skins which we use;
texture entSkin1;
sampler basemap = sampler_state
{
texture=(entSkin1);
};

texture mtlSkin1;
sampler noiseMap=sampler_state
{
texture=(mtlSkin1);
};

texture mtlSkin2;
sampler furmap = sampler_state
{
texture=(mtlSkin2);
};

// Next the main pixel shader (can't explain much on it though)
float4 mainPS
(
in float4 nrm:COLOR0,
in float2 texCoord:TEXCOORD0,
uniform float alpha
) : COLOR
{
float4 base=tex2D(basemap,texCoord); //mtlskin1 sampler
float4 fur=tex2D(furmap,texCoord); //mtlskin2 sampler
float4 noise=tex2D(noiseMap,texCoord);
base *= fur; //this is for color fur
base.a=alpha*noise.rgb; //this is for making it transparent using the noisemap as for, 'how much and where' transparency should be(???)
return base;
}

// Through these passes, the amount of fur-layers are determined, the more passes, the less fps (and even a changing effect, too much contrast)
technique test1
{
pass p0
{
alphablendenable=true;

VertexShader=compile vs_1_1 mainVS(0);
PixelShader=compile ps_1_4 mainPS(1);
}

//fur part:
pass p1
{
AlphaBlendEnable=true;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.1); //the last numbers gives the height of the layer
PixelShader=compile ps_1_4 mainPS(0.9); //the last numbers sets the transparency of this pass
}

pass p2
{
AlphaBlendEnable=true;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.2);
PixelShader=compile ps_1_4 mainPS(0.9);
}

pass p3
{
AlphaBlendEnable=true;
destBlend=13; //7/9

VertexShader=compile vs_1_1 mainVS(0.3);
PixelShader=compile ps_1_4 mainPS(0.9);
}

pass p4
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.4);
PixelShader=compile ps_1_4 mainPS(0.8);
}

pass p5
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.5);
PixelShader=compile ps_1_4 mainPS(0.7);
}

pass p6
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.6);
PixelShader=compile ps_1_4 mainPS(0.6);
}

pass p7
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.7);
PixelShader=compile ps_1_4 mainPS(0.5);
}

pass p8
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.8);
PixelShader=compile ps_1_4 mainPS(0.4);
}

pass p9
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(0.9);
PixelShader=compile ps_1_4 mainPS(0.4);
}

pass p10
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1);
PixelShader=compile ps_1_4 mainPS(0.4);
}

pass p11
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.1);
PixelShader=compile ps_1_4 mainPS(0.4);
}
pass p12
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.2);
PixelShader=compile ps_1_4 mainPS(0.4);
}
pass p13
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.3);
PixelShader=compile ps_1_4 mainPS(0.3);
}
pass p14
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.4);
PixelShader=compile ps_1_4 mainPS(0.3);
}
pass p15
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.5);
PixelShader=compile ps_1_4 mainPS(0.3);
}
pass p16
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.6);
PixelShader=compile ps_1_4 mainPS(0.2);
}
pass p17
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.7);
PixelShader=compile ps_1_4 mainPS(0.2);
}
pass p18
{
AlphaBlendEnable=true;
zWriteEnable = True;
destBlend=13;

VertexShader=compile vs_1_1 mainVS(1.8);
PixelShader=compile ps_1_4 mainPS(0.1);
}
}



Add this to your script:

Code:

// call local images
bmap noise_bmap = <noise.tga>;
bmap color_bmap = <noise.tga>;

material mtl_fur
{
skin1 = noise_bmap;
skin2 = color_bmap;

effect = "fur.fx";
}



Should work. If there are any problems let me know and I'll try my best to help you out

Cheers
-Bright
Posted By: Uhrwerk

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 08/27/07 11:38

It looks good, I can't deny that. But 18 passes for a single object..?! Maybe 17 will do the trick too...
Posted By: Scorpion

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 08/27/07 13:18

can u please make the hairs longer?
Posted By: Mondivirtuali

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 08/27/07 14:21

awesome, i'll try it
Posted By: frazzle

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 08/28/07 09:27

Nice effort but the more passes, the more instruction slots you use which leads into a decreasing framerate like you mentioned. This is also partly caused because when using one technique and several passes, the technique encapsulates the effect state that determines a rendering style. A technique is made up of one or more passes. An effect file that uses one technique and multiple passes like yours, has result that one pass depends on the result of the previous pass so you get a fps decrease. Anyway, nice work

Cheers

Frazzle
Posted By: Matt_Aufderheide

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 08/28/07 19:14

Quote:

the more passes, the more instruction slots you use which leads into a decreasing framerate like you mentioned. This is also partly caused because when using one technique and several passes, the technique encapsulates the effect state that determines a rendering style. A technique is made up of one or more passes. An effect file that uses one technique and multiple passes like yours, has result that one pass depends on the result of the previous pass so you get a fps decrease.




This explanation leaves something to be desired..

The basic reason multipass shaders like this are slow (aside from the mulitple draw calls and polygon transforms) is the excessive overdraw.

Think about it, each pixel in the effect has to be redrawn at least 18 times, often more.
Posted By: frazzle

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 08/28/07 20:30

Quote:


This explanation leaves something to be desired..





Well it may leave something to be desired but it makes sense.
You said the following:

Quote:


Think about it, each pixel in the effect has to be redrawn at least 18 times, often more.





In theory, this replicates my explanation.
Btw I love reading your comments Matt, they have a satire style but helpful at the same time

Cheers

Frazzle
Posted By: Nowherebrain

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 08/28/07 23:12

"maybe 17 will do the trick"...funny.
Posted By: mohsen123

Re: Hi-Pass Fur Shader - No Fuzz! (almost) - 09/13/07 03:12

hi
thank you .
but . where can i use your material code ?
whene i save .fx file and .tga file and past material script in my proje i see :
http://i5.tinypic.com/4md6rkx.jpg
thank you.

© 2023 lite-C Forums