Hallo erstmal, ich habe schon seit einigen Tagen das Problem, dass die Shadow Maps, die ich in Java (LWJGL) eingebaut habe, nicht funktionieren.
Hier ist der Code der Render - Passage:
Alles anzeigen
Und hier der Code für das Erstellen des Framebuffers:
Alles anzeigen
Vielen Dank für eure Hilfe
LG
Hier ist der Code der Render - Passage:
Quellcode
- float r = 0.5f;
- float g = 0.8f;
- float b = 1.0f;
- glClearColor(r, g, b, 1);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- int w = Display.getWidth();
- int h = Display.getHeight();
- float aspect = w / (float) h;
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glClearDepth(1.0);
- glShadeModel(GL_SMOOTH);
- if (true) {
- glColorMask(false, false, false, false);
- glViewport(0, 0, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(70, aspect, 0.05f, 1000f);
- glMatrixMode(GL_MODELVIEW);
- for (int i = 0; i < lights.size(); i++) {
- Light light = lights.get(i);
- for (int d = 0; d < 6; d++) {
- glBindFramebuffer(GL_FRAMEBUFFER, cubeMaps[i][d]);
- glClear(GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- if (d == 0) glRotatef(90, 0, 1, 0);
- if (d == 1) glRotatef(270, 0, 1, 0);
- if (d == 2) glRotatef(90, 1, 0, 0);
- if (d == 3) glRotatef(-90, 1, 0, 0);
- if (d == 4) glRotatef(0, 0, 0, 1);
- if (d == 5) glRotatef(180, 0, 0, 1);
- glLight(GL_LIGHT0, GL_POSITION, GLX.getf(0, 0, 0, 1));
- glTranslatef(-(float) light.pos.x, -(float) light.pos.y, -(float) light.pos.z);
- glCallList(displayList);
- }
- }
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- glColorMask(true, true, true, true);
- }
- glViewport(0, 0, w, h);
- glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(70, aspect, 0.05f, 1000f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glRotatef(yRot, 1, 0, 0);
- glRotatef(xRot, 0, 1, 0);
- glTranslatef(-xCam, -yCam, -zCam);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, 0.1f);
- glEnable(GL_COLOR_MATERIAL);
- Shader.depthShader.enable();
- Shader.depthShader.bind("texture", 0);
- glClientActiveTexture(GL_TEXTURE0);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, terrainTexture);
- glEnable(GL_TEXTURE_2D);
- glDisable(GL_LIGHTING);
- glCallList(displayList);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_COLOR_MATERIAL);
- glDisable(GL_ALPHA_TEST);
- glDepthMask(false);
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE);
- glColorMask(true, true, true, true);
- Shader.lightShader.enable();
- Shader.lightShader.bind("shadowMap", 1);
- for (int i = 0; i < lights.size(); i++) {
- glClientActiveTexture(GL_TEXTURE1);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapTextures[i]);
- Light light = lights.get(i);
- float xx = (float) light.pos.x;
- float yy = (float) light.pos.y;
- float zz = (float) light.pos.z;
- float rr = light.r;
- float gg = light.g;
- float bb = light.b;
- glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 1.0f / (light.size));
- glLight(GL_LIGHT0, GL_POSITION, GLX.getf(xx, yy, zz, 1));
- glLight(GL_LIGHT0, GL_DIFFUSE, GLX.getf(rr, gg, bb, 1));
- glLight(GL_LIGHT0, GL_AMBIENT, GLX.getf(0, 0, 0, 1));
- glLight(GL_LIGHT0, GL_SPECULAR, GLX.getf(rr, gg, bb, 1));
- glMaterial(GL_FRONT, GL_SPECULAR, GLX.getf(rr, gg, bb, 1));
- glMaterialf(GL_FRONT, GL_SHININESS, 16.0f);
- glCallList(displayList);
- }
- Shader.lightShader.disable();
- glDepthMask(true);
- glDisable(GL_BLEND);
- glDisable(GL_CULL_FACE);
Und hier der Code für das Erstellen des Framebuffers:
Quellcode
- IntBuffer ib = MemoryTracker.createIntBuffer(6);
- for (int i = 0; i < cubeMaps.length; i++) {
- int shadowMap = cubeMapTextures[i] = glGenTextures();
- ib.clear();
- glGenFramebuffers(ib);
- glBindTexture(GL_TEXTURE_CUBE_MAP, shadowMap);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
- for (int j = 0; j < 6; j++) {
- int id = cubeMaps[i][j] = ib.get(j);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, 0, GL_DEPTH_COMPONENT24, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, 0, GL_DEPTH_COMPONENT, GL_FLOAT, (ByteBuffer) null);
- glBindFramebuffer(GL_FRAMEBUFFER, id);
- glDrawBuffer(GL_NONE);
- glReadBuffer(GL_NONE);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, shadowMap, 0);
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- }
- int error = glGetError();
- if (error != 0) {
- System.out.println(error + ": " + gluErrorString(error));
- }
- }
Vielen Dank für eure Hilfe
LG