从计算着色器生成深度图

问题描述 投票:0回答:0
我对 opengl 很陌生,尤其是在纹理和贴图方面

const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;

unsigned int depthMapFBO; glGenFramebuffers(1, &depthMapFBO); // create depth texture unsigned int depthMap; glGenTextures(1, &depthMap); glBindTexture(GL_TEXTURE_2D, depthMap); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // attach depth texture as FBO's depth buffer glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0); glDrawBuffer(GL_NONE); glReadBuffer(GL_NONE); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); glClear(GL_DEPTH_BUFFER_BIT); glActiveTexture(GL_TEXTURE0);

渲染场景(简单深度着色器);

glBindFramebuffer(GL_FRAMEBUFFER,0); glBindFramebuffer(GL_FRAMEBUFFER,0);

glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glActiveTexture(GL_TEXTURE1);

glBindTexture(GL_TEXTURE_2D, depthMap);

renderScene(makeshadow);

第一次通过(simpleDepthShader)**着色器生成深度图,第二次通过**(makeshadow)**着色器使用深度图并在片段着色器中制作阴影

我如何使用从第一个着色器通道生成的深度图**(simpleDepthShader)**,然后将其作为第二个着色器通道传递给计算着色器,然后将其复制到计算着色器中,深度图的新副本将通过

(makeshadow)shader

c++ opengl texture-mapping basic compute-shader
© www.soinside.com 2019 - 2024. All rights reserved.