Attention

You are viewing PyUnity docs under the develop branch. As such, they are only applicable if you installed from source. Go to https://docs.pyunity.x10.bz/en/latest/ for the most recent release.

pyunity.render module


Classes to aid in rendering in a Scene.

pyunity.render.fillScreen(scale=1)[source]
class pyunity.render.Shader[source]

Bases: object

VERSION = '1.10'

Type:    str

loadCache(file)[source]
compile()[source]

Compiles shader and generates program. Checks for errors.

Notes

This function will not work if there is no active framebuffer.

static fromFolder(path, name)[source]

Create a Shader from a folder. It must contain vertex.glsl and fragment.glsl.

Parameters:
  • path (str) – Path of folder to load

  • name (str) – Name to register this shader to. Used with Camera.SetShader().

setVec3(var, val)[source]

Set a vec3 uniform variable.

Parameters:
  • var (bytes) – Variable name

  • val (Vector3) – Value of uniform variable

setMat3(var, val)[source]

Set a mat3 uniform variable.

Parameters:
  • var (bytes) – Variable name

  • val (glm.mat3) – Value of uniform variable

setMat4(var, val)[source]

Set a mat4 uniform variable.

Parameters:
  • var (bytes) – Variable name

  • val (glm.mat4) – Value of uniform variable

setInt(var, val)[source]

Set an int uniform variable.

Parameters:
  • var (bytes) – Variable name

  • val (int) – Value of uniform variable

setFloat(var, val)[source]

Set a float uniform variable.

Parameters:
  • var (bytes) – Variable name

  • val (float) – Value of uniform variable

use()[source]

Compile shader if it isn’t compiled, and load it into OpenGL.

pyunity.render.compileShaders()[source]
pyunity.render.compileSkyboxes()[source]
pyunity.render.resetShaders()[source]
pyunity.render.resetSkyboxes()[source]
class pyunity.render.LightType[source]

Bases: IntEnum

An enumeration.

Point = 0

Type:    int

Directional = 1

Type:    int

Spot = 2

Type:    int

class pyunity.render.Light[source]

Bases: SingleComponent

Component to hold data about the light in a scene.

intensity = 20

Intensity of light

Type:

int

color = RGB(255, 255, 255)

Light color (will mix with material color)

Type:

Color

type = LightType.Directional

Type of light (currently only Point and Directional are supported)

Type:

LightType

setupBuffers(depthMapSize)[source]
class pyunity.render.Camera[source]

Bases: SingleComponent

Component to hold data about the camera in a scene.

near = 0.05

Distance of the near plane in the camera frustrum. Defaults to 0.05.

Type:

float

far = 200.0

Distance of the far plane in the camera frustrum. Defaults to 100.

Type:

float

clearColor = None

The clear color of the camera. Defaults to black.

Type:

Color

shader = <pyunity.render.Shader object at 0x7fc4aa68ee80>

The shader to use for 3D objects.

Type:

Shader

skyboxEnabled = True

Toggle skybox on or off. Defaults to True.

Type:

bool

skybox = <pyunity.files.Skybox object at 0x7fc4aa654460>

Selected skybox to render.

Type:

Skybox

ortho = False

Orthographic or perspective proection. Defaults to False.

Type:

bool

customProjMat

If not None, will be used over any other type of projection matrix. Unavailable from the Editor and also not saved.

Type:

glm.mat4 or None

shadows = False

Whether to render depthmaps and use them. Defaults to True.

Type:

bool

canvas = None

Target canvas to render. Defaults to None.

Type:

Canvas

depthMapSize = 1024

Depth map texture size. Do not modify after scene has started. Defaults to 1024.

Type:

int

setupBuffers()[source]

Creates 2D quad VBO and VAO for GUI.

property fov

FOV of camera

property orthoSize
Resize(width, height)[source]

Resizes the viewport on screen size change.

Parameters:
  • width (int) – Width of new window

  • height (int) – Height of new window

getMatrix(transform)[source]

Generates model matrix from transform.

get2DMatrix(rectTransform)[source]

Generates model matrix from RectTransform.

getViewMat()[source]

Generates view matrix from Transform of camera.

UseShader(name)[source]

Sets current shader from name.

SetupShader(lights)[source]
SetupDepthShader(light)[source]
Draw(renderers)[source]

Draw specific renderers, taking into account light positions.

Parameters:

renderers (List[MeshRenderer]) – Which meshes to render

DrawDepth(renderers)[source]
RenderDepth(renderers, lights)[source]
RenderScene(renderers, lights)[source]
Render(renderers, lights)[source]
RenderSkybox()[source]
Render2D()[source]

Draw all Image2D and Text components in the Camera’s target canvas.

If the Camera has no Canvas, this function does nothing.

Setup2D()[source]
Draw2D(renderers)[source]
class pyunity.render.Screen[source]

Bases: object

width = 800

Type:    int

height = 500

Type:    int

size = Vector2(800, 500)

Type:    Vector2

aspect = 1.6

Type:    float