|
|
Re: What about a Relief_Mapping shader...
[Re: Matt_Aufderheide]
#51780
08/14/05 07:56
08/14/05 07:56
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
Serious User
|
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
The parallax code I am currently working on has fair performance on my ATI 9800. That said, I do need to make a full-on level and tweak from there. Relief mapping... well... with the code I have tinkered with I have yet to get good results with good performance. Parallax: 
|
|
|
Re: What about a Relief_Mapping shader...
[Re: XNASorcerer]
#51783
08/14/05 23:18
08/14/05 23:18
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
Serious User
|
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
Thanks guys!
Sorcerer: Give me some time and I can help you. I am real busy right now with my job. The parallax code needs some more work before it gets posted.
Last edited by Steempipe; 08/14/05 23:19.
|
|
|
Re: What about a Relief_Mapping shader...
[Re: XNASorcerer]
#51785
08/17/05 11:38
08/17/05 11:38
|
Joined: Oct 2003
Posts: 4,131
Matt_Aufderheide
Expert
|
Expert
Joined: Oct 2003
Posts: 4,131
|
I have converted that relif mapping shader, and alhtough it does look good, it is just too slow, when you want multiple lights..my parallax shader does 6 lights no problem, the relief shader really bogs down.. although i think this is the next standard(or something like it) it needs another generation of shader hardware before viable for real games.
That said, its a neat thing, and maybe i will release my shader eventually.. also, i can imagine a scheme where you have an LOD fragment shader when only the pixels nearest you use the relief shader, the further ones use parallax, and the most distant would just use normal mapping.. who knows.. it could work.
|
|
|
Re: What about a Relief_Mapping shader...
[Re: ello]
#51787
08/18/05 01:23
08/18/05 01:23
|
Joined: Oct 2003
Posts: 4,131
Matt_Aufderheide
Expert
|
Expert
Joined: Oct 2003
Posts: 4,131
|
here is the basic HLSL code, you may need to chnage some things, but it will work in A6, although there is still aproblem with the perspective.. for some reason things point in the wrong direction.. but this is fixable.. i just havent bothered.. maybe someone can improve this.. Also, i havent implemented any attenuation, but this is simple to do. I commented out the self shadowing...but you can add back in to try it.. it is slow Code:
struct a2v { float4 pos : POSITION; float3 normal : NORMAL; float2 txcoord : TEXCOORD0; float3 tangent : TEXCOORD1; };
struct v2f { float4 hpos : POSITION; float2 txcoord : TEXCOORD0; float3 vpos : TEXCOORD1; float3 tangent : TEXCOORD2; float3 binormal : TEXCOORD3; float3 normal : TEXCOORD4; float4 lightpos : TEXCOORD5; float Fog : FOG; };
// shaders ////////////////////////////
v2f view_space(a2v IN) { v2f OUT;
// compute modelview rotation only part float3x3 modelviewrot; modelviewrot[0]=(matWorldView[0].xyz); modelviewrot[1]=(matWorldView[1].xyz); modelviewrot[2]=(matWorldView[2].xyz);
// vertex position in clip space OUT.hpos=mul(IN.pos,matWorldViewProj);
// vertex position in view space (with model transformations) OUT.vpos=mul(IN.pos,matWorldView).xyz;
// light position in view space OUT.lightpos=mul(vecLightPos,matView);
// tangent space vectors in view space (with model transformations) OUT.tangent=mul(IN.tangent,-modelviewrot); OUT.binormal=mul( (cross(IN.tangent,IN.normal)),modelviewrot); OUT.normal=mul(IN.normal,modelviewrot);
OUT.txcoord=IN.txcoord.xy;
OUT.Fog = 10000;
return OUT; }
float depth_fact= 0.05f;
float ray_intersect_rm( in float2 dp, in float2 ds) { const int linear_search_steps=16; const int binary_search_steps=6; float depth_step=1.0/linear_search_steps;
// current size of search window float size=depth_step; // current depth position float depth=0.0; // best match found (starts with last position 1.0) float best_depth=1.0; // search front to back for first point inside object for( int i=0;i<linear_search_steps-1;i++ ) { depth+=size; float4 t=tex2D(BumpMapSampler,dp+ds*depth); // normalize(t.w/=3); if (best_depth>0.996) // if no depth found yet if (depth>=t.w) best_depth=depth; // store best depth } depth=best_depth; // recurse around first point (depth) for closest match for( int i=0;i<binary_search_steps;i++ ) { size*=0.5; float4 t=tex2D(BumpMapSampler,dp+ds*depth); // normalize(t.w/=3); if (depth>=t.w) { best_depth=depth; depth-=2*size; } depth+=size; }
return best_depth; }
float4 relief_map( v2f IN) : COLOR { float4 t; float3 p,v,l,s;//c; float4 c;//c; float2 dp,ds,uv; float d;
// ray intersect in view direction p = IN.vpos; v = normalize(p);
if (IN.binormal.x<0 ) { IN.binormal.x*=-1; } if (IN.binormal.y<0 ) { IN.binormal.y*=-1; } if (IN.binormal.z<0 ) { IN.binormal.z*=-1; } s = normalize(float3(dot(v,IN.tangent),dot(v,IN.binormal),dot(v,IN.normal))); s *= depth_fact*0.2/dot(IN.normal,-v); dp = IN.txcoord; ds = s.xy; d = ray_intersect_rm(dp,ds); // get rm and color texture points uv=dp+ds*d; t=tex2D(BumpMapSampler,uv); normalize(t); c=tex2D(ColorMapSampler,uv);
// expand normal from normal map in local polygon space t.xy=t.xy*2.0-1.0; t.z=sqrt(1.0-dot(t.xy,t.xy)); t.xyz=normalize(t.x*IN.tangent-t.y*IN.binormal+t.z*IN.normal);
// compute light direction p += s*d; l=normalize(p-IN.lightpos.xyz); /* ///////////// //selfshadowing--slow and doesnt look good in some cases // ray intersect in light direction dp+= ds*d; s = normalize(float3(dot(l,IN.tangent),dot(l,IN.binormal),dot(l,IN.normal))); s *= depth_fact*0.2/dot(IN.normal,-l); dp-= d*s.xy; ds = s.xy; float dl = ray_intersect_rm(dp,s.xy); if (dl<d-0.05) // if pixel in shadow { c*=0.4; c.w=0; } /////////////// */ // compute diffuse and specular terms float att=saturate(dot(-l,IN.normal.xyz)); float diff=saturate(dot(-l,t.xyz)); float spec=saturate(dot(normalize(-l-v),t.xyz));
// compute final color float4 finalcolor; finalcolor.xyz=att*(c*diff+1*(pow(spec,30)*c.w)); finalcolor.w=1.0;
return finalcolor; }
|
|
|
|