mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Framebuffer rendering on quad is now working! 😂
This commit is contained in:
@@ -169,10 +169,13 @@ class IMICFPS
|
|||||||
|
|
||||||
def configure_vao
|
def configure_vao
|
||||||
glBindVertexArray(@vertex_array_id)
|
glBindVertexArray(@vertex_array_id)
|
||||||
|
gl_error?
|
||||||
|
|
||||||
# index, size, type, normalized, stride, pointer
|
# index, size, type, normalized, stride, pointer
|
||||||
# vertices (positions)
|
# vertices (positions)
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
||||||
|
gl_error?
|
||||||
|
|
||||||
# inPosition
|
# inPosition
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
||||||
gl_error?
|
gl_error?
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ class IMICFPS
|
|||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
@uvs = [
|
@uvs = [
|
||||||
|
0, 0,
|
||||||
|
1, 0,
|
||||||
0, 1,
|
0, 1,
|
||||||
1, 1,
|
|
||||||
0, 0,
|
|
||||||
|
|
||||||
0, 0,
|
0, 1,
|
||||||
1, 1,
|
1, 0,
|
||||||
1, 0
|
1, 1
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
create_framebuffer
|
create_framebuffer
|
||||||
@@ -43,7 +43,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_framebuffer
|
def create_framebuffer
|
||||||
buffer = ' ' * 8
|
buffer = ' ' * 4
|
||||||
glGenFramebuffers(1, buffer)
|
glGenFramebuffers(1, buffer)
|
||||||
@framebuffer = buffer.unpack('L2').first
|
@framebuffer = buffer.unpack('L2').first
|
||||||
|
|
||||||
@@ -80,17 +80,19 @@ class IMICFPS
|
|||||||
|
|
||||||
def create_textures
|
def create_textures
|
||||||
@buffers.size.times do |i|
|
@buffers.size.times do |i|
|
||||||
buffer = ' ' * 8
|
buffer = ' ' * 4
|
||||||
glGenTextures(1, buffer)
|
glGenTextures(1, buffer)
|
||||||
texture_id = buffer.unpack('L2').first
|
texture_id = buffer.unpack('L2').first
|
||||||
@textures[@buffers[i]] = texture_id
|
@textures[@buffers[i]] = texture_id
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture_id)
|
glBindTexture(GL_TEXTURE_2D, texture_id)
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nil)
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nil)
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texture_id, 0)
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, texture_id, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
buffer = ' ' * 8
|
buffer = ' ' * 4
|
||||||
glGenTextures(1, buffer)
|
glGenTextures(1, buffer)
|
||||||
texture_id = buffer.unpack('L2').first
|
texture_id = buffer.unpack('L2').first
|
||||||
@textures[:depth] = texture_id
|
@textures[:depth] = texture_id
|
||||||
@@ -104,7 +106,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_screen_vbo
|
def create_screen_vbo
|
||||||
buffer = ' ' * 8
|
buffer = ' ' * 4
|
||||||
glGenVertexArrays(1, buffer)
|
glGenVertexArrays(1, buffer)
|
||||||
@screen_vbo = buffer.unpack('L2').first
|
@screen_vbo = buffer.unpack('L2').first
|
||||||
|
|
||||||
@@ -125,6 +127,7 @@ class IMICFPS
|
|||||||
glBufferData(GL_ARRAY_BUFFER, @uvs.size * Fiddle::SIZEOF_FLOAT, @uvs.pack("f*"), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, @uvs.size * Fiddle::SIZEOF_FLOAT, @uvs.pack("f*"), GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nil)
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, nil)
|
||||||
|
|
||||||
|
glBindVertexArray(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def bind_for_writing
|
def bind_for_writing
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class IMICFPS
|
|||||||
@g_buffer.bind_for_writing
|
@g_buffer.bind_for_writing
|
||||||
gl_error?
|
gl_error?
|
||||||
|
|
||||||
|
glClearColor(0.0, 0.0, 0.0, 0.0)
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||||
|
|
||||||
Shader.use("default") do |shader|
|
Shader.use("default") do |shader|
|
||||||
@@ -47,9 +48,15 @@ class IMICFPS
|
|||||||
@g_buffer.unbind_framebuffer
|
@g_buffer.unbind_framebuffer
|
||||||
gl_error?
|
gl_error?
|
||||||
|
|
||||||
lighting(lights)
|
|
||||||
|
@g_buffer.bind_for_reading
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)
|
||||||
|
|
||||||
|
# lighting(lights)
|
||||||
post_processing
|
post_processing
|
||||||
render_framebuffer
|
render_framebuffer
|
||||||
|
|
||||||
|
@g_buffer.unbind_framebuffer
|
||||||
gl_error?
|
gl_error?
|
||||||
else
|
else
|
||||||
puts "Shader 'default' failed to compile, using immediate mode for rendering..." unless @@immediate_mode_warning
|
puts "Shader 'default' failed to compile, using immediate mode for rendering..." unless @@immediate_mode_warning
|
||||||
@@ -82,11 +89,24 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def lighting(lights)
|
def lighting(lights)
|
||||||
@g_buffer.bind_for_reading
|
@g_buffer.set_read_buffer(:position)
|
||||||
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
|
0, 0, @g_buffer.width / 2, @g_buffer.height / 2,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
|
|
||||||
@g_buffer.set_read_buffer(:diffuse)
|
@g_buffer.set_read_buffer(:diffuse)
|
||||||
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
0, 0, @g_buffer.width / 2, @g_buffer.height / 2,
|
0, @g_buffer.height / 2, @g_buffer.width / 2, @g_buffer.height,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
|
|
||||||
|
@g_buffer.set_read_buffer(:normal)
|
||||||
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
|
@g_buffer.width / 2, @g_buffer.height / 2, @g_buffer.width, @g_buffer.height,
|
||||||
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
|
|
||||||
|
@g_buffer.set_read_buffer(:texcoord)
|
||||||
|
glBlitFramebuffer(0, 0, @g_buffer.width, @g_buffer.height,
|
||||||
|
@g_buffer.width / 2, 0, @g_buffer.width, @g_buffer.height / 2,
|
||||||
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
GL_COLOR_BUFFER_BIT, GL_LINEAR)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -101,8 +121,16 @@ class IMICFPS
|
|||||||
glEnableVertexAttribArray(1)
|
glEnableVertexAttribArray(1)
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST)
|
glDisable(GL_DEPTH_TEST)
|
||||||
|
glEnable(GL_BLEND)
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0)
|
||||||
glBindTexture(GL_TEXTURE_2D, @g_buffer.texture(:diffuse))
|
glBindTexture(GL_TEXTURE_2D, @g_buffer.texture(:diffuse))
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, @g_buffer.vertices.size)
|
glDrawArrays(GL_TRIANGLES, 0, @g_buffer.vertices.size)
|
||||||
|
|
||||||
|
glDisableVertexAttribArray(1)
|
||||||
|
glDisableVertexAttribArray(0)
|
||||||
|
glBindVertexArray(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class IMICFPS
|
|||||||
|
|
||||||
array_of_pixels = texture.to_blob
|
array_of_pixels = texture.to_blob
|
||||||
|
|
||||||
tex_names_buf = ' ' * 8
|
tex_names_buf = ' ' * 4
|
||||||
glGenTextures(1, tex_names_buf)
|
glGenTextures(1, tex_names_buf)
|
||||||
texture_id = tex_names_buf.unpack('L2').first
|
texture_id = tex_names_buf.unpack('L2').first
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
@include "light_struct"
|
@include "light_struct"
|
||||||
|
|
||||||
// layout(location = 0) out vec4 fragColor;
|
layout(location = 0) out vec3 fragPosition;
|
||||||
layout (location = 1) out vec3 fragColor;
|
layout (location = 1) out vec4 fragColor;
|
||||||
|
layout (location = 2) out vec3 fragNormal;
|
||||||
|
layout (location = 3) out vec3 fragUV;
|
||||||
|
|
||||||
in vec3 outPosition;
|
in vec3 outPosition;
|
||||||
in vec3 outColor;
|
in vec3 outColor;
|
||||||
@@ -99,5 +101,8 @@ void main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fragColor = vec3(1,1,1);//result;
|
fragPosition = outPosition;
|
||||||
|
fragColor = vec4(result, 1.0);
|
||||||
|
fragNormal = outNormal;
|
||||||
|
fragUV = outUV;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user