Posts

Showing posts with the label OpenGL

Forward, Deferred and Raytracing rendering in openFrameworks and web

Image
Currently, there are three basic approaches for rendering computer graphics scenes: forward rendering, deferred rendering, raytracing. 1. Forward rendering It's that OpenGL does, you create vertices, then make faces, and rasterize them, all passing via shaders. The rendering process is straightworward and fast, but rendering shadows, making degree-of-field effect and drawing clouds is hard here. Most of openFrameworks examples use forward rendering. 2. Deferred rendering It's the same as forward rendering, but additionally some extra data is rendered for computing shadows. The lighting pass is performed after the scene geometry is drawn. See detailed explanation here: https://learnopengl.com/Advanced-Lighting/Deferred-Shading Shadows, degree-of-field effect and some kind of reflections are possible with deferred rendering. Unreal Engine 4 and Unity currently (2019) are based on deferred rendering. openFrameworks: https://github.com/perevalovds...

Raymarching - a way to liberation of generative graphics

Image
I published this article on openFrameworks forum also. Recently I was so fascinating to work with raymarching technology in oF, that I decide to write this detailed post about it. Such technology allows to render non-rigid objects such as clouds, create dynamic and truly geneative volumes without meshes, and, additionally, very simply render in in VR or 360-degrees panoramic images. It was not so fast to collect all information, so I sure it will be useful for somebody desired to work with in in a modern oF/GLSL. We (art-duet Endless Attractions Museum ) recently released VR art project "Night sleep was taken from my eyes, V.2". In the project we are thinking, how are our memories formed? Is it possible to visualize the amnesia process? What will the storage look like in the future? Wearing the VR HMD, a viewer found himself flying in a cloudy space. Some clouds contain inside transformed panoramic photos illustrating one day in the life of...

Creating panoramic images with raymarching

If we have raymarch shader, it's easy to create a panoramic image with it. Here I will explain how to do it by modifying a GLSL fragment shader which performs raymarching (raycasting, raytracing). 1) In the vertex shader, generate normalized 2D coordinates  pos_normalized at [-1,1]x[-1,1] of the rendered pixel: //Declare variable which will be interpolated and passed into fragment shader     out vec2  pos_normalized; //position [-1,1]x[-1,1] //Inside main() shader's function:     gl_Position = modelViewProjectionMatrix * position; //... some normal code     vec2 pos_normalized = gl_Position.xy/gl_Position.w; 2) In the fragment shader, add uniform for passing center of panoram and also optional rotation of panoram horizontally in degrees; and of course pos_normalized input:     uniform vec3 head_position = vec3(0,0,0);     uniform float panoramic_render_angle...

Using 3D texture in OpenGL/openFrameworks with programmable pipeline

Here we explain how to work with 3D textures using modern OpenGL, verson >= 3.2, using C++ code with openFrameworks. For preparing this text we used several sources: https://stackoverflow.com/questions/13459770/glsl-sampler3d-in-vertex-shader-texture-appears-blank https://en.sfml-dev.org/forums/index.php?topic=23871.0 https://community.khronos.org/t/opengl-3-x-glenable-gl-texture-2d-gl-invalid-enum/61405 https://github.com/tiagosr/ofxShadertoy We will performs the folliwing steps to create and 3D texture for openFrameworks 0.10.1: 1. Enable programmable pipeline 2. Define the function for printing GL errors 3. Create some volume data 4. Create and upload 3D texture 5. Setting 3D texture to shader 6. Create shader files 1. Enable programmable pipeline Be sure you are using programmable pipeline, so in main.cpp, main() use the following code: int main() {     ofGLWindowSettings settings;     se...

Getting maximum possible texture size and GPU memory available

Getting maximum possible texture size Material is based on OpenGL Wiki page: https://www.khronos.org/opengl/wiki/Textures_-_more     int max_tex_size;     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);       cout << "GPU maximal 2D texture size: " << max_tex_size << endl; For 3D texture: GL_MAX_3D_TEXTURE_SIZE For cubemap texture:GL_MAX_CUBE_MAP_TEXTURE_SIZE Getting total and available GPU memory for NVidia cards Material is based on the article How to Know the Graphics Memory Size and Usage In OpenGL by JEGX: https://www.geeks3d.com/20100531/programming-tips-how-to-know-the-graphics-memory-size-and-usage-in-opengl/     #define GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX 0x9048    #define GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX 0x9049     GLint total_mem_kb = 0;     glGetIntegerv(GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX, &total_mem_kb...

Computing ray origin and direction from Model View Projection matrices for raymarching

When performing raymarching (as well a raycasting and raytracing) using fragment shaders in OpenGL, it's required to compute ray's origin and direction. Here we will give solution for finding it from the Model View Projection matrices in OpenGL, implemented in openFrameworks. Using it, you can combine raymarching/raycasting/raytracing with forward OpenGL rendering, so obtain hybrid rendering modes. Also, you can use it for creating VE applications based on raymarching or hybrid rendering. (Actually, we checked what this approach is corrent by creating VR rendering app in HTC Vive). The algorithm can be used on any OpenGL platform with any language supporting matrix inversion computation (in our case it's C++ with GLM library, included in openFrameworks 0.10.1). The approach is based on this hint by  GClements in this discussion on the topic: https://community.khronos.org/t/ray-origin-through-view-and-projection-matrices/7257...