environment.yml for vid2vid for easier setup

Vid2vid seems to be a promising technique for video synthesis using GANs, as of 2019, which is similar in spirit to it’s image counterpart, pix2pix. When setting this up, I found there are some additional requirements needed, than what’s stated at: https://github.com/NVIDIA/vid2vid.

I created my own environment.yml to make this setup easier (pytorch is specifically for CUDA 9.1, CUDNN 7.1.2, but you can edit the yml file and swap out this version based on the available pytorch versions, and it should work).

The gist is available at: https://gist.github.com/tharindu-mathew/7f79433d92d884fa662f6ccf023537e1

How to improve your shadows – Understanding the light projection matrix

When using shadow mapping, the resolution of your shadow buffer is lower than your default color buffer resulting in a low resolution shadow. But, this effect can be somewhat mitigated by programatically computing your light projection matrix so it covers the minimal volume possible.

In the above images, the buffer of the shadow resolution is the same. But, the bounds use for the computation of the light matrix (light_projection_matrix * light_view_matrix) differs. For the high res shadows on the right, the light projection matrix is controlled by the bounds of the view frustrum. In terms of a directional light, this will be an orthographic matrix, and the bounds of the light be the bounds of the viewing frustrum (which can be perspective or orthographic). This makes the resolution of the shadows far more high-res as only a smaller portion of your scene is considered. So, if you choose a reasonable resolution and use a bounds-aware light projection matrix you get good use resolution of your shadows. This can vary for level of detail that you shoot for based on the zoom of your camera.

Binding to framebuffer 0 may cause a blank screen


Today, I encountered an interesting issue that took away a few hours of my (not so) precious life, to debug and understand. I was implementing some basic shadow mapping, which requires you to create a new render target (meaning you need to render to a separate buffer other than the screen). So, we have to switch back and forth between framebuffers. Most OpenGL tutorials out there will simply ask you to bind back to the default framebuffer 0.

Here’s a code excerpt from learnopengl.com site (as of 11/16/2018) from their article on shadow mapping (I love this site, and this in no way a criticism of their content, just using it to point to a probably bug). https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping

// 1. first render to depth map
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glClear(GL_DEPTH_BUFFER_BIT);
ConfigureShaderAndMatrices();
RenderScene();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
// 2. then render scene as normal with shadow mapping (using depth map)
glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ConfigureShaderAndMatrices();
glBindTexture(GL_TEXTURE_2D, depthMap);
RenderScene();

Binding back to framebuffer 0, as mentioned here, simply output a blank screen for me. And I went through a period of commenting out all my rendering code and enabling line by line (costing me half a day or more) to see what was going wrong. I found the culprit in the line: glBindFramebuffer(GL_FRAMEBUFFER, 0);. Then I suddenly got an idea and executed these lines to find my actual default framebuffer (after disabling any shadow mapping code and simply doing a simple setup for single pass rendering):


glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &default_draw_fbo_);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &default_read_fbo_);

And to my surprise, the answer was 3. With allocating a new framebuffer for shadow mapping, this went up to 4 (weird!). I’m using Qt 5.11 as my application framework, and I’m not sure whether this is a bug/feature or what (maybe they use framebuffer 0 to render their own stuff). But, it seems that the default framebuffer cannot be assumed to be 0.

So, if you’re experiencing a blank screen when trying to a render anything that causes you to switch between framebuffers, make sure you find out what exactly you’re default framebuffer ID is. Then, just switch back to this known number, and all will be well.


// also GL_FRAMEBUFFER is deprecated now, simply use
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, default_draw_fbo_);

 

HTH.

A comparison with and without normal maps

I implemented a normal map into my tiny graphics engine (I’ve gotten by mostly with phong shading for my research work, so yeah I should do more graphics stuff I thought), and also to learn about tangent space. I saw firsthand the remarkable difference a normal map brings.

Map without normal map

without-normal-map

Map with normal map (same lighting as above)

with-normal-map

It’s pretty cool how much more detail a normal map brings into your models. Hope to integrate more features like this.

Loading Shininess in Materials when using Assimp

I was looking around on how to get the shininess (aka the specular coefficient, specular exponent) from a loaded model, when using the Assimp APIs (4.1.0). Unfortunately, nothing in the docs helped me and I had to look into some sample programs to get the answer. So, here’s how to do it:

// material index is the ID of the material you are interested in
	const aiMaterial* ai_material = scene.mMaterials[material_index];
float shininess;
if(AI_SUCCESS != aiGetMaterialFloat(ai_material, AI_MATKEY_SHININESS, &shininess))
    {
// if unsuccessful set a default
shininess = 20.f;
    }

Here’s an example to get some other property like specular color using Assimp’s structs.

aiColor4D spec_color;
 if(AI_SUCCESS != aiGetMaterialColor(ai_material, AI_MATKEY_COLOR_SPECULAR,
        &spec_color))
    {
        spec_color = aiColor4D(1.f, 1.f, 1.f, 1.f);
    }

HTH