Bonjour,
Donc je vais donner quelques petites indications avant de developper mon probleme, je developpe en Delphi.Net et en DirectX managed, ce qui m'oblige souvent à faire de la "traduction" de code pour certaines choses.
J'en viens donc à mon problème.
J'ai trouvé un exemple de rendu Cel Shading en HLSL qui me convenait (il est en C++ et DirectX non managé) j'ai donc essayé de récuperer la partie nécessaire à l'utilisation et l'application des Shaders (j'ai déja manipulé plusieurs fois des shaders, et je n'ai pas encore eu ce genre de problème). Mais ca ne marche pas (d'ou le post :p). Mon application bug au niveau de la premiere passe, après le draw de mon objet.
Voici le code en C++ (vous inquietez pas il n'est pas long)
Donc le code m'avait pas l'air trop compliqué et voila ce que ca donne en delphi.net pour les parties qui nous interesse :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 #include "dxutil/dxutil/resources.h" using namespace std; using namespace DXUtil; class CelDemo : public DXUtil::IApplication, public DXUtil::IDeviceListener, public DXUtil::IInputListener { public: CelDemo(AppWindow& aw) : IDeviceListener(aw), IInputListener(aw), resource_(aw), aw_(aw), move_(0.0f, 0.0f), precision_(3), outline_(3), fps_(0), clicking_(false) { // create resources DXUtil::Mesh::Cache c; mesh_ = Mesh::create_prop_mesh(resource_, c, "Resource/Mesh/teapot.prop"); effect_ = Effect::create(resource_, "Resource/FX/Cel.fx"); prec_tex_ = Texture::create(resource_, "Resource/Tex/precision.png"); //change window to something bigger EnumStart start = aw.get_enum(); EnumAdapter adap = start.choose(Enum::HardVP); EnumSamples samp = adap.wind(0); DeviceSpec spec = samp.choose(800, 600, 0); aw.change_device(spec); } //IApplication //render a single frame void frame(IDirect3DDevice9& dev, float dt) { //Update the resource manager resource_.think(); //make sure our effect is good before we try and render with it if(!effect_->good()) return; //clear the backbuffer and begin our scene dev.Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(255,50,125,255), 1, 0); dev.BeginScene(); ID3DXEffect& effect = *effect_->get(); //set up our world matrix based on rotation static D3DXVECTOR2 angles(0.0f, D3DX_PI/2); angles += move_ * dt; move_ = D3DXVECTOR2(0.0f, 0.0f); D3DXMATRIX world, rotx, roty, scale; D3DXMatrixScaling(&scale, 10.f, 10.f, 10.f); D3DXMatrixRotationAxis(&rotx, &D3DXVECTOR3(cos(angles.x), 0, sin(angles.x)),angles.y ); D3DXMatrixRotationY(&roty, angles.x); world = scale * rotx * roty; effect.SetMatrix("World", &world); if(prec_tex_->good()) effect.SetTexture("Tex_Precision", prec_tex_->get()); effect.SetFloat("outline", outline_ / 100.0f); effect.SetFloat("precision", precision_ / 16.0f); //render it UINT passes; effect.Begin(&passes, NULL); for(UINT i=0; i<passes; i++) { effect.BeginPass(i); mesh_->draw_subset(0); effect.EndPass(); } effect.End(); dev.EndScene(); dev.Present(0,0,0,0); } void device_created(IDirect3DDevice9& dev) {} void device_reset(IDirect3DDevice9& dev) { //set up view and projection matrices D3DXMATRIX view; D3DXVECTOR3 eye(0,0,-7); D3DXVECTOR3 at(0,0,0); D3DXVECTOR3 up(0,1,0); D3DXMatrixLookAtLH(&view, &eye, &at, &up); dev.SetTransform(D3DTS_VIEW, &view); D3DXMATRIX proj; D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI/4.0f, 4.0f/3, 1.0f, 100.0f); dev.SetTransform(D3DTS_PROJECTION, &proj); if(effect_->good()) { effect_->get()->SetMatrix("View", &view); effect_->get()->SetMatrix("Proj", &proj); } //create a blitter - a blitter basically wraps an ID3DXSprite blitter_ = Blitter::create(resource_, dev); // Describe a font D3DXFONT_DESC desc; memset(&desc, 0, sizeof(desc)); desc.Height = 26; strcpy(desc.FaceName, "Arial"); font_ = Font::create(resource_, dev, desc); }
Dans les initialisations :
// Blabla
Code : Sélectionner tout - Visualiser dans une fenêtre à part Feffect := Effect.FromFile(FDevice, 'graphics/shader/Cel.fx', nil, ShaderFlags.None, nil);
Voila en gros, si j'utilise un autre fichier effect (en changeant bien tout) je n'ai pas de problème...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Feffect.SetValue('World',FDevice.Transform.World); Feffect.SetValue('View', FDevice.Transform.View); Feffect.SetValue('Proj',FDevice.Transform.Projection); Feffect.setValue('outline',3/ 100.0); Feffect.setValue('precision',3/ 100.0); Feffect.setValue('Tex_Precision',precision); // Bla Bla Feffect.Technique := 'None'; for k:= 0 to Feffect.&Begin(Fx.None) -1 do begin Feffect.BeginPass(k); cube.DrawSubset(0); // Et la c'est le drame Feffect.EndPass(); end; Feffect.&End();
Voici au cas ou le fichier .fx bien que je ne pense pas que l'erreur vienne de la, vu que l'application en C++ s'en sert et marche très bien.
Merci d'avance pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 //Parallax and Normal Mapping Shader float3 lightDir = {1, -1, 1}; //Matrices float4x4 World : WORLD; float4x4 View : VIEW; float4x4 Proj : PROJECTION; float precision = 3.0f / 16; float outline = 0.01f; //************************************************* //STRUCTS //************************************************* struct VS_OUTPUT { float4 Pos : POSITION; float4 TexCoord : TEXCOORD0; float3 Light : TEXCOORD1; float3 Normal : TEXCOORD2; }; texture Tex; sampler texSample= sampler_state { Texture = (Tex); MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; texture Tex_Precision; sampler2D precSample= sampler_state { Texture = (Tex_Precision); MipFilter = POINT; MinFilter = POINT; MagFilter = POINT; AddressU = clamp; AddressV = clamp; }; //************************************************* //VERTEX SHADER //************************************************* VS_OUTPUT VS(float4 Position : POSITION, float3 Normal : NORMAL, float4 TexCoord : TEXCOORD0, uniform float offset) { VS_OUTPUT Out = (VS_OUTPUT)0; //transform and project onto screen float4 WorldNorm = normalize(mul(Normal, World)); Out.Normal = WorldNorm; float4 WorldPos = mul(Position,World); Out.Pos = mul(float4(WorldPos.xyz, 1.0f), View) + offset * mul(WorldNorm,View); Out.Pos = mul(float4(Out.Pos.xyz, 1.0f), Proj); //pass through light directions Out.Light = normalize(-lightDir); //pass through texture coordinates Out.TexCoord = TexCoord; return Out; } //************************************************* //Pixel Shader //************************************************* float4 PS( VS_OUTPUT In) : COLOR { //texture for model float4 Tex = tex2D(texSample, In.TexCoord); float light = saturate(dot(In.Normal, In.Light)); float2 t = float2(1.0f-light, precision-0.05f); float4 diff = tex2D(precSample, t); return diff; } float4 PS_black() : COLOR { return float4(0.0f, 0.0f, 0.0f, 1.0f); } technique None { pass p0 { VertexShader = compile vs_1_1 VS(0.0f); PixelShader = compile ps_1_4 PS(); CullMode = CCW; } pass p1 { VertexShader = compile vs_1_1 VS(outline); PixelShader = compile ps_1_1 PS_black(); CullMode = Cw; } }
Partager