0 registered members (),
744
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
asm => hlsl..... projection shader
#162016
10/19/07 01:38
10/19/07 01:38
|
Joined: Mar 2007
Posts: 99 Germany
zSteam
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2007
Posts: 99
Germany
|
hello I'm trying to build a texture projection demo. but the shader is in asm and i need it in hsl to increase the result. can me anyone explain/convert the shader? I think the projection shader is very important for many 3dgs users. Code:
texture mtlSkin1; //projector texture entSkin1; //colormap matrix matWorldViewProj; matrix matWorld; matrix matMtl; technique projector { pass p0 //projector { //load matrices //VertexShaderConstant[0] = <matWorld>; //World Matrix VertexShaderConstant[8] = <matWorldViewProj>; VertexShaderConstant[95] = <matMtl>; //range constant VertexShaderConstant[33] = {0.01f, 0.5f, 0.05f, 0.0f}; Texture[0] = <mtlSkin1>; //projection tex Texture[1] = <entSkin1>; //projection tex AddressU[0] = Clamp; // don't wrap around edges AddressV[0] = Clamp; AddressU[1] = Clamp; // don't wrap around edges AddressV[1] = Clamp; zWriteEnable=true; // enables writing to the z-buffer VertexShader= asm { vs_1_1
dcl_position v0 dcl_normal v3 dcl_texcoord0 v7 dcl_texcoord1 v8 ; position in clip space m4x4 oPos, v0, c8 ; position in texture projection space m4x4 r10,v0,c95 ; Divide each component by the range value mul r10, r10, c33.x ; multiply with 0.5 and add 0.5 mad r10, r10, c33.yyyy, c33.yyyy ; map the x and y components into the first texture mov oT0.xy, r10.xy mov oT1.xy, v7.xy; color }; PixelShader= asm { ps_1_1 tex t0 tex t1 mov r0,t0 mul r0,r0,t1 }; } }
|
|
|
Re: asm => hlsl..... projection shader
[Re: zSteam]
#162017
10/19/07 13:32
10/19/07 13:32
|
Joined: Mar 2007
Posts: 99 Germany
zSteam
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2007
Posts: 99
Germany
|
I tried to convert the shader to HLSL but it doesn't work.... the engine starts and close without a message. => crash? what's wrong? here is my prototype shader: Code:
//-------------------------------------------------------------- // Texture Projection Shader // // by zSteam // -------------------------------------------------------------
float4x4 matWorldViewProj; float4x4 matMtl;
float4 range = {0.01f, 0.5f, 0.05f, 0.0f}; float tps;
struct VS_OUTPUT { float4 oPos : POSITION; float2 Tex0 : TEXCOORD0; float2 Tex1 : TEXCOORD1; };
VS_OUTPUT mainVS( float4 oPos : POSITION, float2 Tex0 : TEXCOORD0, float2 Tex1 : TEXCOORD1 ) { VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.oPos = mul(oPos, matWorldViewProj); tps = mul(oPos, matMtl); tps = tps * range.x; tps = (tps * range.yyyy) + range.yyyy; Out.Tex0.xy = tps.xy; Out.Tex1.xy = Tex0.xy;
return Out; }
texture entSkin1; texture mtlSkin1;
sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; // don't wrap around edges AddressV = Clamp; // don't wrap around edges };
sampler ProjTex = sampler_state { Texture = <mtlSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; // don't wrap around edges AddressV = Clamp; // don't wrap around edges };
float4 mainPS(float2 Tex : TEXCOORD0) : COLOR { Color = ColorMapSampler * ProjTex; return Color; }
technique projector { pass p0 { zWriteEnable=true; VertexShader = compile vs_1_1 mainVS(); PixelShader = compile ps_1_1 mainPS(); } }
|
|
|
Re: asm => hlsl..... projection shader
[Re: zSteam]
#162018
10/19/07 14:31
10/19/07 14:31
|
Joined: Aug 2006
Posts: 652 Netherlands
bstudio
User
|
User
Joined: Aug 2006
Posts: 652
Netherlands
|
You named the inputs the same as the outputs, change that.
BASIC programmers never die, they GOSUB and don't RETURN.
|
|
|
Re: asm => hlsl..... projection shader
[Re: bstudio]
#162019
10/19/07 14:44
10/19/07 14:44
|
Joined: Mar 2007
Posts: 99 Germany
zSteam
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2007
Posts: 99
Germany
|
ok ty i've changed the in-/outputs but i've the same problem my currently code Code:
... struct VS_OUTPUT { float4 oPos : POSITION; float2 oTex0 : TEXCOORD0; float2 oTex1 : TEXCOORD1; };
VS_OUTPUT mainVS( float4 Pos : POSITION, float2 Tex : TEXCOORD0 ) { VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.oPos = mul(Pos, matWorldViewProj); tps = mul(Pos, matMtl); tps = tps * range.x; tps = (tps * range.yyyy) + range.yyyy; Out.oTex0.xy = tps.xy; Out.oTex1.xy = Tex.xy;
return Out; }
...
float4 mainPS(float4 Color: COLOR) : COLOR { Color = ColorMapSampler * ProjTex; return Color; } ...
|
|
|
Re: asm => hlsl..... projection shader
[Re: zSteam]
#162020
10/19/07 14:51
10/19/07 14:51
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
"Color = ColorMapSampler * ProjTex;"
..YOu can't retrieve a texture like this. You need to use a texture lookup [tex2D(sampler, float2 coords);]
Also many undefined variables, such as "tps, Colorrange"
xXxGuitar511 - Programmer
|
|
|
Re: asm => hlsl..... projection shader
[Re: zSteam]
#162022
10/19/07 16:13
10/19/07 16:13
|
Joined: Mar 2007
Posts: 99 Germany
zSteam
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2007
Posts: 99
Germany
|
OK It works, but I have a problem ... The projected image is distorted on the edges. How can I solve this problem? screeny: my code: Code:
//-------------------------------------------------------------- // Texture Projection Shader HLSL // // © by zSteam // // date: 19.10.2007 // -------------------------------------------------------------
float4x4 matWorldViewProj; float4x4 matMtl;
struct VS_OUTPUT { float4 oPos : POSITION; float2 oTex0 : TEXCOORD0; float2 oTex1 : TEXCOORD1; };
VS_OUTPUT mainVS( float4 Pos : POSITION, float2 Tex : TEXCOORD0 ) { float2 tps;
VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.oPos = mul(Pos, matWorldViewProj); tps = mul(Pos, matMtl) * 0.01f; tps = (tps * 0.5f) + 0.5f;
Out.oTex0.xy = tps.xy; Out.oTex1.xy = Tex.xy;
return Out; }
texture entSkin1; texture mtlSkin1;
sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; };
sampler ProjTex = sampler_state { Texture = <mtlSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; // don't wrap around edges AddressV = Clamp; // don't wrap around edges };
float4 mainPS(float2 Tex0 : TEXCOORD0, float2 Tex1 : TEXCOORD1 ) : COLOR { float4 base = tex2D(ColorMapSampler, Tex1); float4 proj = tex2D(ProjTex, Tex0)*4;
return (base*proj); }
technique projector { pass p1 { VertexShader = compile vs_1_1 mainVS(); PixelShader = compile ps_1_1 mainPS(); } }
technique fallback { pass one { } }
|
|
|
Re: asm => hlsl..... projection shader
[Re: bstudio]
#162023
10/19/07 17:57
10/19/07 17:57
|
Joined: Oct 2002
Posts: 8,939 planet.earth
ello
Senior Expert
|
Senior Expert
Joined: Oct 2002
Posts: 8,939
planet.earth
|
Quote:
You named the inputs the same as the outputs, change that.
as far as i know this causes no problem. i never found problems with this
|
|
|
Re: asm => hlsl..... projection shader
[Re: ello]
#162024
10/19/07 18:02
10/19/07 18:02
|
Joined: Apr 2007
Posts: 582 Germany
Poison
User
|
User
Joined: Apr 2007
Posts: 582
Germany
|
I think it is a problem with the graphics card! Wich Card do you have??
Cheers
Poison Byte
PS: Sometimes I have the same Problem
Everything is possible, just Do it!
|
|
|
Re: asm => hlsl..... projection shader
[Re: Poison]
#162025
10/19/07 18:26
10/19/07 18:26
|
Joined: Mar 2007
Posts: 99 Germany
zSteam
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2007
Posts: 99
Germany
|
hi .. it's not my graficcard (ati radeon 1800xt => shader 3.0) if i change AddressU/AddressV to wrap, the prjected picture shows tiling. but i only need one tile (no other tiling)
|
|
|
|