Skip to content

Commit

Permalink
Merge pull request #294 from Bam4d/example_cleanup
Browse files Browse the repository at this point in the history
commit shaders and fix/test other examples
  • Loading branch information
Bam4d authored Dec 24, 2023
2 parents 1dc4455 + 959d133 commit 8ef1933
Show file tree
Hide file tree
Showing 63 changed files with 114 additions and 120 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ jobs:
- python-version: "3.10"
py-bin: cp310-cp310
platform: manylinux_2_28_x86_64
# - python-version: "3.11"
# py-bin: cp311-cp311
# platform: manylinux_2_28_x86_64
- python-version: "3.11"
py-bin: cp311-cp311
platform: manylinux_2_28_x86_64
- python-version: "3.8"
py-bin: cp38-cp38
platform: manylinux2014_x86_64
Expand All @@ -67,6 +67,9 @@ jobs:
- python-version: "3.10"
py-bin: cp310-cp310
platform: manylinux2014_x86_64
- python-version: "3.11"
py-bin: cp311-cp311
platform: manylinux2014_x86_64
container:
image: quay.io/pypa/${{ matrix.manylinux_config.platform }}
env:
Expand Down Expand Up @@ -136,6 +139,7 @@ jobs:
- python-version: "3.8"
- python-version: "3.9"
- python-version: "3.10"
- python-version: "3.11"

steps:
# Checkout the repository
Expand Down Expand Up @@ -201,6 +205,7 @@ jobs:
- python-version: "3.8"
- python-version: "3.9"
- python-version: "3.10"
- python-version: "3.11"

