Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Model Displayable

The Model displayable acts as a factory to created models for use with the model-based renderer.
class Model(size=None, **properties)

This is a displayable that causes Ren'Py to create a 2D or 3D model for use with the model-based
renderer, that will be drawn in a single operation with the shaders given here, or selected by an
enclosing Transform or Displayable.

size
If not None, this should be a width, height tuple, that's used to give the size of the Model. If
not given, the model is the size of the area provided to it. The fit parameter to a texture
takes precedence.

If no mesh method is called, a mesh that sets a_position and a_tex_coord to match the way
Ren'Py loads textures is created if at least one texture is supplied. Otherwise, a mesh that only
sets a_position is used.

All methods on this calls return the displayable the method is called on, making it possible to
chain calls.

child(displayable, fit=False)

This is the same as the texture method, except that the focus and main parameters are set to
true.

grid_mesh(width, height)

Creates a mesh that consists of a width x height grid of evenly spaced points, connecting
each point to the closest points vertically and horizontally, and dividing each rectangle in
the grid so created into triangles.

width, height
The number of points in the horizontal vertical directions, a integer that is at least 2.
properties(name, value)

Sets the value of a gl property.

name
A string giving the name of the GL property, including the "gl_" prefix.
value
The value of the gl property.
shader(shader)

Adds a shader to this model.


shader
A string given the name of a shader to use with this model.
texture(displayable, focus=False, main=False, fit=False)

Add a texture to this model, by rendering the given displayable. The first texture added will
be tex0, the second tex1, a and so on.

focus
If true, focus events are passed to the displayable. It's assumed that coordinate
relative to the model map 1:1 with coordinates relative to the displayable.
main
If true, this is marked as a main child of this displayable, which allows it to be
inspected using the displayable inspector.
fit
If true, the Model is given the size of the displayable. This may only be true for one
texture.
uniform(name, value)

Sets the value of a uniform that is passed to the shaders.

name
A string giving the name of the uniform to set, including the "u_" prefix.
value
The value of the uniform. Either a float, a 2, 3, or 4 element tuple of floats, or a
Matrix.

Model Displayable Examples


The Model displayable can be used in conjunction with an ATL transform and a built-in shader to
create the Dissolve transform:
transform dt(delay=1.0, new_widget=None, old_widget=None):
delay delay
Model().texture(old_widget).child(new_widget)
shader [ 'renpy.dissolve' ]

u_renpy_dissolve 0.0
linear delay u_renpy_dissolve 1.0

Default Shader Parts


renpy.geometry (priority 100)
Variables:
uniform mat4 u_transform;
attribute vec4 a_position;

Vertex shader:
gl_Position = u_transform * a_position;

renpy.blur (priority 200)


Variables:
uniform sampler2D tex0;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;
uniform float u_renpy_blur_log2;

Vertex shader:
v_tex_coord = a_tex_coord;

Fragment shader:
gl_FragColor = vec4(0.);
float renpy_blur_norm = 0.;

for (float i = -5.; i < 1.; i += 1.) {


float renpy_blur_weight = exp(-0.5 * pow(u_renpy_blur_log2 - i, 2.));
renpy_blur_norm += renpy_blur_weight;
}

gl_FragColor += renpy_blur_norm * texture2D(tex0, v_tex_coord.xy, 0.);

for (float i = 1.; i < 14.; i += 1.) {

if (i >= u_renpy_blur_log2 + 5.) {


break;
}

float renpy_blur_weight = exp(-0.5 * pow(u_renpy_blur_log2 - i, 2.));


gl_FragColor += renpy_blur_weight * texture2D(tex0, v_tex_coord.xy, i);
renpy_blur_norm += renpy_blur_weight;
}

gl_FragColor /= renpy_blur_norm;

renpy.dissolve (priority 200)


Variables:
uniform float u_lod_bias;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float u_renpy_dissolve;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;

Vertex shader:
v_tex_coord = a_tex_coord;

Fragment shader:
vec4 color0 = texture2D(tex0, v_tex_coord.st, u_lod_bias);
vec4 color1 = texture2D(tex1, v_tex_coord.st, u_lod_bias);

gl_FragColor = mix(color0, color1, u_renpy_dissolve);

renpy.imagedissolve (priority 200)


Variables:
uniform float u_lod_bias;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform float u_renpy_dissolve_offset;
uniform float u_renpy_dissolve_multiplier;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;

Vertex shader:
v_tex_coord = a_tex_coord;

Fragment shader:
vec4 color0 = texture2D(tex0, v_tex_coord.st, u_lod_bias);
vec4 color1 = texture2D(tex1, v_tex_coord.st, u_lod_bias);
vec4 color2 = texture2D(tex2, v_tex_coord.st, u_lod_bias);

float a = clamp((color0.a + u_renpy_dissolve_offset) * u_renpy_dissolve_multiplier,


0.0, 1.0);
gl_FragColor = mix(color1, color2, a);

renpy.solid (priority 200)


Variables:
uniform vec4 u_renpy_solid_color;

Fragment shader:
gl_FragColor = u_renpy_solid_color;

renpy.texture (priority 200)


Variables:
uniform float u_lod_bias;
uniform sampler2D tex0;
attribute vec2 a_tex_coord;
varying vec2 v_tex_coord;

Vertex shader:
v_tex_coord = a_tex_coord;
Fragment shader:
gl_FragColor = texture2D(tex0, v_tex_coord.xy, u_lod_bias);

renpy.matrixcolor (priority 400)


Variables:
uniform mat4 u_renpy_matrixcolor;

Fragment shader:
gl_FragColor = u_renpy_matrixcolor * gl_FragColor;

renpy.alpha (priority 500)


Variables:
uniform float u_renpy_alpha;
uniform float u_renpy_over;

Fragment shader:
gl_FragColor = gl_FragColor * vec4(u_renpy_alpha, u_renpy_alpha, u_renpy_alpha,
u_renpy_alpha * u_renpy_over);

You might also like