Reviewed shaders_deferred_render (#4676)
Fixed: g-buffer textures binding Fixed: Clearing screen with white would leak onto g-buffer textures Reviewed comments
This commit is contained in:
parent
34f431b422
commit
08b089f620
1 changed files with 17 additions and 17 deletions
|
@ -134,14 +134,15 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we initialize the sampler2D uniform's in the deferred shader.
|
// Now we initialize the sampler2D uniform's in the deferred shader.
|
||||||
// We do this by setting the uniform's value to the color channel slot we earlier
|
// We do this by setting the uniform's values to the texture units that
|
||||||
// bound our textures to.
|
// we later bind our g-buffer textures to.
|
||||||
rlEnableShader(deferredShader.id);
|
rlEnableShader(deferredShader.id);
|
||||||
|
int texUnitPosition = 0;
|
||||||
rlSetUniformSampler(rlGetLocationUniform(deferredShader.id, "gPosition"), 0);
|
int texUnitNormal = 1;
|
||||||
rlSetUniformSampler(rlGetLocationUniform(deferredShader.id, "gNormal"), 1);
|
int texUnitAlbedoSpec = 2;
|
||||||
rlSetUniformSampler(rlGetLocationUniform(deferredShader.id, "gAlbedoSpec"), 2);
|
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gPosition"), &texUnitPosition, RL_SHADER_UNIFORM_SAMPLER2D);
|
||||||
|
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gNormal"), &texUnitNormal, RL_SHADER_UNIFORM_SAMPLER2D);
|
||||||
|
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gAlbedoSpec"), &texUnitAlbedoSpec, RL_SHADER_UNIFORM_SAMPLER2D);
|
||||||
rlDisableShader();
|
rlDisableShader();
|
||||||
|
|
||||||
// Assign out lighting shader to model
|
// Assign out lighting shader to model
|
||||||
|
@ -208,11 +209,10 @@ int main(void)
|
||||||
// Draw
|
// Draw
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
|
||||||
|
|
||||||
// Draw to the geometry buffer by first activating it
|
// Draw to the geometry buffer by first activating it
|
||||||
rlEnableFramebuffer(gBuffer.framebuffer);
|
rlEnableFramebuffer(gBuffer.framebuffer);
|
||||||
|
rlClearColor(0, 0, 0, 0);
|
||||||
rlClearScreenBuffers(); // Clear color and depth buffer
|
rlClearScreenBuffers(); // Clear color and depth buffer
|
||||||
|
|
||||||
rlDisableColorBlend();
|
rlDisableColorBlend();
|
||||||
|
@ -246,14 +246,14 @@ int main(void)
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
rlDisableColorBlend();
|
rlDisableColorBlend();
|
||||||
rlEnableShader(deferredShader.id);
|
rlEnableShader(deferredShader.id);
|
||||||
// Activate our g-buffer textures
|
// Bind our g-buffer textures
|
||||||
// These will now be bound to the sampler2D uniforms `gPosition`, `gNormal`,
|
// We are binding them to locations that we earlier set in sampler2D uniforms `gPosition`, `gNormal`,
|
||||||
// and `gAlbedoSpec`
|
// and `gAlbedoSpec`
|
||||||
rlActiveTextureSlot(0);
|
rlActiveTextureSlot(texUnitPosition);
|
||||||
rlEnableTexture(gBuffer.positionTexture);
|
rlEnableTexture(gBuffer.positionTexture);
|
||||||
rlActiveTextureSlot(1);
|
rlActiveTextureSlot(texUnitNormal);
|
||||||
rlEnableTexture(gBuffer.normalTexture);
|
rlEnableTexture(gBuffer.normalTexture);
|
||||||
rlActiveTextureSlot(2);
|
rlActiveTextureSlot(texUnitAlbedoSpec);
|
||||||
rlEnableTexture(gBuffer.albedoSpecTexture);
|
rlEnableTexture(gBuffer.albedoSpecTexture);
|
||||||
|
|
||||||
// Finally, we draw a fullscreen quad to our default framebuffer
|
// Finally, we draw a fullscreen quad to our default framebuffer
|
||||||
|
@ -269,8 +269,8 @@ int main(void)
|
||||||
rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT
|
rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT
|
||||||
rlDisableFramebuffer();
|
rlDisableFramebuffer();
|
||||||
|
|
||||||
// Since our shader is now done and disabled, we can draw our lights in default
|
// Since our shader is now done and disabled, we can draw spheres
|
||||||
// forward rendering
|
// that represent light positions in default forward rendering
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
rlEnableShader(rlGetShaderIdDefault());
|
rlEnableShader(rlGetShaderIdDefault());
|
||||||
for(int i = 0; i < MAX_LIGHTS; i++)
|
for(int i = 0; i < MAX_LIGHTS; i++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue