3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Wiki Grass Shader Problem
#55760
09/21/05 11:39
09/21/05 11:39
|
Joined: Sep 2005
Posts: 274 Switzerland - Zurich
zwecklos
OP
Member
|
OP
Member
Joined: Sep 2005
Posts: 274
Switzerland - Zurich
|
Hi @all Ich versuche den grass shader von wiki zum laufen zu bringen. Ich weiss das es probleme mit der directX version gibt. Meîne Frage ist, auf was muss ich achten wenn ich diesen script für dx9c/6.3 portieren will? Egal was ich versuche ich bekomm immer folgende fehlermeldung: Kann mir jemmand sagen was genau diese fehlermeldung bedeutet? hier noch mein script: Code:
bind <grass.fx>;
bmap grass = <grass02.tga>;
function makemips { bmap_to_mipmap(mtl.Skin1);
}
material mat_grass { Skin1 = grass; event = makemips; }
Action grass_wave { effect_load(mat_grass, "grass.fx"); wait(1); my.material = mat_grass; }
fx code: Code:
texture entSkin1;
matrix matWorldViewProj; matrix matWorldView;
vector vecFog; vector vecTime;
technique grass { pass p0 { texture[0]=<entSkin1>; zWriteEnable=true; alphaTestEnable=true; cullMode=none;
vertexShaderConstant[0]=<matWorldViewProj>; vertexShaderConstant[8]=<matWorldView>; vertexShaderConstant[16]=<vecFog>; vertexShaderConstant[32]=<vecTime>; vertexShaderConstant[33]=(0.0f,0.5f,1.0f,2.0f); // common constants vertexShaderConstant[34]=(-0.16161616f,0.0083333f,-0.00019841f,0.000002755731f);// (-1/3!,1/5!,-1/7!,1/9!) vertexShaderConstant[35]=(4.0f,1.57079632f,3.14159265f,6.28318530f); // (4.0,pi/2,pi,pi*2) vertexShaderConstant[36]=(1.07f,0.0f,0.0f,0.0f); // fixup factor
vertexShaderConstant[40]=(2.5f,1.0f,0.5f,0.1f); // wave distort x vertexShaderConstant[41]=(5.0f,0.5f,0.25f,0.1f); // wave distort y vertexShaderConstant[42]=(-1.0f,-0.01f,-0.04f,-0.01f); // wave distort z vertexShaderConstant[43]=(-0.1f,-0.2f,0.1f,0.05f); // wave dir x vertexShaderConstant[44]=(-0.005f,-0.01f,-0.005f,-0.0025f); // wave dir y vertexShaderConstant[45]=(0.02f,0.04f,0.05f,0.1f); // wave speed vertexShaderConstant[46]=(0.35f,0.1f,0.1f,0.04f); // lighting wave scale vertexShaderConstant[47]=(0.6f,0.8f,0.3f,0.0f); // lighting scale bias
vertexShader= decl { stream 0; float v0[3]; //position float v3[3]; //normal float v7[2]; //uv }
asm { vs.1.1
mov r1.w,c16.w // r1.w=1 dp4 r0,v0,c10 // distance to camera position (v0 is the position without sinusodial warping!) add r0,r0,-c16.x // distance-fog_start mad r0.x,-r0.x,c16.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start)) max oFog.x,r0.x,c33.x // clamp with custom max value
mul r0,c43,v0.x // use vertex pos x as inputs to sinusoidal warp mad r0,c44,v0.y,r0 // use vertex pos y as inputs to sinusoidal warp
mov r1,c32.w // get current time mad r0,r1,c45,r0 // add scaled time frc r0.xy,r0 // take fraction of all 4 components frc r1.xy,r0.zwzw mov r0.zw,r1.xyxy
mul r0,r0,c36.x // multiply by fixup factor (due to inaccuracy of taylor series) sub r0,r0,c33.y // subtract 0.5 mul r1,r0,c35.w // range -pi to pi
mul r2,r1,r1 // wave_vec^2 mul r3,r2,r1 // wave_vec^3 mul r5,r3,r2 // wave_vec^5 mul r7,r5,r2 // wave_vec^7 mul r9,r7,r2 // wave_vec^9
mad r0,r3,c34.x,r1 // wave_vec-(wave_vec^3)/3! mad r0,r5,c34.y,r0 // +(wave_vec^5)/5! mad r0,r7,c34.z,r0 // -(wave_vec^7)/7! mad r0,r9,c34.w,r0 // +(wave_vec^9)/9!
dp4 r3.x,r0,c40 dp4 r3.y,r0,c41 dp4 r3.zw,r0,c42
sub r4,c33.z,v7.y // attenuate sinusoidal warping by (1-uv.y)^2 mul r4,r4,r4 mul r3,r3,r4
mov r2.w,v0 add r2.xyz,r3,v0 // add sinusoidal warping to grass position m4x4 oPos,r2,c0 // transform position to clip space
dp4 r1.x,r0,c46 // scale and add sin waves together mad oD0,c47.xzxz,-r1.x,c47.y // scale and bias color values (green is scaled more than red and blue) mov oT0.xy,v7.xy // output uvs };
pixelShader= asm { ps.1.3 def c0,1,1,1,1 def c1,0,0,0,0 tex t0 // sample t0 mov r0,t0 cnd r0.a,r0.a,c0,c1 // if(r0.a>0.5){r0.a=1;}else{r0.a=0;} mul_x2 r0.rgb,r0,v0 // modulate with lighting }; } }
Bin für jeden Tipp dankbar cheers
|
|
|
Re: Wiki Grass Shader Problem
[Re: zwecklos]
#55761
09/21/05 12:21
09/21/05 12:21
|
Joined: Sep 2004
Posts: 238 N - Österreich
Sybercool
Member
|
Member
Joined: Sep 2004
Posts: 238
N - Österreich
|
wenn du dir den code oben durchlest wirst du festellen dass der shader eine pixelshader version von mindestens 1.3 erfordert ( im code: ps.1.3 ) bisst du sicher dass deine grafikkarte die anforderungen erfüllt?
Wenn alles schläft und einer spricht,
den Zustand nennt mann UNTERRICHT
|
|
|
Re: Wiki Grass Shader Problem
[Re: Sybercool]
#55762
09/21/05 12:32
09/21/05 12:32
|
Joined: Sep 2005
Posts: 274 Switzerland - Zurich
zwecklos
OP
Member
|
OP
Member
Joined: Sep 2005
Posts: 274
Switzerland - Zurich
|
Ich hab ne ASUS N6800/TD, GeForce PCX6800, 256MB, PCI-E 16x, DVI-I, TV-Out, Retail die Unterstützt bis zu Shader 2.0 also ich denke an der graka kanns nicht liegen aber danke trotzdem für deinen Tipp. cheers
|
|
|
Re: Wiki Grass Shader Problem
[Re: ello]
#55766
09/21/05 16:52
09/21/05 16:52
|
Joined: Sep 2005
Posts: 274 Switzerland - Zurich
zwecklos
OP
Member
|
OP
Member
Joined: Sep 2005
Posts: 274
Switzerland - Zurich
|
Dank dir Ello, war ein guter Tip. Jetz kann ich wenigstens schon ein dx8 von einem dx9 shader unterscheiden. Habe alle Fehler so beseitigen können, das wird mir sicher noch nützlich sein. Danke nochmals. Was ich jetzt nicht verstehe ist warum mein Grass einfach nur schwarz dargestellt wird und es keine Bewegung hat. Hier noch der code: Code:
/////////////////////////////////// // grass.wdl bind <grass.fx>;
bmap grass_bild = <grass02.tga>;
/* function makemips { bmap_to_mipmap(mtl.Skin1);
} */
material mat_grass { Skin1 = grass_bild; //event = makemips; }
Action grass_wave { fps_max = 60; effect_load(mat_grass, "grass.fx"); wait(1); my.material = mat_grass; }
und hier die fx datei: Code:
//texture entSkin1;
matrix matWorldViewProj; matrix matWorldView; vector vecFog; vector vecTime;
technique grass { pass p0 { vertexShaderConstant[0]=<matWorldViewProj>; vertexShaderConstant[8]=<matWorldView>; vertexShaderConstant[16]=<vecFog>; vertexShaderConstant[32]=<vecTime>; vertexShaderConstant[33]=(0.0f,0.5f,1.0f,2.0f); // common constants vertexShaderConstant[34]=(-0.16161616f,0.0083333f,-0.00019841f,0.000002755731f);// (-1/3!,1/5!,-1/7!,1/9!) vertexShaderConstant[35]=(4.0f,1.57079632f,3.14159265f,6.28318530f); // (4.0,pi/2,pi,pi*2) vertexShaderConstant[36]=(1.07f,0.0f,0.0f,0.0f); // fixup factor
vertexShaderConstant[40]=(2.5f,1.0f,0.5f,0.1f); // wave distort x vertexShaderConstant[41]=(5.0f,0.5f,0.25f,0.1f); // wave distort y vertexShaderConstant[42]=(-1.0f,-0.01f,-0.04f,-0.01f); // wave distort z vertexShaderConstant[43]=(-0.1f,-0.2f,0.1f,0.05f); // wave dir x vertexShaderConstant[44]=(-0.005f,-0.01f,-0.005f,-0.0025f); // wave dir y vertexShaderConstant[45]=(0.02f,0.04f,0.05f,0.1f); // wave speed vertexShaderConstant[46]=(0.35f,0.1f,0.1f,0.04f); // lighting wave scale vertexShaderConstant[47]=(0.6f,0.8f,0.3f,0.0f); // lighting scale bias //vertexShaderConstant[64]= {20.0,20.0,20.0,20.0}; vertexShader= asm {
vs.1.1 dcl_position v0; dcl_normal v3; dcl_texcoord0 v7; dcl_tangent v8; //Stream 0; mov r1.w,c16.w // r1.w=1 dp4 r0,v0,c10 // distance to camera position (v0 is the position without sinusodial warping!) add r0,r0,-c16.x // distance-fog_start mad r0.x,-r0.x,c16.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
mul r0,c43,v0.x // use vertex pos x as inputs to sinusoidal warp mad r0,c44,v0.y,r0 // use vertex pos y as inputs to sinusoidal warp
mov r1,c32.w // get current time mad r0,r1,c45,r0 // add scaled time frc r0.xy,r0 // take fraction of all 4 components frc r1.xy,r0.zwzw mov r0.zw,r1.xyxy
mul r0,r0,c36.x // multiply by fixup factor (due to inaccuracy of taylor series) sub r0,r0,c33.y // subtract 0.5 mul r1,r0,c35.w // range -pi to pi
mul r2,r1,r1 // wave_vec^2 mul r3,r2,r1 // wave_vec^3 mul r5,r3,r2 // wave_vec^5 mul r7,r5,r2 // wave_vec^7 mul r9,r7,r2 // wave_vec^9
mad r0,r3,c34.x,r1 // wave_vec-(wave_vec^3)/3! mad r0,r5,c34.y,r0 // +(wave_vec^5)/5! mad r0,r7,c34.z,r0 // -(wave_vec^7)/7! mad r0,r9,c34.w,r0 // +(wave_vec^9)/9!
dp4 r3.x,r0,c40 dp4 r3.y,r0,c41 dp4 r3.zw,r0,c42
sub r4,c33.z,v7.y // attenuate sinusoidal warping by (1-uv.y)^2 mul r4,r4,r4 mul r3,r3,r4
mov r2.w,v0 add r2.xyz,r3,v0 // add sinusoidal warping to grass position m4x4 oPos,r2,c0 // transform position to clip space
dp4 r1.x,r0,c46 // scale and add sin waves together mad oD0,c47.xzxz,-r1.x,c47.y // scale and bias color values (green is scaled more than red and blue) mov oT0.xy,v7.xy // output uvs //max oFog.x,r0.x,c33.x // clamp with custom max value max oFog,r0.x,c95.w };
pixelShader= asm { ps.1.3 def c0,1,1,1,1 def c1,0,0,0,0 tex t0 // sample t0 mov r0,t0 cnd r0.a,r0.a,c0,c1 // if(r0.a>0.5){r0.a=1;}else{r0.a=0;} mul_x2 r0.rgb,r0,v0 // modulate with lighting }; } }
Irgendwie denke ich es könnte an den vertexShaderConstants liegen...irgendjemand ne Idee in welcher Richtung ich suchen muss? cheers
|
|
|
Re: Wiki Grass Shader Problem
[Re: ello]
#55768
09/22/05 14:37
09/22/05 14:37
|
Joined: Sep 2005
Posts: 274 Switzerland - Zurich
zwecklos
OP
Member
|
OP
Member
Joined: Sep 2005
Posts: 274
Switzerland - Zurich
|
Hi ello danke für die Antwort, Ich hab mal deinen Rat befolgt und es sieht immer noch gleich aus. Nur hab ich das Gefühl das es so etwas pixeliger wirkt. Ich hab dann weiter versucht und herausgefunden, dass wenn ich "mul_x2 r0.rgb,r0,v0" im Pixelshader auskommentiere, wird die Textur angezeigt Aber immer noch keine Bewegung. was genau macht die Zeile mul_x2 r0.rgb,r0,v0? Ich hab noch Probleme den Stream korrekt in den script einzubinden, sobald ich den Stream 0 aktiviere bekomme ich beim starten die comma expression fehlermeldung. Ich denke die bringt er immer wenn was mit der syntax nicht in ordnung ist. Weisst du ello oder sonst jemand wie ich den Stream behnadeln muss damit er unter dx9 läuft? Ich habe ein thread gefunden (http://www.coniserver.net/ubbthreads/showflat.php?Cat=0&Number=514715&page=0&fpart=2&vc=1)wo du rätst Stream auszukommentieren aber brauchts den ned? Für jeden Tipp bin ich weiterhin dankbar. cheers Edit: Code vergessen WDL Datei Code:
/////////////////////////////////// // grass.wdl bind <grass.fx>;
bmap grass_bild = <grass02.tga>;
/* function makemips { bmap_to_mipmap(mtl.Skin1); } */
material mat_grass { Skin1 = grass_bild; //event = makemips; }
Action grass_wave { my.flare = off; my.transparent = off; //fps_max = 60; effect_load(mat_grass, "grass.fx"); wait(1); my.material = mat_grass; }
fx Datei: Code:
texture texSkin1;
matrix matWorldViewProj; matrix matWorldView; vector vecFog; vector vecTime;
technique grass { pass p0 {
ZWriteEnable=true; AlphaTestEnable=true; CullMode=none; vertexShaderConstant[0]=<matWorldViewProj>; vertexShaderConstant[8]=<matWorldView>; vertexShaderConstant[16]=<vecFog>; vertexShaderConstant[32]=<vecTime>; vertexShaderConstant[33]=(0.0f,0.5f,1.0f,2.0f); // common constants vertexShaderConstant[34]=(-0.16161616f,0.0083333f,-0.00019841f,0.000002755731f);// (-1/3!,1/5!,-1/7!,1/9!) vertexShaderConstant[35]=(4.0f,1.57079632f,3.14159265f,6.28318530f); // (4.0,pi/2,pi,pi*2) vertexShaderConstant[36]=(1.07f,0.0f,0.0f,0.0f); // fixup factor
vertexShaderConstant[40]=(2.5f,1.0f,0.5f,0.1f); // wave distort x vertexShaderConstant[41]=(5.0f,0.5f,0.25f,0.1f); // wave distort y vertexShaderConstant[42]=(-1.0f,-0.01f,-0.04f,-0.01f); // wave distort z vertexShaderConstant[43]=(-0.1f,-0.2f,0.1f,0.05f); // wave dir x vertexShaderConstant[44]=(-0.005f,-0.01f,-0.005f,-0.0025f); // wave dir y vertexShaderConstant[45]=(0.02f,0.04f,0.05f,0.1f); // wave speed vertexShaderConstant[46]=(0.35f,0.1f,0.1f,0.04f); // lighting wave scale vertexShaderConstant[47]=(0.6f,0.8f,0.3f,0.0f); // lighting scale bias //vertexShaderConstant[64]= {20.0,20.0,20.0,20.0}; vertexShader= asm { vs.1.1 //stream 0; dcl_position v0; dcl_normal v3; dcl_texcoord0 v7; //dcl_tangent v8; mov r1.w,c16.w // r1.w=1 dp4 r0,v0,c10 // distance to camera position (v0 is the position without sinusodial warping!) add r0,r0,-c16.x // distance-fog_start mad r0.x,-r0.x,c16.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
mul r0,c43,v0.x // use vertex pos x as inputs to sinusoidal warp mad r0,c44,v0.y,r0 // use vertex pos y as inputs to sinusoidal warp
mov r1,c32.w // get current time mad r0,r1,c45,r0 // add scaled time frc r0.xy,r0 // take fraction of all 4 components frc r1.xy,r0.zwzw mov r0.zw,r1.xyxy
mul r0,r0,c36.x // multiply by fixup factor (due to inaccuracy of taylor series) sub r0,r0,c33.y // subtract 0.5 mul r1,r0,c35.w // range -pi to pi
mul r2,r1,r1 // wave_vec^2 mul r3,r2,r1 // wave_vec^3 mul r5,r3,r2 // wave_vec^5 mul r7,r5,r2 // wave_vec^7 mul r9,r7,r2 // wave_vec^9
mad r0,r3,c34.x,r1 // wave_vec-(wave_vec^3)/3! mad r0,r5,c34.y,r0 // +(wave_vec^5)/5! mad r0,r7,c34.z,r0 // -(wave_vec^7)/7! mad r0,r9,c34.w,r0 // +(wave_vec^9)/9!
dp4 r3.x,r0,c40 dp4 r3.y,r0,c41 dp4 r3.zw,r0,c42
sub r4,c33.z,v7.y // attenuate sinusoidal warping by (1-uv.y)^2 mul r4,r4,r4 mul r3,r3,r4
mov r2.w,v0 add r2.xyz,r3,v0 // add sinusoidal warping to grass position m4x4 oPos,r2,c0 // transform position to clip space
dp4 r1.x,r0,c46 // scale and add sin waves together mad oD0,c47.xzxz,-r1.x,c47.y // scale and bias color values (green is scaled more than red and blue) mov oT0.xy,v7.xy // output uvs //max oFog.x,r0.x,c33.x // clamp with custom max value max oFog,r0.x,c95.w };
pixelShader= asm { ps.1.3 def c0,1,1,1,1 def c1,0,0,0,0 tex t0 // sample t0 mov r0,t0 cnd r0.a,r0.a,c0,c1 // if(r0.a>0.5){r0.a=1;}else{r0.a=0;} //mul_x2 r0.rgb,r0,v0 // modulate with lighting
}; } }
Last edited by zwecklos; 09/22/05 15:10.
|
|
|
Re: Wiki Grass Shader Problem
[Re: zwecklos]
#55769
09/22/05 19:07
09/22/05 19:07
|
Joined: Oct 2002
Posts: 8,939 planet.earth
ello
Senior Expert
|
Senior Expert
Joined: Oct 2002
Posts: 8,939
planet.earth
|
pas auf, mach das mal mit hlsl!
da kannst du viel intuitiver arbeiten.
z.b. kannst du bevor du die position zum ausgang sendest folgendes tun (nicht getestet aber prinzipiell):
position.xyz+=float3(sin(normal.x/100+vecTime.w/33),cos(position.y/89-vecTime.w/41),-sin(vecTime.w/50+position.z)); oPos = mul(position,matWorldViewProj);
damit hast du dann die vertexposition verändert. schau dir einfach mal n paar hlsl seiten an, google mal
damit solltest du dich mal auseinander setzen. es ist besser als in asm zu proggn (macht auch spass)
www.earthcontrol.dequoted: We want to maintain a clean, decent, American family suited forum look... which means you may post zombies or chainsaw massacres, but no erotic.
|
|
|
|