HLSL高级应用实例

   废话少说,直接入题。

先给出整个应用程序构架:

Code

HLSL代码如下:

HLSL

这是默认的效果,效果图如下:

 

负片效果:

1float4 PSfun(PSInput input) : COLOR0
2{
3    //负片效果
4    return(1- float4(color*AmbientColor) );
5}

模糊效果:

 1float4 PSfun(PSInput input) : COLOR0
 2{
 3    //模糊效果
 4    float4 color = float4( tex2D( TextureSampler,float2(input.texcoord.x+0.0025, input.texcoord.y+0.025))*AmbientColor);
 5    color += tex2D( TextureSampler,float2(input.texcoord.x-0.025, input.texcoord.y-0.025));
 6    color += tex2D( TextureSampler,float2(input.texcoord.x+0.025, input.texcoord.y-0.025));
 7    color += tex2D( TextureSampler,float2(input.texcoord.x-0.025, input.texcoord.y+0.025));
 8    color = color / 4;
 9    return( color );
10}

 

浮雕效果:

 1float4 PSfun(PSInput input) : COLOR0
 2{
 3    //浮雕
 4    float sharpAmount = 15.0f;
 5    float4 color;
 6    color.rgb = 0.5f;
 7    color.a = 1.0f;
 8    color -= float4( tex2D( TextureSampler, input.texcoord - 0.0001* sharpAmount*AmbientColor);
 9    color += float4( tex2D( TextureSampler, input.texcoord + 0.0001* sharpAmount*AmbientColor);
10    color = (color.r+color.g+color.b) / 3.0f;
11    return( color );
12}

Grayscale:

 1float4 PSfun(PSInput input) : COLOR0
 2{
 3    //Grayscale
 4    float4 color =float4(tex2D(TextureSampler, input.texcoord)*AmbientColor);
 5    float4 gs = dot(color.rgb, float3(0.30.590.11));
 6    if (input.texcoord.x > 0.5f)
 7        color = lerp(gs, color, (1 - input.texcoord.x) * 2);
 8    else
 9        color = lerp(gs, color, input.texcoord.x * 2);
10    return( color );
11}

 

粉笔效果:

1float4 PSfun(PSInput input) : COLOR0
2{
3    //粉笔
4    float sharpAmount = 100.0f;
5    float4 color = float4(tex2D(TextureSampler, input.texcoord)*AmbientColor);
6    color += tex2D( TextureSampler, input.texcoord - 0.001* sharpAmount;
7    color -= tex2D( TextureSampler, input.texcoord + 0.001* sharpAmount;
8    return( color );
9}

波动效果:

1float4 PSfun(PSInput input) : COLOR0
2{
3    //动的
4    float y = input.texcoord.y;
5    float x = input.texcoord.x;
6    y = y + (sin(x*100)*0.01);
7    float4 color = float4(tex2D(TextureSampler, float2(x,y))*AmbientColor);
8    return( color );
9}

posted @ 2008-09-24 00:26  齐.net  阅读(2871)  评论(0编辑  收藏  举报