2 registered members (Akow, SBGuy),
1,423
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
change smoothly between textures
#96405
10/29/06 12:58
10/29/06 12:58
|
Joined: Sep 2006
Posts: 36 Ger
Fussfoehn
OP
Newbie
|
OP
Newbie
Joined: Sep 2006
Posts: 36
Ger
|
Hi, i´m looking for a shader which changes smoothly between two or more textures depending on a skill of the entity. for example like a chameleon for camouflage. Hope you can help me Hi Allemiteinander ich bin auf der suche nach nem shader der weich zwischen mehreren texturen wechseln kann abhängig von einem oder mehreren skills der entity. Also wenn man wie beim multitex terrain mehrere texturen übereinanderlegt aber den Alphawert der Texturen während dem spielverlauf verändern kann. Wie wenn sich ein Chamäleon grade anpasst. Hoffe ihr könnt mir helfen
|
|
|
Re: change smoothly between textures
[Re: ello]
#96408
10/30/06 21:07
10/30/06 21:07
|
Joined: Sep 2006
Posts: 36 Ger
Fussfoehn
OP
Newbie
|
OP
Newbie
Joined: Sep 2006
Posts: 36
Ger
|
k thx das klingt schon gut... nur dafür muss man doch dann nen pixel shader benutzen oder?
hab nu mal folgenden shader für die entity... wie bau ich das jetzt da ein?.. also dass man den Alphawert von s_blueTex von vecSkill41.x anhängig macht?
material anpassen_mat {
effect= "
float4x4 matTerrainTexSize = {1.0, 0.0, 0.0 ,0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
float4 vecLight; float4 vecSkill41; float ambientLightFactor = 0.05;
Texture entSkin1; Texture entSkin2;
sampler s_redTex = sampler_state { Texture = (entSkin1); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap;
MipMapLodBias=-0.2; };
sampler s_blueTex = sampler_state { Texture = (entSkin2); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap;
MipMapLodBias=-0.2; };
technique technique_one {
pass p0 { Sampler[0] = (s_redTex);
AlphaBlendEnable = False; AlphaTestEnable = False; DitherEnable = True; zWriteEnable = True; zEnable = True; Lighting=True;
Ambient = mul(vecLight, ambientLightFactor);
TextureTransformFlags[0] = Count2; TexCoordIndex[0] = 1;
ColorOp[0] = Modulate2x; ColorArg1[0] = Texture; ColorArg2[0] = Diffuse; AlphaOp[0] = Disable;
}
pass p1 { Sampler[0] = (s_blueTex);
AlphaBlendEnable = False; AlphaTestEnable = False; DitherEnable = True; zWriteEnable = True; zEnable = True; Lighting=True;
Ambient = mul(vecLight, ambientLightFactor);
TextureTransformFlags[0] = Count2; TexCoordIndex[0] = 1;
ColorOp[0] = Modulate2x; ColorArg1[0] = Texture; ColorArg2[0] = Diffuse; AlphaOp[0] = Disable; } }
"; }
ich weiss manche Zeilen sind da überflüssig, aber ich als shadernewb bin froh das ich den so hinbekomme hab^^
|
|
|
Re: change smoothly between textures
[Re: ello]
#96409
11/04/06 20:35
11/04/06 20:35
|
Joined: Oct 2002
Posts: 150 Prince Edward Island, Canada
Nagashi
Member
|
Member
Joined: Oct 2002
Posts: 150
Prince Edward Island, Canada
|
Here is what I have come up with based on this idea. Unfortunaly I'm stuck when it comes to passing the needed value to the shader… The shader it’s self works well if you replace “mtlSkill1” in the pixel shader output, with a value like 0.5 (must be between 1 and 0) but to do smooth transitions you would need to set this dynamically out side the shader and pass it. As ello hase metioned above. So the big question is dose any one know how I would pass a value between 1 and 0 to a shader, again for example the number 0.5 Here is the shader Code:
float4x4 matWorldViewProj;
float4 mtlSkill1;
struct VS_OUTPUT { float4 Pos: POSITION; float2 Txr1: TEXCOORD0; float2 Txr2: TEXCOORD1; float2 Txr3: TEXCOORD2; };
VS_OUTPUT mainVS( float4 inPos: POSITION, float2 Txr1: TEXCOORD0 ) { VS_OUTPUT Out;
// Output our transformed and projected vertex // position and texture coordinate Out.Pos = mul(inPos,matWorldViewProj); Out.Txr1 = Txr1; Out.Txr2 = Txr1; Out.Txr3 = Txr1;
return Out; }
texture entSkin1;
sampler Texture0 = sampler_state { Texture = <entSkin1>; };
texture entSkin2;
sampler Texture1 = sampler_state { Texture = <entSkin2>; };
texture entSkin3;
sampler Texture2 = sampler_state { Texture = <entSkin3>; };
float4 mainPS(float2 inTxr1: TEXCOORD0, float2 inTxr2: TEXCOORD1, float2 inTxr3: TEXCOORD2) : COLOR { // Output float4 color1 = tex2D(Texture1,inTxr2); float4 color2 = tex2D(Texture2,inTxr3); float4 blended = lerp(color1,color2,mtlSkill1);// uses a value between 1 and 0, for example 0.5 return tex2D(Texture0,inTxr1)*blended; }
//--------------------------------------------------------------// // Technique Section for MyEffectGroup //--------------------------------------------------------------// technique MyEffect { pass Pass_0 { VertexShader = compile vs_1_1 mainVS(); PixelShader = compile ps_1_1 mainPS(); }
}
Any help would be greatly appreciated Cheers
No rest for the wicked. __________________________ Ironbound Studios__________________________
|
|
|
Re: change smoothly between textures
[Re: Excessus]
#96411
11/04/06 21:12
11/04/06 21:12
|
Joined: Oct 2002
Posts: 150 Prince Edward Island, Canada
Nagashi
Member
|
Member
Joined: Oct 2002
Posts: 150
Prince Edward Island, Canada
|
I have tried this with both float and float4 I'm setting the value as you would expect like this; Code:
material tester { //skill1 = 0.5; also tried setting it here. effect = "ati.fx"; }
action test_shader { tester.skill1 = 0.5; my.material = tester; }
This does not work for me, I have also just tried changing the case to mtlskin1 in stead of mtlSkin1 though I believe it should be mtlSkin1 not the lower case. I should also mention the problem seems to be in the shader it’s self since the above method dose pass a value along to the shader… the problem is any thing above 0 is treated as 1 so there is no distinction between 0.1, and 1. I believe the problem lies in calling the variable as a float… for which I have no solution. cheers
No rest for the wicked. __________________________ Ironbound Studios__________________________
|
|
|
Re: change smoothly between textures
[Re: Nagashi]
#96412
11/04/06 21:18
11/04/06 21:18
|
Joined: Jan 2004
Posts: 2,013 The Netherlands
Excessus
Expert
|
Expert
Joined: Jan 2004
Posts: 2,013
The Netherlands
|
Ah, forgot that: use the float(var) instruction. I think this means you can't set them in the material definition, but have to do it somewhere else in your code: material.skill1 = float(0.5); This is from the manual: Quote:
The skills are _not_ automatically converted to float. This has to be done by C-Script through float(), floatd() or floatr() instructions.
|
|
|
Re: change smoothly between textures
[Re: Excessus]
#96413
11/04/06 21:46
11/04/06 21:46
|
Joined: Oct 2002
Posts: 150 Prince Edward Island, Canada
Nagashi
Member
|
Member
Joined: Oct 2002
Posts: 150
Prince Edward Island, Canada
|
Thanks for the quick replies… I tired this as well… it won’t work ether; I think the problem is that changing the value to a float breaks the shader. Though I have tried using int instead of float neither seem to work.
cheers
No rest for the wicked. __________________________ Ironbound Studios__________________________
|
|
|
|