Merci de répondre B)
Oui, mes variables sont initialisées et utilisées dans le code.
J’utilise la récupération du handle parce que MonEffet.SetValue(unvaleur, « mavariable ») donc une erreur d’application (sans plus de détail); donc j’ai utilisé la méthode qui consiste à faire un get sur le handle, puis un set d’une valeur sur ce handle pour m’apercevoir que mon handle était toujours nul.
Le code du shader en question:
[code]float4x4 WorldViewProj : WorldViewProjection;
float4x4 WorldViewIT : WorldInverseTranspose;
float4x4 WorldView : ViewInverse;
float4 MinMaxDist;
float4 FocusConst;
float4 lightDir : Direction
<
= {200.0f, 300.0f, 150.0f, 0.0f};
float4 lightColor : Diffuse
<
= {1.0f, 1.0f, 1.0f, 1.0f};
float4 lightAmbient : Ambient
<
= {1.0f, 1.0f, 1.0f, 1.0f};
float4 materialDiffuse : Diffuse
<
= {1.0f, 1.0f, 1.0f, 1.0f};
float UvOffsetToUse;
float4 UvBase[8];
//-------------------------------------------------------------------
// Textures (bound to real textures by app)
//-------------------------------------------------------------------
texture Meshes;
texture CircleOfConfusion;
texture WorldTex;
texture BlurTex;
texture FilteredTex0;
texture FilteredTex1;
texture FilteredTex2;
//-------------------------------------------------------------------
// Vertex shader input structures
//-------------------------------------------------------------------
struct vertexInput {
float3 position : POSITION;
float3 normal : NORMAL;
float4 texCoordDiffuse : TEXCOORD0;
};
struct VS_INPUT_PT {
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
};
//-------------------------------------------------------------------
// Vertex shader output (and pixel shader input) structures
//-------------------------------------------------------------------
struct VS_OUTPUT_PT4 {
float4 oPosition : POSITION;
float2 oTexCoord0 : TEXCOORD0;
float2 oTexCoord1 : TEXCOORD1;
float2 oTexCoord2 : TEXCOORD2;
float2 oTexCoord3 : TEXCOORD3;
};
struct vertexOutput {
float4 hPosition : POSITION;
float4 texCoordDiffuse : TEXCOORD0;
float4 diffAmbColor : COLOR0;
float3 oTexCoord1 : TEXCOORD1;
};
//-------------------------------------------------------------------
// Texture samplers
//-------------------------------------------------------------------
sampler TextureSampler = sampler_state
{
texture = ;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
sampler CircleOfConfusionSampler = sampler_state
{
Texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = None;
AddressU = Clamp;
AddressV = Clamp;
AddressW = Clamp;
};
sampler BlurTexSampler = sampler_state
{
Texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
sampler FilteredTexSampler0 = sampler_state
{
Texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = NONE;
AddressU = Clamp;
AddressV = Clamp;
};
sampler FilteredTexSampler1 = sampler_state
{
Texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = NONE;
AddressU = Clamp;
AddressV = Clamp;
};
sampler FilteredTexSampler2 = sampler_state
{
Texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = NONE;
AddressU = Clamp;
AddressV = Clamp;
};
//-------------------------------------------------------------------
// Vertex Shaders (and subroutines)
//-------------------------------------------------------------------
float ComputeDistance(float4 position)
{
float dist = dot(position, float4(WorldView[0][2], WorldView[1][2], WorldView[2][2], WorldView[3][2]));
//dist = dist / dot(position, float4(WorldView[0][3], WorldView[1][3], WorldView[2][3], WorldView[3][3]));
return dist;
}
vertexOutput VS_TransformAndTexture(vertexInput IN)
{
vertexOutput OUT;
OUT.hPosition = mul( float4(IN.position.xyz , 1.0) , WorldViewProj);
OUT.texCoordDiffuse = IN.texCoordDiffuse;
float3 worldEyePos = WorldView[3].xyz;
float3 worldVertPos = (IN.position).xyz;
float4 N = mul(IN.normal, WorldViewIT); //normal vector
float3 E = normalize(worldEyePos - worldVertPos); //eye vector
float3 L = normalize( -lightDir.xyz); //light vector
float3 H = normalize(E + L); //half angle vector
float diff = max(0 , dot(N,L));
float4 ambColor = materialDiffuse * lightAmbient;
float4 diffColor = materialDiffuse * diff * lightColor;
OUT.diffAmbColor = diffColor + ambColor;
float4 lPosition = float4(IN.position, 1.0);
float dist = ComputeDistance(lPosition);
OUT.oTexCoord1.x = dist*MinMaxDist.y - MinMaxDist.x;
OUT.oTexCoord1.yz = FocusConst.xy;
return OUT;
}
VS_OUTPUT_PT4 BlurVS(const VS_INPUT_PT IN)
{
VS_OUTPUT_PT4 OUT;
// Transform vertex position to clip space
OUT.oPosition = mul(IN.Position, WorldViewProj);
int a = (int)UvOffsetToUse * 4;
OUT.oTexCoord0 = IN.TexCoord + UvBase[a ].xy;
OUT.oTexCoord1 = IN.TexCoord + UvBase[a + 1].xy;
OUT.oTexCoord2 = IN.TexCoord + UvBase[a + 2].xy;
OUT.oTexCoord3 = IN.TexCoord + UvBase[a + 3].xy;
return OUT;
}
//-------------------------------------------------------------------
// Pixel Shaders
//-------------------------------------------------------------------
float4 BlurPS(VS_OUTPUT_PT4 IN) : COLOR
{
// This is a simple blur-shader: we simply average all alpha and color
// values together.
// get colors and alphas from all 4 texture stages
float4 color0 = tex2D(BlurTexSampler, IN.oTexCoord0);
float4 color1 = tex2D(BlurTexSampler, IN.oTexCoord1);
float4 color2 = tex2D(BlurTexSampler, IN.oTexCoord2);
float4 color3 = tex2D(BlurTexSampler, IN.oTexCoord3);
// return the average (keeping within the [-2..2] range)
return 0.5*( 0.5*(color0 + color1) + 0.5*(color2 + color3) );
}
float4 PS_Textured( vertexOutput IN): COLOR
{
float4 diffuseTexture = tex2D( TextureSampler, IN.texCoordDiffuse );
// return IN.diffAmbColor * diffuseTexture;
return float4(1.0f,1.0f,1.0f,1.0f);
}
//-------------------------------------------------------------------
// TECHNIQUES
//-------------------------------------------------------------------
technique TetraDOF
{
pass P0
{
VertexShader = compile vs_1_1 VS_TransformAndTexture();
PixelShader = compile ps_1_1 PS_Textured();
}
}
technique Blur
{
pass P0
{
VertexShader = compile vs_1_1 BlurVS();
PixelShader = compile ps_1_1 BlurPS();
// note that these render-state changes are reverted once the effect is complete.
AlphaBlendEnable = False;
ZEnable = False;
CullMode = None;
FillMode = Solid; // (even if wireframe is turned on)
ColorOp[0] = SelectArg1;
ColorArg1[0] = Texture;
ColorArg2[0] = Diffuse;
ColorOp[1] = Disable;
AlphaOp[0] = Disable;
}
}
technique ShowDepthOfField
{
pass P0
{
Sampler[0] = ;
Sampler[1] = ;
Sampler[2] = ;
AlphaBlendEnable = False;
ZEnable = False;
CullMode = None;
FillMode = Solid; // (even if wireframe is turned on)
VertexShader = compile vs_1_1 BlurVS();
PixelShader =
asm
{
; NOTE: This shader exists in HLSL above (see ShowDepthOfFieldPS),
; but is commented out; the assembly version is used here because
; it's the only way to fit this shader in ps1.1. The HLSL-compiled
; version will work if you compile it using ps_2_0; but since the
; assembly version will fit in ps_1_1, it is used here instead.
; Declare pixel shader version
ps_1_1
def c0, 0.0f, 0.0f, 0.0f, 0.5f
def c1, 0.0f, 0.0f, 0.0f, 0.333333f
; sample all the texture stages
tex t0
tex t1
tex t2
; first interpolate the interpolator: using t0 straight produces ghosting
; since the DoF selection is always hi-res (ie, t0) even for the blurred parts.
; playing with various combinations of t0, t1, t2 shows that the following
; is reasonable (depth-changing edges never get really unblurred)
; and yet only takes a single instruction.
lrp r0.a, c0, t2.a, t0.a
; although the following also produces good results (but with a bit of ghosting
; and two instructions)
; r0.a = 0.666*(.5*t2.a + .5*t1.a) + 0.333 * t0.a)
; = 0.333*(t0.a+t1.a+t2.a)
; lrp r0.a, c0, t2.a, t1.a
; lrp r0.a, c1, r0.a, t0.a
mov_x2_sat r1.a, r0.a // pretend 0 <= r0.a <= 0.5
lrp r1.rgb, r1.a, t1, t0 // correctly interpolate t0, t1 and store
mov_sat r1.a, r0_bx2.a // pretend 0.5 <= r0.a <= 1
lrp r0.rgb, r1.a, t2, t1 // correctly interpolate t1, t2 and store
cnd r0.rgb, r0.a, r0, r1 // figure out which case is the true one and select it
; mov r0.rgb, t0.a
};
}
}[/code]
Et ça foire pour les variables lightDir, lightColor, lightAmbient et materialDiffuse.