Bonjour,

j'ai un soucis quand j'essais de créer une texture 3D. Il semblerai qu'il n'y a pas de profondeur (z). Mon but étant de mettre cote à cote en deux les deux images en profondeur de ma texture afin juste de pouvoir vérifier que ma texture 3D est bien implémenté (ce qui n'est pas le cas car je n'obtiens pas le bon résultat).

Info technique :
Je suis sur Qt et j'utilise comme build : Desktop_Qt_5_6_0_MinGW_32bit
et les lib que j'utilise sont celle-ci :
#include <QtGui/QOpenGLFunctions_3_0>
#include <QtGui/QOpenGLShaderProgram>

et ma class hérite en protected de QOpenGLFunctions_3_0

Mon code cpp :
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
 
//Set 3D Texture
    glEnable(GL_TEXTURE_3D);
    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1,&m_lut3D);
    glBindTexture(GL_TEXTURE_3D, m_lut3D);
 
    float data[] = {
        0.0, 0.0, 0.0,
        1.0, 0.0, 0.0,
        0.0, 1.0, 0.0,
        1.0, 1.0, 0.0,
        0.0, 0.0, 1.0,
        1.0, 0.0, 1.0,
        0.0, 1.0, 1.0,
        1.0, 1.0, 1.0
    };
 
    glTexImage3D(
        GL_TEXTURE_3D,
        0,
        GL_RGBA,
        2,
        2,
        2,
        0,
        GL_RGB,
        GL_FLOAT,
        data
    );
 
    // Set nearest filtering mode for texture minification
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 
    // Set nearest filtering mode for texture magnification
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
    // Wrap texture coordinates by clamping
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 
//Render part
    m_program->bind(); //Avec QOpenGLShaderProgram *m_program = new QOpenGLShaderProgram(pMainWindow), pMainWindow étant ma fenetre liée à openGL;
 
    // Set the Uniforms here
 
    m_vertexAttr = m_program->attributeLocation("vertexAttr");
    m_resolutionUniform = m_program->uniformLocation("resolution");
    m_texture0SizeUniform = m_program->uniformLocation("texture0_Size");
    m_texture0Uniform = m_program->uniformLocation("texture0");
 
    m_program->setUniformValue(m_resolutionUniform, m_resolution);
    m_program->setUniformValue(m_texture0SizeUniform, m_frameBuffer_Size);
    //qDebug() << m_pMainWindow->m_frameBuffer_Size;
 
    m_program->setUniformValue(m_texture0Uniform, 0);
    m_pGl->glActiveTexture(GL_TEXTURE0);
    m_pGl->glBindTexture(GL_TEXTURE_2D, m_texture0_out);
 
    GLfloat vertices[] = {
        -1, -1, // LL
        1, -1,  // RL
        -1, 1,  // LU
        1, 1    // RU
    };
 
    // Assign the data
    m_pGl->glVertexAttribPointer(m_vertexAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
 
    // Enable the attributes
    m_pGl->glEnableVertexAttribArray(0);
    m_pGl->glClearColor(0.0f,0.0f,0.0f,1.0f);
 
    m_pGl->glClear(GL_COLOR_BUFFER_BIT);
    m_pGl->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
    // Disable the attributes
    m_pGl->glDisableVertexAttribArray(0);
    m_program->release();
Ainsi je peux tester facilement avec une petite texture 3D. Je n'utilise pas le coté 3D directe du vertex shader, celui étant plus ou moins en 2D donc.

Mon Code vsh :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
attribute highp vec4 vertexAttr;
 
void main()
{
    gl_Position = vertexAttr;
}
Mon Code fsh :
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
// #define MAC
 
// #ifndef MAC
// precision highp float;
// precision highp int;
// #endif
 
uniform vec2 resolution;
uniform sampler3D texture0;
uniform vec2 texture0_Size;
 
void main()
{
    vec2 nCoords = gl_FragCoord.xy / resolution ;
    nCoords.y = 1.0-nCoords.y;
    float b = floor(nCoords.x*2);
    float nx = fract(nCoords.x*2);
    float r = floor(nx+0.5);
    float g = floor(nCoords.y+0.5);
 
    gl_FragColor = texture3D(texture0,vec3(r,g,b));
}
Et le résultat obtenu :
Nom : image.PNG
Affichages : 189
Taille : 9,6 Ko

Merci de bien vouloir m'aide à comprendre mon erreur.

Chiyori