Pygame shader effects for 2D video game and arcade game
Project description
Pygame Shaders Library
Pygame shader project is a 2D game library written in Python and Cython that contains special effects for development of multimedia applications like video games, arcade game or for image processing It contains shaders offering a large variety of tools or algorithms to modify your game display and mechanics in real time @60 fps for games running display in medium resolution such as 1024 x 768. Some algorithms are more demanding than others in terms of processing power (ex median filtering, predator vision, due to the fact that they are built with more than one shader to provide a composite effect). Consequently, not all shader will run at the same speed at medium resolutions, feel free to experiment with higher display resolution while the shader provides 60 fps or above.
If you are using the shader library for sprites texturing and special effect for your sprites, then the overall processing time will be extremely fast due to the code optimization with cython and the size of the textures.
The shaders effects can be sorted within 5 different categories
- Color variation
- Filter
- Transformation
- Ambiance
- Special effect
Some effects can be used for interaction with the player(s) (ex the player is being hit or is receiving damages, and the screen is turning red; check the blood effect).
Screen shacking after an explosion, check the dampening effect.
Game pausing, use the blur effect to blur the background image until you unpause the game
You need to change the brightness of a scene uses the shader brightness.
Sprite texture colors can be changed over time with the HSL algorithm.
Your game needs to look a bit more retro, use the reduction shader to decrease the amount of colors in your texture or display etc
PygameShader provide tools to improve your overall game appearance by changing Sprites texture/surface and or by using great special effects that will affect the entire screen.
This version contains the following shaders:
-
Color variations
- RGB to BGR (Change your game display from RGB to a BGR model)
- RGB to BRG (Change your game display from RGB to a BRG model)
- grayscale mode
- sepia; Sepia mode
- color reduction, decrease the amount of color
- hsl Rotate the colors
- invert (Invert the game display negative color)
- plasma (Add a plasma effect to your display)
- heatmap conversion
-
Filters
- median*
- sobel effect (edge display)
- gaussian blur 5x5 (add a blur effect to your game)
- sharpen filter (increase the image sharpness)
- bright pass filter (bpf)
-
Transformations
- wave effect, create a wave effect to your game display
- swirl, swirl the entire screen or texture
- horizontal glitch, create a glitch effect affecting your display
- mirroring
- lateral dampening (lateral dampening effect that can be used for explosions)
- dampening effect (zoom in and out dampening effect)
- fisheye your game display is turned into a fisheye model
- heatwave
-
Ambiances
- brightness, increase / decrease the brightness of your texture or game display in real time
- saturation, increase / decrease the level of saturation
-
Special effects
- bloom effect, real time bloom effect for your display
- water ripple effect, create water ripple effect in real time on your game display
- tunnel effect, show a tunnel effect
- tv scanline, TV scanline effect
- blood effect, use a red vignette to color your screen each time your player is taking damage
- predator vision, create a predator vision mode
- fire effect, Display an amazing fire effect onto your game display or texture in real time
- smoke/cloud effect, create a smoke effect or moving cloud
- RGB split, split all the RGB channels separately and display the R, G and B channel with an offset
- rain (bubble effect), You can generate a hundred bubbles or water droplets on your game display, the droplets/bubbles will reflect the game display in real time
The project is under the GNU GENERAL PUBLIC LICENSE Version 3
Demo
C:\>python demo.py
Installation
check the link for newest version https://pypi.org/project/PygameShader/
pip install PygameShader
# or version 1.0.2
pip install PygameShader==1.0.2
- version installed
- Imported module is case sensitive
>>>from PygameShader.shader import __VERSION__
>>>__VERSION__
Building cython code
When do you need to compile the cython code ?
Each time you are modifying any of the following files
shader.pyx, shader.pxd, __init__.pxd or any external C code if applicable
1) open a terminal window
2) Go in the main project directory where (shader.pyx &
shader.pxd files are located)
3) run : python setup_shader.py build_ext --inplace --force
If you have to compile the code with a specific python
version, make sure to reference the right python version
in (python38 setup_shader.py build_ext --inplace)
If the compilation fail, refers to the requirement section and
make sure cython and a C-compiler are correctly install on your
system.
- A compiler such visual studio, MSVC, CGYWIN setup correctly on
your system.
- a C compiler for windows (Visual Studio, MinGW etc) install
on your system and linked to your windows environment.
Note that some adjustment might be needed once a compiler is
install on your system, refer to external documentation or
tutorial in order to setup this process.e.g https://devblogs.
microsoft.com/python/unable-to-find-vcvarsall-bat/
OPENMP
In the main project directory, locate the file setup_shader.py
.
The compilation flag /openmp is used by default.
To override the OPENMP feature and disable the multi-processing remove the flag /openmp
setup_shader.py
ext_modules=cythonize(Extension(
"*", ['*.pyx'],
extra_compile_args=["/Qpar", "/fp:fast", "/O2", "/Oy", "/Ot"], language="c"
Save the change and build the cython code with the following instruction:
python setup_shader.py build_ext --inplace --force
If the project build successfully, the compilation will end up with the following lines
Generating code
Finished generating code
If you have any compilation error refer to the section Building cython code
, make sure
your system has the following program & libraries installed. Check also that the code is not
running in a different thread.
- Pygame version >3
- numpy >= 1.18
- cython >=0.29.21 (C extension for python)
- A C compiler for windows (Visual Studio, MinGW etc)
Credit
Yoann Berenguer
Dependencies :
numpy >= 1.18
pygame >=2.0.0
cython >=0.29.21
License :
GNU GENERAL PUBLIC LICENSE Version 3
Copyright (c) 2019 Yoann Berenguer
Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Testing:
>>> import PygameShader
>>> from PygameShader.tests.test_shader import run_testsuite
>>> run_testsuite()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file PygameShader-1.0.0.tar.gz
.
File metadata
- Download URL: PygameShader-1.0.0.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58b29773cac58945d16e4bc50ac777524f1cf97a2f15ec6a35e1c0efe40b1dae |
|
MD5 | 49b508acba42e9befa9ce1901c6c24d3 |
|
BLAKE2b-256 | 312a24d542911063ca8ab7adbce2189e89f19de334dc3085c0e9c79c6e15ff89 |
File details
Details for the file PygameShader-1.0.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: PygameShader-1.0.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f3e2fe9b7b801544c54b41779d9aceffd78f984d2e1d1097781357ca237fa68 |
|
MD5 | ba40f66ec32d624bec78f6084c219bbb |
|
BLAKE2b-256 | b3b40003b6b3b810935bba85dcf28622d0c9e1b9313dc94307b6808c8db44a3a |
File details
Details for the file PygameShader-1.0.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: PygameShader-1.0.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a53401c0d92c3c89fda457841e6c377a1074683ebc1714106459c90bd9c040c |
|
MD5 | 0f7f012af42a9fc8918e80130db2bbcb |
|
BLAKE2b-256 | d675ddda81a6b9cb1473b0b326996768d5cbb51797a7b360def58439cb758bd3 |
File details
Details for the file PygameShader-1.0.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: PygameShader-1.0.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 4.8 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6460a8a73a85efdb5be091e544c41d2919eceb2ae50c83f847550a658fb06c1a |
|
MD5 | 23684beef4d825e845501c136d5880a5 |
|
BLAKE2b-256 | d419b2015a2e4ef0505694dca2d95592ffb44a32533e206e7c061ba01d0b14f0 |
File details
Details for the file PygameShader-1.0.0-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: PygameShader-1.0.0-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af146be7c19d2cc20b3801985974fa85f3428264279f16c903023801f958b288 |
|
MD5 | 62160f63143307b8ce06e0f3d1653c31 |
|
BLAKE2b-256 | 35ff6ae1853b997075254b5464a9e27ccaeb4cfd4847c9937329c47c284d33f9 |
File details
Details for the file PygameShader-1.0.0-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: PygameShader-1.0.0-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 5.1 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b494087140e671f9b1b44e51d47c61fbc0a10e21315c8efe04d9d67d342129a |
|
MD5 | 42e8f787c5025576d66f37f870252175 |
|
BLAKE2b-256 | 5cbfd59b1e45111ed7cb9a66ffcacd2d504532b0646a2f7894a84c9534b31332 |