You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Implemented a very simple SSAO in GLES3.
This commit is contained in:
@@ -87,7 +87,11 @@ void PostEffects::_draw_screen_triangle() {
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void PostEffects::post_copy(GLuint p_dest_framebuffer, Size2i p_dest_size, GLuint p_source_color, Size2i p_source_size, float p_luminance_multiplier, const Glow::GLOWLEVEL *p_glow_buffers, float p_glow_intensity, float p_srgb_white, uint32_t p_view, bool p_use_multiview, uint64_t p_spec_constants) {
|
||||
void PostEffects::post_copy(
|
||||
GLuint p_dest_framebuffer, Size2i p_dest_size, GLuint p_source_color,
|
||||
GLuint p_source_depth, bool p_ssao_enabled, int p_ssao_quality_level, float p_ssao_strength, float p_ssao_radius,
|
||||
Size2i p_source_size, float p_luminance_multiplier, const Glow::GLOWLEVEL *p_glow_buffers, float p_glow_intensity,
|
||||
float p_srgb_white, uint32_t p_view, bool p_use_multiview, uint64_t p_spec_constants) {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_BLEND);
|
||||
@@ -103,6 +107,19 @@ void PostEffects::post_copy(GLuint p_dest_framebuffer, Size2i p_dest_size, GLuin
|
||||
if (p_glow_buffers != nullptr) {
|
||||
flags |= PostShaderGLES3::USE_GLOW;
|
||||
}
|
||||
if (p_ssao_enabled) {
|
||||
if (p_ssao_quality_level == RS::ENV_SSAO_QUALITY_VERY_LOW) {
|
||||
flags |= PostShaderGLES3::USE_SSAO_ABYSS;
|
||||
} else if (p_ssao_quality_level == RS::ENV_SSAO_QUALITY_LOW) {
|
||||
flags |= PostShaderGLES3::USE_SSAO_LOW;
|
||||
} else if (p_ssao_quality_level == RS::ENV_SSAO_QUALITY_HIGH) {
|
||||
flags |= PostShaderGLES3::USE_SSAO_HIGH;
|
||||
} else if (p_ssao_quality_level == RS::ENV_SSAO_QUALITY_ULTRA) {
|
||||
flags |= PostShaderGLES3::USE_SSAO_MEGA;
|
||||
} else {
|
||||
flags |= PostShaderGLES3::USE_SSAO_MED;
|
||||
}
|
||||
}
|
||||
if (p_luminance_multiplier != 1.0) {
|
||||
flags |= PostShaderGLES3::USE_LUMINANCE_MULTIPLIER;
|
||||
}
|
||||
@@ -118,6 +135,20 @@ void PostEffects::post_copy(GLuint p_dest_framebuffer, Size2i p_dest_size, GLuin
|
||||
glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
if (p_ssao_enabled) {
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(texture_target, p_source_depth);
|
||||
glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Thanks to mrjustaguy!
|
||||
glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
post.shader.version_set_uniform(PostShaderGLES3::SSAO_INTENSITY, p_ssao_strength, post.shader_version, mode, flags);
|
||||
post.shader.version_set_uniform(PostShaderGLES3::SSAO_RADIUS_FRAC, p_ssao_radius, post.shader_version, mode, flags);
|
||||
post.shader.version_set_uniform(PostShaderGLES3::SSAO_PRN_UV, // This converts the UV coordinate into a pseudo-random number.
|
||||
p_source_size.x * 1.087f * ((1.0f + sqrt(5.0f)) / 2.0f),
|
||||
p_source_size.y * 1.087f * ((9.0f + sqrt(221.0f)) / 10.0f),
|
||||
post.shader_version, mode, flags);
|
||||
}
|
||||
|
||||
if (p_glow_buffers != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, p_glow_buffers[0].color);
|
||||
@@ -137,6 +168,10 @@ void PostEffects::post_copy(GLuint p_dest_framebuffer, Size2i p_dest_size, GLuin
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
if (p_ssao_enabled) {
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(texture_target, 0);
|
||||
}
|
||||
|
||||
// Return back to nearest
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
Reference in New Issue
Block a user