ajm000

09-21-2005, 09:35 AM

How do I go about to complete this program? The part I'm confused with is how to compute the 2D lightDepthTex from the float4 dist? Does it go like... the vertex position (x,y,z) is projected to texture space (s,t) then the depth (dist) is stored there? Thanks so much!!!

If you have a better way to do subsurface scattering please tell me. Just not the texture diffusion method (e.g. blur shaders).

DEPTH PASS

//VERTEX PROG

struct a2v {

float4 pos : POSITION;

float3 normal : NORMAL;

}

struct v2f {

float4 hpos : POSITION;

float dist : TEXCOORD0;

}

v2f main(a2v IN,

uniform float4x4 modelViewProj,

uniform float4x4 modelView,

uniform float grow)

{

v2f OUT;

float4 P = IN.pos;

P.xyz += IN.normal * grow;

OUT.hpos = mul(modelViewProj, P);

OUT.dist = length(mul(modelView, IN.pos));

return OUT;

}

//FRAGMENT PROG (SEPARATE FILE)

float4 main(float dist : TEX0) : COLOR

{

return dist;

}

THICKNESS COMPUTATION PASS

float trace(float3 P,

uniform float4x4 lightTexMatrix,

uniform float4x4 lightMatrix,

uniform sampler2D lightDepthTex)

{

float4 texCoord = mul(lightTexMatrix, float4(P, 1.0));

float d_i = tex2Dproj(lightDepthTex, texCoord.xyw);

float4 Plight = mul(lightMatrix, float4(P, 1.0));

float d_o = length(Plight);

float s = d_o - d_i;

return s;

}

If you have a better way to do subsurface scattering please tell me. Just not the texture diffusion method (e.g. blur shaders).

DEPTH PASS

//VERTEX PROG

struct a2v {

float4 pos : POSITION;

float3 normal : NORMAL;

}

struct v2f {

float4 hpos : POSITION;

float dist : TEXCOORD0;

}

v2f main(a2v IN,

uniform float4x4 modelViewProj,

uniform float4x4 modelView,

uniform float grow)

{

v2f OUT;

float4 P = IN.pos;

P.xyz += IN.normal * grow;

OUT.hpos = mul(modelViewProj, P);

OUT.dist = length(mul(modelView, IN.pos));

return OUT;

}

//FRAGMENT PROG (SEPARATE FILE)

float4 main(float dist : TEX0) : COLOR

{

return dist;

}

THICKNESS COMPUTATION PASS

float trace(float3 P,

uniform float4x4 lightTexMatrix,

uniform float4x4 lightMatrix,

uniform sampler2D lightDepthTex)

{

float4 texCoord = mul(lightTexMatrix, float4(P, 1.0));

float d_i = tex2Dproj(lightDepthTex, texCoord.xyw);

float4 Plight = mul(lightMatrix, float4(P, 1.0));

float d_o = length(Plight);

float s = d_o - d_i;

return s;

}