steps:
# Checkout the repository
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ tests/vendor/*
!tests/vendor/CMakeLists.txt*

# Vulkan
*.spv
*.ppm

# Idea
Expand Down
10 changes: 8 additions & 2 deletions compile_shaders.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ CALL :compile_shaders_in_dir .\tests\resources\observer\block\shaders\global_lig
CALL :compile_shaders_in_dir .\tests\resources\observer\isometric\shaders\lighting
CALL :compile_shaders_in_dir .\tests\resources\observer\sprite\shaders\health_bars

CALL :compile_shaders_in_dir ".\python\examples\Custom Shaders\Global Lighting\shaders"
CALL :compile_shaders_in_dir ".\python\examples\Custom Shaders\Health Bars\shaders"
CALL :compile_shaders_in_dir ".\python\examples\Custom Shaders\Object Lighting\shaders"



EXIT /B 0

:compile_shaders_in_dir
echo "Compiling shaders in %~1"
%GLSLC_BIN% %~1\triangle-textured.frag -o %~1\triangle-textured.frag.spv
%GLSLC_BIN% %~1\triangle-textured.vert -o %~1\triangle-textured.vert.spv
%GLSLC_BIN% "%~1\triangle-textured.frag" -o "%~1\triangle-textured.frag.spv"
%GLSLC_BIN% "%~1\triangle-textured.vert" -o "%~1\triangle-textured.vert.spv"
9 changes: 7 additions & 2 deletions compile_shaders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ cd "$(dirname "$0")"

compile_shaders_in_dir () {
echo "Compiling shaders in $1"
$GLSLC_BIN $1/triangle-textured.frag -o $1/triangle-textured.frag.spv
$GLSLC_BIN $1/triangle-textured.vert -o $1/triangle-textured.vert.spv
$GLSLC_BIN "$1/triangle-textured.frag" -o "$1/triangle-textured.frag.spv"
$GLSLC_BIN "$1/triangle-textured.vert" -o "$1/triangle-textured.vert.spv"
}

compile_shaders_in_dir ./resources/shaders/default/block
Expand All @@ -14,3 +14,8 @@ compile_shaders_in_dir ./resources/shaders/default/isometric
compile_shaders_in_dir ./tests/resources/observer/block/shaders/global_lighting
compile_shaders_in_dir ./tests/resources/observer/isometric/shaders/lighting
compile_shaders_in_dir ./tests/resources/observer/sprite/shaders/health_bars


compile_shaders_in_dir "./python/examples/Custom Shaders/Global Lighting/shaders"
compile_shaders_in_dir "./python/examples/Custom Shaders/Health Bars/shaders"
compile_shaders_in_dir "./python/examples/Custom Shaders/Object Lighting/shaders"
13 changes: 0 additions & 13 deletions docs/getting-started/action spaces/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,6 @@ Lets say our RTS game has units that have an action ``move`` and an action ``gat

.. code-block:: python
# env.step([
# [ # List of actions for player 1
# [x1, y1, action_type1, action_id1],
# [x2, y2, action_type2, action_id2],
# ...
# ],
# [ # List of actions for player 2
# [x1, y1, action_type1, action_id1],
# [x2, y2, action_type2, action_id2],
# ..
# ],
# ])
env.step([
# Player 1
[
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/observation spaces/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The observations for environments where a single avatar is being controlled are
# obs = np.array([ ... ]) # Player observation
obs, reward, done, info = env.step( ... )
obs, reward, done, truncated, info = env.step( ... )
# obs = np.array([ ... ]) # Player observation
Expand Down
17 changes: 6 additions & 11 deletions python/examples/AStar Search/main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
from griddly import gd, gym
from griddly import gd
from griddly.gym import GymWrapper
from griddly.util.render_tools import RenderToVideo
from griddly.wrappers.render_wrapper import RenderWrapper

if __name__ == "__main__":
# Uncommment to see normal actions (not rotated) being used

# Astar action space: 0: up, 1: down, 2: left, 3: right
# env = GymWrapper('astar_opponent_environment.yaml',
# player_observer_type=gd.ObserverType.VECTOR,
# global_observer_type=gd.ObserverType.SPRITE_2D,
# level=0)

# env = GymWrapper('astar_opponent_rotation_actions_environment.yaml',
# player_observer_type=gd.ObserverType.VECTOR,
# global_observer_type=gd.ObserverType.SPRITE_2D,
# level=0)

# Uncommment to see multiple spiders chasing!
env = gym(
"astar_opponent_rotation_actions_environment.yaml",
# Astar action space: 1: Rotate left, 2: Move forward, 3: Rotate right
env = GymWrapper(
"./astar_opponent_rotation_actions_environment.yaml",
player_observer_type=gd.ObserverType.VECTOR,
global_observer_type=gd.ObserverType.SPRITE_2D,
level=1,
Expand Down
5 changes: 3 additions & 2 deletions python/examples/Custom Shaders/Global Lighting/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from griddly import gd, gym
from griddly import gd
from griddly.gym import GymWrapper
from griddly.util.render_tools import RenderToFile, RenderToVideo
from griddly.wrappers.render_wrapper import RenderWrapper

if __name__ == "__main__":
env = gym(
env = GymWrapper(
"global_lighting.yaml",
player_observer_type=gd.ObserverType.SPRITE_2D,
global_observer_type=gd.ObserverType.SPRITE_2D,
Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions python/examples/Custom Shaders/Health Bars/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from griddly import gd, gym
from griddly import gd
from griddly.gym import GymWrapper
from griddly.util.render_tools import RenderToFile, RenderToVideo
from griddly.wrappers.render_wrapper import RenderWrapper

if __name__ == "__main__":
env = gym(
env = GymWrapper(
"health_bars.yaml",
player_observer_type=gd.ObserverType.SPRITE_2D,
global_observer_type=gd.ObserverType.SPRITE_2D,
Expand Down
Binary file modified python/examples/Custom Shaders/Health Bars/reset_global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions python/examples/Custom Shaders/Object Lighting/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from griddly import gd, gym
from griddly import gd
from griddly.gym import GymWrapper
from griddly.util.render_tools import RenderToFile, RenderToVideo
from griddly.wrappers.render_wrapper import RenderWrapper

if __name__ == "__main__":
env = gym(
env = GymWrapper(
"object_lighting.yaml",
player_observer_type=gd.ObserverType.SPRITE_2D,
global_observer_type=gd.ObserverType.SPRITE_2D,
Expand Down
Binary file modified python/examples/Custom Shaders/Object Lighting/reset_global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Custom Shaders/Object Lighting/reset_partial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Binary file not shown.
Binary file not shown.
9 changes: 4 additions & 5 deletions python/examples/Custom Shaders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

In this directory are a few examples of how to make use of custom shaders to modify the standard pixel output for more complex environnments.


## Global Lighting

We use the episode step timer `_steps` to create a day/night cycle!
We use the episode step timer `_steps` to create a day/night cycle!

![Global Lighting](Global%20Lighting/global_lighting.gif)

## Health Bars

In this example we show health bars on individual units in a combat scenario.
In this example we show health bars on individual units in a combat scenario.

![Health Bars](Health%20Bars/health_bars.gif)

## Object Lighting
## Object Lighting

Add partial observability to agents by only lighting up the immediate area around the agent and the goal

![Object Lighting](Object%20Lighting/object_lighting.gif)
![Object Lighting](Object%20Lighting/object_lighting.gif)
Binary file modified python/examples/Level Design/custom_level_global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/custom_level_string_player_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/custom_level_string_player_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/level_0_global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/level_1_global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/level_1_player_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/level_1_player_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/level_2_global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/level_2_player_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Level Design/level_2_player_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 9 additions & 8 deletions python/examples/Level Design/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from griddly import gd, gym
from griddly import gd
from griddly.gym import GymWrapper
from griddly.util.render_tools import RenderToFile
from griddly.wrappers.render_wrapper import RenderWrapper

if __name__ == "__main__":
env = gym(
env = GymWrapper(
"levels.yaml",
player_observer_type=gd.ObserverType.BLOCK_2D,
global_observer_type=gd.ObserverType.BLOCK_2D,
Expand All @@ -26,13 +27,13 @@
image_renderer.render(obs, f"level_{i}_player_2.png")

level_string = \
""". c c c c c c . . c c c c c c . . c c . c c c c c c . . c c c c c c . . c c . . . . . . c c . . . . c c .
c c . . . . . . . c c . . . c c . c c . c c . . . c c . c c . . . c c . c c . . . . . . . c c . . c c . .
c c . . . c c c . c c c c c c . . c c . c c . . . c c . c c . . . c c . c c . . . . . . . . c c c c . . .
c c . . . . c c . c c . . . c c . c c . c c . . . c c . c c . . . c c . c c . . . . . . . . . c c . . . .
. c c c c c c . . c c . . . c c . c c . c c c c c c . . c c c c c c . . c c c c c c c . . . . c c . . . .
""". c c c c c c . . c c c c c c . . c c . c1 c1 c1 c1 c1 c1 . . c2 c2 c2 c2 c2 c2 . . c c . . . . . . c c . . . . c c .
c c . . . . . . . c c . . . c c . c c . c1 c1 . . . c1 c1 . c2 c2 . . . c2 c2 . c c . . . . . . . c c . . c c . .
c c . . . c c c . c c c c c c . . c c . c1 c1 . . . c1 c1 . c2 c2 . . . c2 c2 . c c . . . . . . . . c c c c . . .
c c . . . . c c . c c . . . c c . c c . c1 c1 . . . c1 c1 . c2 c2 . . . c2 c2 . c c . . . . . . . . . c c . . . .
. c c c c c c . . c c . . . c c . c c . c1 c1 c1 c1 c1 c1 . . c2 c2 c2 c2 c2 c2 . . c c c c c c c . . . . c c . . . .
"""
env.reset(options={level_string: level_string})
env.reset(options={"level_string": level_string})
obs = global_obs_render_wrapper.render()
image_renderer.render(obs, "custom_level_global.png")
obs = player_1_obs_render_wrapper.render()
Expand Down
Binary file modified python/examples/Procedural Generation/example_maze_13x13_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Procedural Generation/example_maze_13x13_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Procedural Generation/example_maze_13x13_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Procedural Generation/example_maze_45x45_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/examples/Procedural Generation/example_maze_45x45_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8ef1933

Please sign in to comment.