2016-07-03 2 views
1

저는 OpenGL을 사용하는 작은 입자 시스템을 연구 중입니다.
계산 쉐이더의 위치 업데이트가 작동하지 않는 것 같습니다.SSBO 글을 볼 수 없습니다

  1. 버퍼

    struct ParticleInfo { 
    
        Vec4f position; // w: s coordinate 
        Vec4f normal; // w: t coordinate 
        float materialIndex; 
        Vec3f oldPosition; 
    
    }; 
    
  2. 초기화 버퍼 컴퓨 트 쉐이더

    glGenVertexArrays(1, &mParticleVAO); 
    glBindVertexArray(mParticleVAO); 
    
    glGenBuffers(1, &mParticleVBO); 
    glBindBuffer(GL_ARRAY_BUFFER, mParticleVBO); 
    
    glBufferData(GL_ARRAY_BUFFER, sizeof(ParticleInfo) * mNumParticles, particleData.data(), GL_STATIC_DRAW); 
    
    glEnableVertexAttribArray(0); 
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleInfo), (void*)NULL); 
    
    glEnableVertexAttribArray(1); 
    glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleInfo), (void*)(NULL + sizeof(Vec4f))); 
    
    glEnableVertexAttribArray(2); 
    glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleInfo), (void*)(NULL + 2*sizeof(Vec4f))); 
    
    glBindBuffer(GL_ARRAY_BUFFER, 0); 
    glBindVertexArray(0); 
    
  3. 업데이트 버퍼 : 여기

    코드입니다 @derhass은 주석으로 127,125,683,210
  4. 쉐이더 코드는

    #version 450 
    
    layout(local_size_x = 64) in; 
    
    struct ParticleInfo { 
    
        vec4 position; // modify only the position; 
        vec4 normal; 
        float materialIndex; 
        vec3 oldPosition; 
    
    }; 
    
    struct Attractor { 
    
        vec3 position; 
        float mass; 
    
    }; 
    
    layout(binding = 0, std430) buffer ParticleArray { 
    
        ParticleInfo particles[]; 
    
    }; 
    
    layout(binding = 1, std430) buffer AttractorArray { 
    
        Attractor attractors[]; 
    
    }; 
    
    uniform int numParticles; 
    
    
    vec3 verlet(in vec3 a, in vec3 x, in vec3 xOld, in float dt) { 
    
        return 2.0 * x - xOld + a * dt*dt; 
    
    } 
    
    void main() { 
    
        const int PARTICLES_PER_THREAD = 8; 
    
        int index = int(gl_LocalInvocationIndex)*PARTICLES_PER_THREAD; 
    
        if (index >= numParticles) return; 
    
        Attractor attr = attractors[0]; 
    
        const float G = 9.8; 
    
        for (int i = 0; i < PARTICLES_PER_THREAD; ++i) 
        { 
    
    
         particles[i+index].position = vec4(0.0); 
         particles[i+index].normal = vec4(0.0); 
         particles[i+index].oldPosition = vec3(0.0); 
        } 
    
    
    
    } 
    
+0

작동하지 않음 : 입자가 모두 0으로 설정되도록하려는 동일한 초기 위치에 남아 있음을 의미합니다. –

+0

어떻게 동일한 위치에 있다는 것을 알고 계십니까? 당신은 그것을 렌더링하고 움직이는 것을 보지 않습니까? –

+0

입자가 특정 모양을 닮았습니다. 그것들은 모두 일부 메쉬의 삼각형에서 샘플링됩니다. –

답변

1

때문이다. 메모리 구조가 일치하지 않습니다. 스레드 당 적절한 색인 생성에도 문제가있는 것으로 보입니다. 스레드 당 인덱스를 다음과 같이 설정하여 문제를 해결했습니다.

index = PARTICLES_PER_THREAD * int(gl_WorkGroupSize.x * gl_WorkGroupID.x + gl_LocalInvocationID.x); 

감사합니다.