Skip to content

Commit

Permalink
add shaders for android version
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Feb 18, 2024
1 parent f7b35d4 commit 069d82b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 15 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ endif()

option(BUILD_MINSIZE "Build a smaller executable" OFF)

if(ANDROID)
add_custom_target(pack_assets
COMMAND python ${CMAKE_SOURCE_DIR}/tools/pack_assets.py menu_blur.android.fs=menu_blur.fs
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
else()
add_custom_target(pack_assets
COMMAND python ${CMAKE_SOURCE_DIR}/tools/pack_assets.py menu_blur.android.fs=none
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()


add_subdirectory(lib/raylib)
add_subdirectory(lib/zlib)

Expand Down
26 changes: 25 additions & 1 deletion android/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified android/app/src/main/assets/resource.pack
Binary file not shown.
28 changes: 28 additions & 0 deletions assets/shaders/menu_blur.android.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#version 100

precision mediump float;

varying vec2 fragTexCoord;
varying vec4 fragColor;

uniform sampler2D texture0;
uniform vec4 colDiffuse;

const float renderWidth = 640.0;
const float renderHeight = 360.0;

vec3 offset = vec3(0.0, 1.3846153846, 3.2307692308);
vec3 weight = vec3(0.2270270270, 0.3162162162, 0.0702702703);

void main()
{
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight.x;

tc += texture2D(texture0, fragTexCoord + vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;
tc += texture2D(texture0, fragTexCoord - vec2(offset.y)/renderWidth, 0.0).rgb*weight.y;

tc += texture2D(texture0, fragTexCoord + vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;
tc += texture2D(texture0, fragTexCoord - vec2(offset.z)/renderWidth, 0.0).rgb*weight.z;

gl_FragColor = vec4(tc, 1.0);
}
17 changes: 8 additions & 9 deletions src/screen/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ void menu_screen(w_state *state) {
(Vector2){0, title_text->font_size + 10}),
(char *)TextFormat("made by @julesgrc0 - %s", WISPY_VERSION), 20, WHITE);

while (!WindowShouldClose() && is_active) {
double angle = 0.0;
while (!WindowShouldClose() && is_active) {

camera.target.x += sinf(GetTime() * 0.05) * 100.0f * GetFrameTime();
camera.target.y += cosf(GetTime() * 0.05) * 100.0f * GetFrameTime();
double speed = GetFrameTime() * 0.1;
angle += speed;
angle = fmod(angle, 360.0);

camera.target.x += (sin(angle) * 1000.0) * speed;
camera.target.y += (cos(angle) * 1000.0) * speed;

update_chunkview(view, grp, get_camera_view(&camera));
update_chunkview_lighting(
Expand All @@ -85,16 +90,10 @@ void menu_screen(w_state *state) {
BeginDrawing();
ClearBackground(BLACK);

#ifndef __ANDROID__
BeginShaderMode(blurShader);
#endif

DrawTexturePro(state->render.texture, state->src_rnd, state->dest_rnd,
VEC_ZERO, 0.0f, WHITE);

#ifndef __ANDROID__
EndShaderMode();
#endif

DrawRectangleLinesEx(
(Rectangle){0, 0, ctx->render_size.x, ctx->render_size.y}, 5,
Expand Down
29 changes: 24 additions & 5 deletions tools/pack_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@
from io import TextIOWrapper


def write_to_pack(out_file: TextIOWrapper, folder_path: str) -> int:
def write_to_pack(out_file: TextIOWrapper, folder_path: str, redirect_files: dict[str, str]) -> int:
total_size = 0
null = 0

for root, _, files in os.walk(folder_path):
for file in files:
file_path = os.path.join(root, file)
relative_path = os.path.relpath(file_path, folder_path)

if file in redirect_files.keys():
if redirect_files[file] == "none":
print(f"[+] SKIP {file} (ignored)")
continue

file_path = os.path.join(root, file)
relative_path = os.path.relpath(os.path.join(root, redirect_files[file]), folder_path)

print(f"[+] REDIRECT {file} => {redirect_files[file]}")
elif file in redirect_files.values():
print(f"[+] SKIP {file} (ignored)")
continue

file_size = os.path.getsize(file_path)
total_size += file_size

Expand All @@ -22,7 +36,7 @@ def write_to_pack(out_file: TextIOWrapper, folder_path: str) -> int:
length=1, byteorder="little", signed=False)) # end of string
out_file.write(file_size.to_bytes(
length=4, byteorder="little", signed=False)) # sizeof(unsigned int) = 4
print(f"[+] {file_path:100}{file_size} o")
print(f"[+] {file_path:100}{file_size} o{' ' * 10}({relative_path})")

with open(file_path, "rb") as file:
out_file.write(file.read())
Expand All @@ -31,20 +45,25 @@ def write_to_pack(out_file: TextIOWrapper, folder_path: str) -> int:


def main(args: list[str]) -> int:
redirect_files = {}
for arg in args:
parts = arg.split("=")
if len(parts) == 2:
redirect_files[parts[0]] = parts[1]

base_dir = os.path.dirname(os.path.abspath(__file__))

assets_dir = os.path.join(os.path.dirname(base_dir), "assets")

out_tmp = os.path.join(base_dir, "resource.tmp")
out_gz = os.path.join(base_dir, "resource.pack")

print("[PACK]: Start packing...")
print(f"[-] {'filename':100}{'size (octet)'}\n")
print(f"[I] {'filename':100}size{' '*10}id\n")

start_t = time.time()
total_size = 0
with open(out_tmp, "wb+") as fp:
total_size = write_to_pack(fp, assets_dir)
total_size = write_to_pack(fp, assets_dir, redirect_files)
fp.close()

with open(out_tmp, 'rb') as fp_in:
Expand Down
Binary file modified tools/resource.pack
Binary file not shown.

0 comments on commit 069d82b

Please sign in to comment.