Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #21 Add basic shader & python compress data and demo project #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 59 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,93 @@ name: build

on: [push]

# Software
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners

jobs:
Emscripten:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v1

- name: Install Dependencies
shell: cmd
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull
./emsdk install latest-upstream
./emsdk activate latest-upstream
source ./emsdk_env.sh
ls -l upstream/emscripten/system/include
cd ..
wget -O SDL2-version_18.zip -q https://github.com/emscripten-ports/SDL2/archive/version_18.zip
mkdir InstallLibs
mkdir InstallLibs/SDL2
7z x SDL2-version_18.zip -oInstallLibs
ls -l InstallLibs
cp -p InstallLibs/SDL2-version_18/include/*.* InstallLibs/SDL2/

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
call emsdk.bat install latest-upstream
call emsdk.bat activate latest-upstream
cd ..
echo Choco install
dir C:\ProgramData\Chocolatey\bin
echo Install WGET
choco install wget -y
echo Install SDL2LIB
wget -O SDL2-version_18.zip -q https://github.com/emscripten-ports/SDL2/archive/version_18.zip
mkdir InstallLibs
mkdir InstallLibs\SDL2
7z x SDL2-version_18.zip -oInstallLibs
copy InstallLibs\SDL2-version_18\include\*.* InstallLibs\SDL2
echo Install success
- name: Build
run: |
cmake -DCMAKE_TOOLCHAIN_FILE=emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -S.
make

shell: cmd
run: |
cd Assets
python BuildAssetBundles.py
cd ..
mkdir Bin\BuiltIn
copy Bin\BuiltIn.zip Bin\BuiltIn
call emsdk\emsdk_env.bat
cmake -DCMAKE_TOOLCHAIN_FILE=emsdk\upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake -S . -B ./PrjEmscripten -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND"
mingw32-make -C PrjEmscripten
- name: Package
shell: cmd
run: |
mkdir Build
ls -l Bin
7z a Build/Skylicht_Demo_Emscripten.zip Bin/MainApp*
7z a Build/Skylicht_Demo_Emscripten.zip Bin/*.zip

type Version.txt
set /p CONFIG_VERSION=<Version.txt
set file_version=%CONFIG_VERSION:.=_%
set output=Build\SkylichtDemo_%file_version%__Emscripten.zip
7z a %output% Bin\MainApp*
7z a %output% Bin\*.zip
- name: Result
uses: actions/upload-artifact@v1
with:
name: Skylicht_Demo_Emscripten
path: Build/Skylicht_Demo_Emscripten.zip
name: SkylichtDemo_Emscripten
path: Build

Linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- uses: actions/checkout@v1
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y libglfw3-dev libsdl2-dev
cmake --version

sudo apt-get install -y libglfw3-dev libsdl2-dev
sudo apt remove --purge --auto-remove cmake
wget -q https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5-Linux-x86_64.tar.gz
tar -zxvf cmake-3.15.5-Linux-x86_64.tar.gz
- name: Build
run: |
cmake -S. -DBUILD_SDL=true
make
export PATH="./cmake-3.15.5-Linux-x86_64/bin:$PATH"
cmake -S. -BPrjLinux -DBUILD_SDL=true
cd Assets
python BuildAssetBundles.py
cd ..
make -C PrjLinux
- name: Unit Test
run: |
ctest --verpose

ctest --verpose
- name: Package
run: |
mkdir Build
ls -l Bin
7z a Build/Skylicht_Demo_Linux.zip Bin/MainApp*
7z a Build/Skylicht_Demo_Emscripten.zip Bin/*.zip

version=$(cat "Version.txt")
file_version=${version//./_}
output=Build/SkylichtDemo_${file_version}_Linux.zip
7z a ${output} Bin/MainApp*
7z a ${output} Bin/*.zip
- name: Result
uses: actions/upload-artifact@v1
with:
name: Skylicht_Demo_Linux
path: Build/Skylicht_Demo_Linux.zip
name: SkylichtDemo_Linux
path: Build
40 changes: 40 additions & 0 deletions Assets/BuildAssetBundles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import zipfile
import os

zipFileTypes = ["xml", "hlsl", "glsl"]

def needCompress(filename):
for type in zipFileTypes:
if filename.endswith(type):
return True
return False

def compress(dirName):
outputZip = "../Bin/" + dirName + ".zip"
z = zipfile.ZipFile(outputZip, "w", zipfile.ZIP_DEFLATED)

for root, dirs, files in os.walk(dirName):
for file in files:
if needCompress(file):
print("%s <-- %s - %s" %(outputZip, root, file))
z.write(os.path.join(root, file))

z.close

def main():
# Create Bin folder
if (os.path.exists("../Bin/") == False):
os.mkdir("../Bin/")

# Walk and build bundle
directory = "."
for filename in os.listdir(directory):
if os.path.isdir(filename):
print("Compress directory: %s" % filename)
compress(filename)
continue
else:
continue

if __name__ == '__main__':
main()
18 changes: 18 additions & 0 deletions Assets/BuiltIn/Shader/Basic/AlphaBlend.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<shaderConfig name="AlphaBlend" baseShader="TRANSPARENT_ALPHA_CHANNEL">
<uniforms>
<vs>
<uniform name="uMvpMatrix" type="WORLD_VIEW_PROJECTION" value="0" float="16" matrix="true"/>
</vs>
<fs>
<uniform name="uTexDiffuse" type="DEFAULT_VALUE" value="0" float="1" directX="false"/>
<uniform name="uTexAlpha" type="DEFAULT_VALUE" value="1" float="1" directX="false"/>
</fs>
</uniforms>
<customUI>
<ui control="UIGroup" name="Texture">
<ui control="UITexture" name="uTexDiffuse" autoReplace="_diff.tga"/>
</ui>
</customUI>
<shader type="GLSL" vs="GLSL/AlphaBlendVS.glsl" fs="GLSL/AlphaBlendFS.glsl"/>
<shader type="HLSL" vs="HLSL/AlphaBlendVS.hlsl" fs="HLSL/AlphaBlendFS.hlsl"/>
</shaderConfig>
18 changes: 18 additions & 0 deletions Assets/BuiltIn/Shader/Basic/AlphaTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<shaderConfig name="AlphaTest" baseShader="SOLID">
<uniforms>
<vs>
<uniform name="uMvpMatrix" type="WORLD_VIEW_PROJECTION" value="0" float="16" matrix="true"/>
</vs>
<fs>
<uniform name="uTexDiffuse" type="DEFAULT_VALUE" value="0" float="1" directX="false"/>
<uniform name="uTexAlpha" type="DEFAULT_VALUE" value="1" float="1" directX="false"/>
</fs>
</uniforms>
<customUI>
<ui control="UIGroup" name="Texture">
<ui control="UITexture" name="uTexDiffuse" autoReplace="_diff.tga"/>
</ui>
</customUI>
<shader type="GLSL" vs="GLSL/AlphaTestVS.glsl" fs="GLSL/AlphaTestFS.glsl"/>
<shader type="HLSL" vs="HLSL/AlphaTestVS.hlsl" fs="HLSL/AlphaTestFS.hlsl"/>
</shaderConfig>
19 changes: 19 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/AlphaBlendFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
precision mediump float;

uniform sampler2D uTexDiffuse;
uniform sampler2D uTexAlpha;

in vec2 varTexCoord0;
in vec4 varColor;

out vec4 FragColor;

void main(void)
{
vec4 t1 = texture(uTexDiffuse, varTexCoord0.xy) * varColor;
vec4 t2 = texture(uTexAlpha, varTexCoord0.xy);

t1.a = t2.r * varColor.a;

FragColor = t1;
}
16 changes: 16 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/AlphaBlendVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
in vec4 inPosition;
in vec4 inColor;
in vec3 inNormal;
in vec2 inTexCoord0;

uniform mat4 uMvpMatrix;

out vec2 varTexCoord0;
out vec4 varColor;

void main(void)
{
varTexCoord0 = inTexCoord0;
varColor = inColor/255.0;
gl_Position = uMvpMatrix * inPosition;
}
21 changes: 21 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/AlphaTestFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
precision mediump float;

uniform sampler2D uTexDiffuse;
uniform sampler2D uTexAlpha;

uniform vec4 uColorSaturation;

in vec2 varTexCoord0;
out vec4 FragColor;

void main(void)
{
vec4 alphaColor = texture(uTexAlpha, varTexCoord0.xy);

if (alphaColor.r < 0.5)
discard;

vec3 result = texture(uTexDiffuse, varTexCoord0.xy).rgb;

FragColor = vec4(result, 1.0);
}
15 changes: 15 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/AlphaTestVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
in vec4 inPosition;
in vec4 inColor;
in vec3 inNormal;
in vec2 inTexCoord0;

uniform mat4 uMvpMatrix;

out vec2 varTexCoord0;

void main(void)
{
varTexCoord0 = inTexCoord0;

gl_Position = uMvpMatrix * inPosition;
}
9 changes: 9 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/ColorFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
precision mediump float;

in vec4 varColor;
out vec4 FragColor;

void main(void)
{
FragColor = varColor;
}
12 changes: 12 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/ColorVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
in vec4 inPosition;
in vec4 inColor;

uniform mat4 uMvpMatrix;

out vec4 varColor;

void main(void)
{
varColor = inColor/255.0;
gl_Position = uMvpMatrix * inPosition;
}
18 changes: 18 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/TextureColor2LayerFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
precision mediump float;

uniform sampler2D uTexDiffuse1;
uniform sampler2D uTexDiffuse2;

in vec2 varTexCoord0;
in vec2 varTexCoord1;
in vec4 varColor;

out vec4 FragColor;

void main(void)
{
vec4 color1 = texture(uTexDiffuse1, varTexCoord0.xy);
vec4 color2 = texture(uTexDiffuse2, varTexCoord1.xy);

FragColor = color1 * color2 * varColor;
}
19 changes: 19 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/TextureColor2LayerVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
in vec4 inPosition;
in vec4 inColor;
in vec2 inTexCoord0;
in vec2 inTexCoord1;

uniform mat4 uMvpMatrix;

out vec2 varTexCoord0;
out vec2 varTexCoord1;
out vec4 varColor;

void main(void)
{
varTexCoord0 = inTexCoord0;
varTexCoord1 = inTexCoord1;
varColor = inColor/255.0;

gl_Position = uMvpMatrix * inPosition;
}
14 changes: 14 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/TextureColorAdditiveFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
precision mediump float;

uniform sampler2D uTexDiffuse;

in vec2 varTexCoord0;
in vec4 varColor;

out vec4 FragColor;

void main(void)
{
vec4 color = texture(uTexDiffuse, varTexCoord0.xy) * varColor;
FragColor = color * varColor.a;
}
17 changes: 17 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/TextureColorAdditiveVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
in vec4 inPosition;
in vec4 inColor;
in vec3 inNormal;
in vec2 inTexCoord0;

uniform mat4 uMvpMatrix;

out vec2 varTexCoord0;
out vec4 varColor;

void main(void)
{
varTexCoord0 = inTexCoord0;
varColor = inColor/255.0;

gl_Position = uMvpMatrix * inPosition;
}
Loading