This is the pixel-art post-process shaders for 3D.
There is a simple example included in this project. Demo: https://selimanac.github.io/defold-pixelart-shader/
https://github.com/selimanac/defold-pixelart-shader-example
This post-processing effect cannot make every 3D model perfect for pixel art. Do not expect miracles.
- This library does not contain any pixel-perfect solutions. It is up to you to handle camera, pixel size and up-scaling
- Use direct rotations (top, left, right, bottom) or isometric rotations (e.g., x: 30, y: 45) for camera views to better align pixels.
- Use an orthographic camera projection.
- Use simple/flat/basic 3D models. Small details looks bad.
- Use simple/flat textures. Even gradients are undesirable, stick to solid colors if you can.
- [optional] Add pixelart.render to game.project -> Bootstrap -> Render section. You may also use your own solution. Refer to pixelart_render
- [optional] Add camera to your collection.
- Add pixelart_post_process.go gameobject file from library to your collection
- Add empty gameobject with ID
light_source
and change its position to desire location - Add empty gameobject with ID
light_target
and change its position to desire location - Use pixelart.init() to initialize
There are two lua modules to help you to setup
pixel_settings
(table)
pixel_settings.pixel_size
(integer) Pixel sizepixel_settings.normal_edge_coefficient
(number) Normal edge for sharpening edgespixel_settings.depth_edge_coefficient
(number) Depth edge for outline
light_settings
(table)[optional]
light_settings.source
(string) Light source gameobject URLlight_settings.target
(string) Light target gameobject URLlight_settings.diffuse_light_color
(vector3)[optional] Diffuse light color
shadow_settings
(table)[optional]
Requires light_settings
.
shadow_settings.projection_width
(number) Light projection widthshadow_settings.projection_height
(number) Light projection heightshadow_settings.projection_near
(number) Light projection near planeshadow_settings.projection_far
(number) Light projection far planeshadow_settings.depth_bias
(number)[optional] The 'depth_bias' value is per-scene dependent and must be tweaked accordingly. It is needed to avoid shadow acne, which is basically a precision issue.shadow_settings.shadow_opacity
(number)[optional] Shadow opacity
Set shadow depth bias
depth_bias
(number) Depth Bias
Set shadow opacity
shadow_opacity
(number) Shadow opacity
Set Pixel-art pixel size for post-processing shader
pixel_size
(integer) Pixel size
Set Pixel-art normal edge for sharpening edges
normal_edge
(number) Normal edge
Set Pixel-art depth edge for outline
depth_edge
(number) Depth edge
Set Pixel-art models ambient light
ambient_light
(vector3) Ambient light
Set Pixel-art resolution for post-processing shader
pixel_size
(integer) Pixel size
Set light source and target
light_source
(string) Light source gameobject URLlight_target
(string) Light target gameobject URL
Use this file to render pixel-art post-process.
Must be called on render_script's init(self)
function
pixelart_render.update(self
, camera_frustum
, view
, proj
, window_width
, window_height
, clear_buffers
)
Must be called on render_script's update(self)
function
camera_frustum
(matrix4) Camera frustumview
(matrix4) Camera viewproj
(matrix4) Camera projectionwindow_width
(number) Window widthwindow_height
(number) Window heightclear_buffers
(table) Clear buffer table
Materials can be found in pixelart/materials folder.
Very similar to build-in model_instanced material
Unlit instanced model material
Same as pixelart_model.material but for World Vertex Space required by animated 3D models.
Same as pixelart_model_unlit.material but for World Vertex Space required by animated 3D models.
Shadow material from Igor Suntsev's (aka @dragosha) Light and Shadows
Shadow material from Jhonny Göransson's examples
- Shadow shaders are mostly from Jhonny Göransson's examples and Igor Suntsev's (aka @dragosha) Light and Shadows
- Slightly modified version of Abadonna's orbit-camera
- Björn Ritzl's extension-imgui