Hi.
I'd like to use your shader in my project, but my project is in DX9 so I need the HLSL version.
I have no idea of shader language but I intend to convert by my self.
Code: Select all
// antialiasing pixel shader
// HLSL version
// Original GLSL version Author:Stefbuet
//this shader is doing an edge detection with depth and normal map
//then it blur edges with a more or less good quelity filter (user selected)
sampler2D depthMap: register(s0) ;
sampler2D renderMap: register(s1) ;
float4 textureCoord;
float2 offsetArray[8];
float4 pixelMain(): COLOR0
{
float2 textCoord=textureCoord.xy;
textCoord.x*=-1.0;
float currentDepth=tex2D(depthMap, -textCoord).w;
float3 normal=tex2D(depthMap, -textCoord).xyz*2.0-float3(1.0,1.0,1.0);
offsetArray[0] = float2(1.0/SCREENX, 1.0/SCREENY);
offsetArray[1] = float2(1.0/SCREENX, 0.0);
offsetArray[2] = float2(1.0/SCREENX, -1.0/SCREENY);
offsetArray[3] = float2(0.0, 1.0/SCREENY);
offsetArray[4] = float2(0.0, -1.0/SCREENY);
offsetArray[5] = float2(-1.0/SCREENX, 1.0/SCREENY);
offsetArray[6] = float2(-1.0/SCREENX, 0.0);
offsetArray[7] = float2(-1.0/SCREENX, -1.0/SCREENY);
//depth
float depthDif=0.0;
float minD=0.005;
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[0]).w-currentDepth));
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[1]).w-currentDepth));
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[2]).w-currentDepth));
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[3]).w-currentDepth));
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[4]).w-currentDepth));
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[5]).w-currentDepth));
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[6]).w-currentDepth));
depthDif+=min(minD,abs(tex2D(depthMap, -textCoord+offsetArray[7]).w-currentDepth));
depthDif/=(1.0+5.0*currentDepth);
if(depthDif<0.01) depthDif=0;
depthDif*=25.0;
depthDif=min(1.0, depthDif);
depthDif=sin(depthDif*2.0);
//normals
float t=1-abs(dot(normal, tex2D(depthMap, -textureCoord.xy+offsetArray[0]).xyz*2.0-float3(1.0,1.0,1.0)));
t+=1-abs(dot(normal, tex2D(depthMap, -textCoord+offsetArray[1]).xyz*2.0-float3(1.0,1.0,1.0)));
t+=1-abs(dot(normal, tex2D(depthMap, -textCoord+offsetArray[2]).xyz*2.0-float3(1.0,1.0,1.0)));
t+=1-abs(dot(normal, tex2D(depthMap, -textCoord+offsetArray[3]).xyz*2.0-float3(1.0,1.0,1.0)));
t+=1-abs(dot(normal, tex2D(depthMap, -textCoord+offsetArray[4]).xyz*2.0-float3(1.0,1.0,1.0)));
t+=1-abs(dot(normal, tex2D(depthMap, -textCoord+offsetArray[5]).xyz*2.0-float3(1.0,1.0,1.0)));
t+=1-abs(dot(normal, tex2D(depthMap, -textCoord+offsetArray[6]).xyz*2.0-float3(1.0,1.0,1.0)));
t+=1-abs(dot(normal, tex2D(depthMap, -textCoord+offsetArray[7]).xyz*2.0-float3(1.0,1.0,1.0)));
t/=15.0;
t/=(1.0+2.5*currentDepth);
if(t<0.16) t=0.0;
t=sin(t*3.74);
depthDif+=t;
if(depthDif>0.2) {
float4 finalColor=tex2D(renderMap, -textCoord.xy);
for(int i=0; i<8; i++)
finalColor+=tex2D(renderMap, -textCoord.xy+offsetArray[i]);
finalColor/=8.0;
return finalColor;
}
else {
return tex2D(renderMap, -textCoord);
}
}
It compiles without errors, but for sure it does not work at all.
Could you, please, help me?
I apologize for my poor English, but it doesn't my mother language.
Regards.