Skip to content

Rendering in python without OpenGL/Directx. Only numpy

Notifications You must be signed in to change notification settings

Denizantip/py-numpy-renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

This repo was created only for educational purpose I wanted to understand how the rendering works. It do not have any practiacal sense. It slow as hell. The naming of variables are not the best. But should be quiet clear. Try to go inside the code and read it. The most heavy computation part is shadows. First I've tried shadow map. but the algorithm is looks capricious for me. Thats why switched to Shadow Volume. Result much better and the algorithm is more general but much computationally intensive.

Small Documentation: to render the Wavefron obj model need to perform few steps.

  1. load model
    from core import Model
    some_model = Model.load_model(path_to_model)
    
  2. (Optional step) Apply chain of transformations for model. (Or just one)
    from transformation import scale, translation, rotate
    some_model = some_model @ scale(factor) @ translation((x, y, z)) @ rotate((degrees_x, degrees_y, degrees_z))
    
  3. Create light. (in Scene class will be used default light if not provided)
    from core import Light
    from lightning import Lightning
    
    light = Light(position,               #  position is (x, y, z) coordinates
                  light_type: Lightning,  # type of light (DIRECTIONAL_LIGHTNING, POINT_LIGHTNING, SPOT_LIGHTNING). Default is Lightning.POINT_LIGHTNING
                  center,                 # Coordinates to which it will directed (makes sense for spot and directional light)
    ) 
    
  4. Camera MOTOR!!!
    from core import Camera
    camera = Camera(position,                         # Nothing new
                    center,                           # Coordinated of point to which camera will "look"
                    fovy,                             # field of view in degrees (default is 90)
                    near,                             # near clip plane
                    far,                              # far clip plane
                    backface_culling: bool,           # is faces that "looks" not to camera will be skipped
                    projection_type: PROJECTION_TYPE  #  PERSPECTIVE or ORTHOGRAPHIC
    )
  5. create Scene:
    from core import Scene
    scene = Scene(camera, light, resolution:tuple)  # try to guess what resolution means. I think you can do it!
  6. Add models to scene:
    scene.add_model(some_model)
    scene.add_model(some_another_model)
    ...
  7. Render it.
    frame = scene.render()  #  the frame is numpy array (dtype=uint8) with shape (*resolution, 3)
  8. Save/Convert/visualize the frame. Some examples: Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test

About

Rendering in python without OpenGL/Directx. Only numpy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages