Help finding the right code for cameras

Hi, new to blenderartist. Looking to see if anybody knows the answer to my issue after not being able to get it working.

I want to edit the orthographic projection matrix of the camera or basically add a few matrix in before the orthographic projection.

Started off using the matrix to skew the mesh so it looked like an oblique projection in the top orthographic camera. Worked ok but I wanted to be able to work with a normal mesh and just skew the projection.

I did manage to do this using gpu in python (see image) still using the top orthographic camera and skewing the matrix before the projection but that seems to only be able to render the viewport. It is a possible solution but I would really like to work with a renderable camera.

Started looking into the blender code. Not really sure what I am doing but tried two different builds. One editing the cycles util_projection.h that didn’t seem to do anything.

	ccl_device_inline ProjectionTransform projection_orthographic(float znear, float zfar)
	{
	  Transform t = transform_scale(1.0f, 1.0f, 1.0f / (zfar - znear)) *
	                transform_translate(0.0f, 0.0f, -znear) *
                        #MyCode
                        make_transform(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f) *
                        make_transform(1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
                        #EndMyCode 
	
	  return ProjectionTransform(t);

Another try editing the blenderlib math_geom.c to just add my matrix to that. Not sure I did the multiplication right. I believe there should be somewhere I can do this but maybe it’s not that simple… Any help is much appreciated.

void orthographic_m4(float matrix[4][4],
                     const float left,
                     const float right,
                     const float bottom,
                     const float top,
                     const float nearClip,
                     const float farClip)
{
  float Xdelta, Ydelta, Zdelta;

  Xdelta = right - left;
  Ydelta = top - bottom;
  Zdelta = farClip - nearClip;
  if (Xdelta == 0.0f || Ydelta == 0.0f || Zdelta == 0.0f) {
    return;
  }
  unit_m4(matrix);
  matrix[0][0] = 2.0f / Xdelta;
  matrix[2][0] = 1.0f;
  matrix[3][0] = -(right + left) / Xdelta;
  matrix[1][1] = 2.0f / Ydelta;
  matrix[2][1] = 1.0f;
  matrix[3][1] = -(top + bottom) / Ydelta;
  matrix[2][2] = -0.9f / Zdelta; /* note: negate Z */
  matrix[3][2] = -(farClip + nearClip) / Zdelta;
}

Well, I tried adding it to gpu_matrix.c and managed to get something to happen! I mean the cube doesn’t look cube shaped but it’s in the right skew. Doesn’t actually render any different so not the right place :sweat_smile:

After some more testing it seems math_geom.c is the right place for the eevee render. Manged to get it working using this code.

  unit_m4(matrix);
  matrix[0][0] = 2.0f / Xdelta;
  matrix[2][0] = -1.0f;
  matrix[3][0] = -(right + left) / Xdelta;
  matrix[1][1] = 2.0f / Ydelta;
  matrix[2][1] = 1.0f;
  matrix[3][1] = -(top + bottom) / Ydelta;
  matrix[2][2] = -2.0f / Zdelta; /* note: negate Z */
  matrix[3][2] = -(farClip + nearClip) / Zdelta;

Still haven’t figured out where is the right place in cycles yet. Here’s the render results from a cube. Something weird going on somewhere as when you change the resolution the cube moves and it’s off centre but that might take some figuring out. For now it sortof works :smile:

1 Like