Pre rendered graphics game dev. Wanting to add a setting to anchor orthographic scale to render resolution

I’m working on assets for a pre-rendered graphics game (ie old school diablo 1-2, runescape, etc). An issue I keep running into is orthographic camera scale:

image

The setting is such that it is independent of resolution (Output > Format > Resolution). This makes sense from an animation perspective, changing the resolution should not change the zoom level. But from a pre-rendered graphics perspective, it’s a bit of a hassle. I have no easy way to assert that 100 pixels.x == 1 meter, for instance.

What I have to do right now for each model is:

  1. zoom in
  2. modify resolution to change the x/y scale of my framing
  3. repeat 1 and 2 until I get a nice crop
  4. whichever resolution is bigger (x or y) set that to being equal to some constant * my scale (for instance, at a scale of 1 I know that my biggest resolution should be 100 pixels)
  5. re-scale my resolution (the smaller one) to have the correct framing
  6. done

What I would prefer is a checkbox that switches to a “pixels per meter” mode. At 100 px per meter, looking perpendicularly at a flat plane of 1m x 1m, each pixel in the rendered output would be .01 meters. A render resolution of 100 x 100 would just fit the whole plane. A resolution of 50 x 50 would crop to a smaller portion of the plane. Changing resolution would act like cropping (ie zooming).


Before getting started, does this seem like a feasible first project? I’m a dev with 20 years experience, but I know most of this is about navigating a large unfamiliar codebase.

Also – if it is feasible – is this more of an add-on, or actual change to Blender?

Or, perhaps, is this better done as a script? Once I have my framing figured out, changing the output resolution to be correct is only a matter of simple math.

Nothing like explaining an idea to realize it isn’t necessary. How do I delete a post?

Also, here’s the script:

import bpy

def update_resolution_from_orthographic_camera():
    # Get the active scene
    scene = bpy.context.scene
    
    # Find the active camera
    camera = scene.camera
    
    if not camera:
        print("No active camera found!")
        return
    
    # Check if the camera is orthographic
    if camera.data.type != 'ORTHO':
        print("Active camera is not orthographic!")
        return
    
    # Get the orthographic scale (zoom level)
    ortho_scale = camera.data.ortho_scale
    
    # Define your desired resolution per orthographic scale unit
    # For example, 100 pixels per Blender unit
    pixels_per_unit = 128/1.1
    
    # Calculate resolution
    resolution_x = int(ortho_scale * pixels_per_unit)
    resolution_y = int(ortho_scale * pixels_per_unit * (scene.render.resolution_y / scene.render.resolution_x))
    
    # Apply the resolution to the render settings
    scene.render.resolution_x = resolution_x
    scene.render.resolution_y = resolution_y
    
    print(f"Updated resolution: {resolution_x}x{resolution_y} based on orthographic scale {ortho_scale}")

# Run the function
update_resolution_from_orthographic_camera()

4 Likes

Rubber duck debugging, FTW! :slight_smile:

Out of interest - why did you set pixels per unit divided by 1.1?

  pixels_per_unit = 128/1.1

A very-particularly-stretched hexagon rotated 15 degrees then zoomed to 1.1 fits well in a 128 px wide sprite square :stuck_out_tongue:

2 Likes

Better leave it up. Someone else might need the same thing,
as it’s a bit offtopic, I’ll close the thread.

3 Likes