Bonjour,
je doit réaliser un shader de filtrage bicubique en CG, j'ai trouvé un peut d'information: http://http.developer.nvidia.com/GPU...chapter20.html (complétement indigéste) et un article de blog sur un shader en hlsl http://vec3.ca/bicubic-filtering-in-fewer-taps/, j'ai éssayé de convertir ce code en cg, mais j'obtient un resultat qui ressemble a rien, d'ailleurs je sais pas vraiment à quoi ça doit ressembler.
voici le code que j'ai convertit
voici le fichier hlsl qui, je suppose, fonctionne:
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 float4 ps_main( float2 iTc : TEXCOORD0, uniform sampler2D tex) : COLOR { //get into the right coordinate system float2 texSize = float2(4, 4); //hardcode texture size float2 invTexSize = 1.0 / texSize; iTc *= texSize; //round tc *down* to the nearest *texel center* float2 tc = floor( iTc - 0.5 ) + 0.5; //compute the fractional offset from that texel center //to the actual coordinate we want to filter at float2 f = iTc - tc; //we'll need the second and third powers //of f to compute our filter weights float2 f2 = f * f; float2 f3 = f2 * f; //compute the filter weights float2 w0 = f2 - 0.5 * (f3 + f); float2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0; float2 w3 = 0.5 * (f3 - f2); float2 w2 = 1.0 - w0 - w1 - w3; //get our texture coordinates float2 s0 = w0 + w1; float2 s1 = w1 + w2; float2 f0 = w1 / (w0 + w1); float2 f1 = w3 / (w2 + w3); float2 t0 = tc - 1 + f0; float2 t1 = tc + 1 + f1; //and sample and blend return tex2D( tex, float2( t0.x, t0.y ) ) * s0.x * s0.y + tex2D( tex, float2( t1.x, t0.y ) ) * s1.x * s0.y + tex2D( tex, float2( t0.x, t1.y ) ) * s0.x * s1.y + tex2D( tex, float2( t1.x, t1.y ) ) * s1.x * s1.y; }
je n'y connais rien en hlsl donc j'ai certainement commis une erreur dans ces quelques lignes que j'ai convertit, en fait j'y connais pas grand chose en cg non plus /:.
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 Texture2D g_Tex; //the texture we're zooming in on SamplerState g_Lin; //a sampler configured for bilinear filtering float4 ps_main( float2 iTc : TEXCOORD0 ) { //get into the right coordinate system float2 texSize; g_Tex.GetDimensions( texSize.x, texSize.y ); float2 invTexSize = 1.0 / texSize; iTc *= texSize; //round tc *down* to the nearest *texel center* float2 tc = floor( iTc - 0.5 ) + 0.5; //compute the fractional offset from that texel center //to the actual coordinate we want to filter at float2 f = iTc - tc; //we'll need the second and third powers //of f to compute our filter weights float2 f2 = f * f; float2 f3 = f2 * f; //compute the filter weights float2 w0 = f2 - 0.5 * (f3 + f); float2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0; float2 w3 = 0.5 * (f3 - f2); float2 w2 = 1.0 - w0 - w1 - w3; //get our texture coordinates float2 tc0 = tc - 1; float2 tc1 = tc; float2 tc2 = tc + 1; float2 tc3 = tc + 2; //get our texture coordinates float s0 = w0 + w1; float s1 = w1 + w2; float f0 = w1 / (w0 + w1); float f1 = w3 / (w2 + w3); float2 t0 = tc - 1 + f0; float2 t1 = tc + 1 + f1; //and sample and blend return g_Tex.Sample( g_Lin, float2( t0.x, t0.y ) ) * s0.x * s0.y + g_Tex.Sample( g_Lin, float2( t1.x, t0.y ) ) * s1.x * s0.y + g_Tex.Sample( g_Lin, float2( t0.x, t1.y ) ) * s0.x * s1.y + g_Tex.Sample( g_Lin, float2( t1.x, t1.y ) ) * s1.x * s1.y; }
Sinon je suis également ouvert si vous avez un complément d'information à apporter ou un lien vers une source d'information suplémentaire que je n'aurait pas trouvé.
Partager