├── examples ├── resources │ ├── Light.efk │ ├── Laser01.efk │ ├── Parts │ │ ├── Aura.png │ │ ├── Null.png │ │ ├── Ring.png │ │ ├── Aura_2.png │ │ ├── Noise2.png │ │ ├── Noise3.png │ │ ├── Noise4.png │ │ ├── Ring2.png │ │ ├── Particle1.png │ │ ├── Particle2.png │ │ ├── Tube.efkmodel │ │ ├── AuraTube.efkmat │ │ ├── ColorNoise.png │ │ ├── Gradient_2.png │ │ ├── Gradient__1.png │ │ ├── Gradient__3.png │ │ ├── Impact.efkmodel │ │ ├── ParticleCore.png │ │ ├── Round.efkmodel │ │ ├── RadiarNoise.efkmat │ │ ├── ToonImpact.efkmat │ │ ├── ToonWaterTube.efkmat │ │ ├── AuraTubeModel.efkmodel │ │ └── Noise_Distortion.efkmat │ ├── toonwater.efk │ ├── Texture │ │ ├── Arrow.png │ │ ├── Fire.png │ │ ├── Glass.png │ │ ├── Halo.png │ │ ├── Line1.png │ │ ├── Line3.png │ │ ├── Line4.png │ │ ├── Line5.png │ │ ├── Smoke.png │ │ ├── Star.png │ │ ├── Wind.png │ │ ├── Burst_1.png │ │ ├── Burst_2.png │ │ ├── Burst_3.png │ │ ├── Feather.png │ │ ├── Line_2.png │ │ ├── Splash.png │ │ ├── UVCheck.png │ │ ├── Fire_Blur.png │ │ ├── ModelFade.png │ │ ├── Particle01.png │ │ ├── Particle02.png │ │ ├── Shockwave.png │ │ ├── Tentacle.png │ │ ├── Yakiniku.png │ │ ├── Fire_Single.png │ │ ├── Humanity_Eye.png │ │ ├── LaserMain01.png │ │ ├── Thunder_Bold.png │ │ ├── Thunder_Thin.png │ │ ├── FractalNoise_1.png │ │ ├── FractalNoise_2.png │ │ ├── FractalNoise_3.png │ │ ├── FractalNoise_4.png │ │ ├── IntensiveLine.png │ │ ├── NoiseAnimation.png │ │ ├── Particle_Hard.png │ │ ├── Particle_Soft.png │ │ ├── Smoke_Lighting.png │ │ ├── ExperimentalBlur.png │ │ └── ExperimentalNoise.png │ ├── sword_ember.efkefc │ ├── Model │ │ ├── Arrow.efkmodel │ │ ├── ShortLance.efkmodel │ │ ├── LongSword_Blade.efkmodel │ │ └── LongSword_Handle.efkmodel │ ├── Simple_Model_UV.efkefc │ └── sword_lightning.efkefc ├── cube │ └── shaders │ │ ├── varying.def.sc │ │ ├── fs_fullscreen.sc │ │ ├── fs_cube.sc │ │ ├── vs_cube.sc │ │ └── vs_fullscreen.sc ├── make.lua └── example.cpp ├── make.lua ├── .gitignore ├── shaders ├── sprite_Unlit_varying.def.sc ├── model_Unlit_varying.def.sc ├── model_BackDistortion_varying.def.sc ├── sprite_BackDistortion_varying.def.sc ├── model_Lit_varying.def.sc ├── sprite_Lit_varying.def.sc ├── defines.sh ├── model_AdvancedUnlit_varying.def.sc ├── model_AdvancedBackDistortion_varying.def.sc ├── model_AdvancedLit_varying.def.sc ├── sprite_AdvancedUnlit_varying.def.sc ├── sprite_AdvancedBackDistortion_varying.def.sc ├── sprite_AdvancedLit_varying.def.sc ├── sprite_unlit_vs.fx.sc ├── make.lua ├── model_unlit_vs.fx.sc ├── sprite_lit_vs.fx.sc ├── sprite_distortion_vs.fx.sc ├── model_lit_vs.fx.sc ├── model_distortion_vs.fx.sc ├── model_distortion_ps.fx.sc ├── model_unlit_ps.fx.sc ├── model_lit_ps.fx.sc ├── ad_sprite_unlit_vs.fx.sc ├── ad_sprite_lit_vs.fx.sc ├── ad_sprite_distortion_vs.fx.sc ├── ad_model_unlit_vs.fx.sc ├── ad_model_distortion_ps.fx.sc ├── ad_model_lit_vs.fx.sc ├── ad_model_distortion_vs.fx.sc ├── ad_model_unlit_ps.fx.sc └── ad_model_lit_ps.fx.sc ├── efkmatc ├── make.lua ├── efkmat.cpp └── genbgfxshader.lua ├── luabinding ├── make.lua └── efkcallback.c ├── LICENSE ├── renderer ├── bgfxrenderer.h └── make.lua ├── Makefile └── README.md /examples/resources/Light.efk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Light.efk -------------------------------------------------------------------------------- /examples/resources/Laser01.efk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Laser01.efk -------------------------------------------------------------------------------- /examples/resources/Parts/Aura.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Aura.png -------------------------------------------------------------------------------- /examples/resources/Parts/Null.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Null.png -------------------------------------------------------------------------------- /examples/resources/Parts/Ring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Ring.png -------------------------------------------------------------------------------- /examples/resources/toonwater.efk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/toonwater.efk -------------------------------------------------------------------------------- /examples/resources/Parts/Aura_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Aura_2.png -------------------------------------------------------------------------------- /examples/resources/Parts/Noise2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Noise2.png -------------------------------------------------------------------------------- /examples/resources/Parts/Noise3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Noise3.png -------------------------------------------------------------------------------- /examples/resources/Parts/Noise4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Noise4.png -------------------------------------------------------------------------------- /examples/resources/Parts/Ring2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Ring2.png -------------------------------------------------------------------------------- /examples/resources/Texture/Arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Arrow.png -------------------------------------------------------------------------------- /examples/resources/Texture/Fire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Fire.png -------------------------------------------------------------------------------- /examples/resources/Texture/Glass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Glass.png -------------------------------------------------------------------------------- /examples/resources/Texture/Halo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Halo.png -------------------------------------------------------------------------------- /examples/resources/Texture/Line1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Line1.png -------------------------------------------------------------------------------- /examples/resources/Texture/Line3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Line3.png -------------------------------------------------------------------------------- /examples/resources/Texture/Line4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Line4.png -------------------------------------------------------------------------------- /examples/resources/Texture/Line5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Line5.png -------------------------------------------------------------------------------- /examples/resources/Texture/Smoke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Smoke.png -------------------------------------------------------------------------------- /examples/resources/Texture/Star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Star.png -------------------------------------------------------------------------------- /examples/resources/Texture/Wind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Wind.png -------------------------------------------------------------------------------- /examples/resources/Parts/Particle1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Particle1.png -------------------------------------------------------------------------------- /examples/resources/Parts/Particle2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Particle2.png -------------------------------------------------------------------------------- /examples/resources/Parts/Tube.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Tube.efkmodel -------------------------------------------------------------------------------- /examples/resources/Texture/Burst_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Burst_1.png -------------------------------------------------------------------------------- /examples/resources/Texture/Burst_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Burst_2.png -------------------------------------------------------------------------------- /examples/resources/Texture/Burst_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Burst_3.png -------------------------------------------------------------------------------- /examples/resources/Texture/Feather.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Feather.png -------------------------------------------------------------------------------- /examples/resources/Texture/Line_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Line_2.png -------------------------------------------------------------------------------- /examples/resources/Texture/Splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Splash.png -------------------------------------------------------------------------------- /examples/resources/Texture/UVCheck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/UVCheck.png -------------------------------------------------------------------------------- /examples/resources/sword_ember.efkefc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/sword_ember.efkefc -------------------------------------------------------------------------------- /examples/resources/Model/Arrow.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Model/Arrow.efkmodel -------------------------------------------------------------------------------- /examples/resources/Parts/AuraTube.efkmat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/AuraTube.efkmat -------------------------------------------------------------------------------- /examples/resources/Parts/ColorNoise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/ColorNoise.png -------------------------------------------------------------------------------- /examples/resources/Parts/Gradient_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Gradient_2.png -------------------------------------------------------------------------------- /examples/resources/Parts/Gradient__1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Gradient__1.png -------------------------------------------------------------------------------- /examples/resources/Parts/Gradient__3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Gradient__3.png -------------------------------------------------------------------------------- /examples/resources/Parts/Impact.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Impact.efkmodel -------------------------------------------------------------------------------- /examples/resources/Parts/ParticleCore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/ParticleCore.png -------------------------------------------------------------------------------- /examples/resources/Parts/Round.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Round.efkmodel -------------------------------------------------------------------------------- /examples/resources/Simple_Model_UV.efkefc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Simple_Model_UV.efkefc -------------------------------------------------------------------------------- /examples/resources/Texture/Fire_Blur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Fire_Blur.png -------------------------------------------------------------------------------- /examples/resources/Texture/ModelFade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/ModelFade.png -------------------------------------------------------------------------------- /examples/resources/Texture/Particle01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Particle01.png -------------------------------------------------------------------------------- /examples/resources/Texture/Particle02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Particle02.png -------------------------------------------------------------------------------- /examples/resources/Texture/Shockwave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Shockwave.png -------------------------------------------------------------------------------- /examples/resources/Texture/Tentacle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Tentacle.png -------------------------------------------------------------------------------- /examples/resources/Texture/Yakiniku.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Yakiniku.png -------------------------------------------------------------------------------- /examples/resources/sword_lightning.efkefc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/sword_lightning.efkefc -------------------------------------------------------------------------------- /examples/resources/Parts/RadiarNoise.efkmat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/RadiarNoise.efkmat -------------------------------------------------------------------------------- /examples/resources/Parts/ToonImpact.efkmat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/ToonImpact.efkmat -------------------------------------------------------------------------------- /examples/resources/Texture/Fire_Single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Fire_Single.png -------------------------------------------------------------------------------- /examples/resources/Texture/Humanity_Eye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Humanity_Eye.png -------------------------------------------------------------------------------- /examples/resources/Texture/LaserMain01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/LaserMain01.png -------------------------------------------------------------------------------- /examples/resources/Texture/Thunder_Bold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Thunder_Bold.png -------------------------------------------------------------------------------- /examples/resources/Texture/Thunder_Thin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Thunder_Thin.png -------------------------------------------------------------------------------- /examples/resources/Model/ShortLance.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Model/ShortLance.efkmodel -------------------------------------------------------------------------------- /examples/resources/Parts/ToonWaterTube.efkmat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/ToonWaterTube.efkmat -------------------------------------------------------------------------------- /examples/resources/Texture/FractalNoise_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/FractalNoise_1.png -------------------------------------------------------------------------------- /examples/resources/Texture/FractalNoise_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/FractalNoise_2.png -------------------------------------------------------------------------------- /examples/resources/Texture/FractalNoise_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/FractalNoise_3.png -------------------------------------------------------------------------------- /examples/resources/Texture/FractalNoise_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/FractalNoise_4.png -------------------------------------------------------------------------------- /examples/resources/Texture/IntensiveLine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/IntensiveLine.png -------------------------------------------------------------------------------- /examples/resources/Texture/NoiseAnimation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/NoiseAnimation.png -------------------------------------------------------------------------------- /examples/resources/Texture/Particle_Hard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Particle_Hard.png -------------------------------------------------------------------------------- /examples/resources/Texture/Particle_Soft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Particle_Soft.png -------------------------------------------------------------------------------- /examples/resources/Texture/Smoke_Lighting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/Smoke_Lighting.png -------------------------------------------------------------------------------- /examples/resources/Parts/AuraTubeModel.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/AuraTubeModel.efkmodel -------------------------------------------------------------------------------- /examples/resources/Parts/Noise_Distortion.efkmat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Parts/Noise_Distortion.efkmat -------------------------------------------------------------------------------- /examples/resources/Texture/ExperimentalBlur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/ExperimentalBlur.png -------------------------------------------------------------------------------- /examples/resources/Texture/ExperimentalNoise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Texture/ExperimentalNoise.png -------------------------------------------------------------------------------- /examples/resources/Model/LongSword_Blade.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Model/LongSword_Blade.efkmodel -------------------------------------------------------------------------------- /examples/resources/Model/LongSword_Handle.efkmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudwu/efkbgfx/HEAD/examples/resources/Model/LongSword_Handle.efkmodel -------------------------------------------------------------------------------- /make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm.EfkDir = "../../" 4 | lm.BgfxBinDir = "../bgfx/.build/win64_vs2022/bin" 5 | lm:import "shaders/make.lua" 6 | lm:import "renderer/make.lua" 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | bin 3 | *.code-workspace 4 | .vscode 5 | shaders/*.bin 6 | shaders/*.hlsl 7 | examples/cube/shaders/*.bin 8 | examples/cube/shaders/*.hlsl 9 | *.so 10 | *.dll 11 | *.ilk -------------------------------------------------------------------------------- /examples/cube/shaders/varying.def.sc: -------------------------------------------------------------------------------- 1 | vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0); 2 | 3 | vec3 a_position : POSITION; 4 | vec4 a_color0 : COLOR0; 5 | 6 | vec2 v_texcoord0 : TEXCOORD0; -------------------------------------------------------------------------------- /shaders/sprite_Unlit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec4 a_color0 : COLOR0; 3 | vec2 a_texcoord0 : TEXCOORD0; 4 | vec4 v_Color : TEXCOORD0; 5 | vec2 v_UV : TEXCOORD1; 6 | vec4 v_PosP : TEXCOORD2; -------------------------------------------------------------------------------- /examples/cube/shaders/fs_fullscreen.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0 2 | 3 | #include 4 | 5 | SAMPLER2D(s_scene, 0); 6 | 7 | void main() 8 | { 9 | gl_FragColor = texture2D(s_scene, v_texcoord0); 10 | } -------------------------------------------------------------------------------- /shaders/model_Unlit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec3 a_normal : NORMAL; 3 | vec3 a_bitangent : BITANGENT; 4 | vec3 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec4 a_color0 : COLOR0; 7 | vec4 v_Color : TEXCOORD0; 8 | vec2 v_UV : TEXCOORD1; 9 | vec4 v_PosP : TEXCOORD2; -------------------------------------------------------------------------------- /examples/cube/shaders/fs_cube.sc: -------------------------------------------------------------------------------- 1 | $input v_color0 2 | 3 | /* 4 | * Copyright 2011-2022 Branimir Karadzic. All rights reserved. 5 | * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE 6 | */ 7 | 8 | #include "../common/common.sh" 9 | 10 | void main() 11 | { 12 | gl_FragColor = v_color0; 13 | } 14 | -------------------------------------------------------------------------------- /efkmatc/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | package.path = "./?.lua;../?.lua" 3 | 4 | require "buildscripts.common" 5 | 6 | lm:lua_dll "efkmat" { 7 | includes = EfkLib_Includes, 8 | sources = { 9 | "efkmat.cpp", 10 | }, 11 | deps = "source_efklib", 12 | bindir = lm.workdir 13 | } 14 | -------------------------------------------------------------------------------- /luabinding/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | lm:import "../renderer/make.lua" 4 | 5 | lm:lua_source "source_effekseer_callback" { 6 | sources = { 7 | "efkcallback.c", 8 | }, 9 | } 10 | 11 | lm:lua_dll "effekseer_callback" { 12 | deps = { 13 | "source_efkbgfx_lib", 14 | "source_effekseer_callback", 15 | } 16 | } -------------------------------------------------------------------------------- /shaders/model_BackDistortion_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec3 a_normal : NORMAL; 3 | vec3 a_bitangent : BITANGENT; 4 | vec3 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec4 a_color0 : COLOR0; 7 | vec2 v_UV : TEXCOORD0; 8 | vec4 v_ProjBinormal : TEXCOORD1; 9 | vec4 v_ProjTangent : TEXCOORD2; 10 | vec4 v_PosP : TEXCOORD3; 11 | vec4 v_Color : TEXCOORD4; -------------------------------------------------------------------------------- /shaders/sprite_BackDistortion_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec4 a_color0 : COLOR0; 3 | vec4 a_normal : NORMAL; 4 | vec4 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec2 a_texcoord1 : TEXCOORD1; 7 | vec2 v_UV : TEXCOORD0; 8 | vec4 v_ProjBinormal : TEXCOORD1; 9 | vec4 v_ProjTangent : TEXCOORD2; 10 | vec4 v_PosP : TEXCOORD3; 11 | vec4 v_Color : TEXCOORD4; -------------------------------------------------------------------------------- /shaders/model_Lit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec3 a_normal : NORMAL; 3 | vec3 a_bitangent : BITANGENT; 4 | vec3 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec4 a_color0 : COLOR0; 7 | vec4 v_Color : TEXCOORD0; 8 | vec2 v_UV : TEXCOORD1; 9 | vec3 v_WorldN : TEXCOORD2; 10 | vec3 v_WorldB : TEXCOORD3; 11 | vec3 v_WorldT : TEXCOORD4; 12 | vec4 v_PosP : TEXCOORD5; -------------------------------------------------------------------------------- /shaders/sprite_Lit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec4 a_color0 : COLOR0; 3 | vec4 a_normal : NORMAL; 4 | vec4 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec2 a_texcoord1 : TEXCOORD1; 7 | vec4 v_Color : TEXCOORD0; 8 | vec2 v_UV : TEXCOORD1; 9 | vec3 v_WorldN : TEXCOORD2; 10 | vec3 v_WorldB : TEXCOORD3; 11 | vec3 v_WorldT : TEXCOORD4; 12 | vec4 v_PosP : TEXCOORD5; -------------------------------------------------------------------------------- /examples/cube/shaders/vs_cube.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_color0 2 | $output v_color0 3 | 4 | /* 5 | * Copyright 2011-2022 Branimir Karadzic. All rights reserved. 6 | * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE 7 | */ 8 | 9 | #include "../common/common.sh" 10 | 11 | void main() 12 | { 13 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); 14 | v_color0 = a_color0; 15 | } 16 | -------------------------------------------------------------------------------- /examples/cube/shaders/vs_fullscreen.sc: -------------------------------------------------------------------------------- 1 | $output v_texcoord0 2 | #include 3 | 4 | void main() 5 | { 6 | vec2 coord = vec2( 7 | float((gl_VertexID & 1) << 2), 8 | float((gl_VertexID & 2) << 1)); 9 | v_texcoord0 = coord * 0.5; 10 | #if !BGFX_SHADER_LANGUAGE_GLSL 11 | v_texcoord0.y = 1.0 - v_texcoord0.y; 12 | #endif //BGFX_SHADER_LANGUAGE_GLSL 13 | 14 | gl_Position = vec4(coord - 1.0, 0.0, 1.0); 15 | } -------------------------------------------------------------------------------- /shaders/defines.sh: -------------------------------------------------------------------------------- 1 | vec3 vec3_splat(vec3 v) 2 | { 3 | return v; 4 | } 5 | 6 | vec2 vec2_splat(vec2 v) 7 | { 8 | return v; 9 | } 10 | 11 | vec4 vec4_splat(vec4 v) 12 | { 13 | return v; 14 | } 15 | 16 | vec3 to_linear(vec3 _rgb) 17 | { 18 | return pow(abs(_rgb), vec3_splat(2.2) ); 19 | } 20 | 21 | vec4 to_linear(vec4 _rgba) 22 | { 23 | return vec4(to_linear(_rgba.xyz), _rgba.w); 24 | } 25 | 26 | #define gl_InstanceIndex gl_InstanceID -------------------------------------------------------------------------------- /shaders/model_AdvancedUnlit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec3 a_normal : NORMAL; 3 | vec3 a_bitangent : BITANGENT; 4 | vec3 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec4 a_color0 : COLOR0; 7 | vec4 v_Color : TEXCOORD0; 8 | vec4 v_UV_Others : TEXCOORD1; 9 | vec3 v_WorldN : TEXCOORD2; 10 | vec4 v_Alpha_Dist_UV : TEXCOORD3; 11 | vec4 v_Blend_Alpha_Dist_UV : TEXCOORD4; 12 | vec4 v_Blend_FBNextIndex_UV : TEXCOORD5; 13 | vec4 v_PosP : TEXCOORD6; -------------------------------------------------------------------------------- /shaders/model_AdvancedBackDistortion_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec3 a_normal : NORMAL; 3 | vec3 a_bitangent : BITANGENT; 4 | vec3 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec4 a_color0 : COLOR0; 7 | vec4 v_UV_Others : TEXCOORD0; 8 | vec4 v_ProjBinormal : TEXCOORD1; 9 | vec4 v_ProjTangent : TEXCOORD2; 10 | vec4 v_PosP : TEXCOORD3; 11 | vec4 v_Color : TEXCOORD4; 12 | vec4 v_Alpha_Dist_UV : TEXCOORD5; 13 | vec4 v_Blend_Alpha_Dist_UV : TEXCOORD6; 14 | vec4 v_Blend_FBNextIndex_UV : TEXCOORD7; -------------------------------------------------------------------------------- /shaders/model_AdvancedLit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec3 a_normal : NORMAL; 3 | vec3 a_bitangent : BITANGENT; 4 | vec3 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec4 a_color0 : COLOR0; 7 | vec4 v_Color : TEXCOORD0; 8 | vec4 v_UV_Others : TEXCOORD1; 9 | vec3 v_WorldN : TEXCOORD2; 10 | vec3 v_WorldB : TEXCOORD3; 11 | vec3 v_WorldT : TEXCOORD4; 12 | vec4 v_Alpha_Dist_UV : TEXCOORD5; 13 | vec4 v_Blend_Alpha_Dist_UV : TEXCOORD6; 14 | vec4 v_Blend_FBNextIndex_UV : TEXCOORD7; 15 | vec4 v_PosP : TEXCOORD8; -------------------------------------------------------------------------------- /shaders/sprite_AdvancedUnlit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec4 a_color0 : COLOR0; 3 | vec2 a_texcoord0 : TEXCOORD0; 4 | vec4 a_texcoord1 : TEXCOORD1; 5 | vec2 a_texcoord2 : TEXCOORD2; 6 | vec4 a_texcoord3 : TEXCOORD3; 7 | float a_texcoord4 : TEXCOORD4; 8 | float a_texcoord5 : TEXCOORD5; 9 | vec4 v_Color : TEXCOORD0; 10 | vec4 v_UV_Others : TEXCOORD1; 11 | vec3 v_WorldN : TEXCOORD2; 12 | vec4 v_Alpha_Dist_UV : TEXCOORD3; 13 | vec4 v_Blend_Alpha_Dist_UV : TEXCOORD4; 14 | vec4 v_Blend_FBNextIndex_UV : TEXCOORD5; 15 | vec4 v_PosP : TEXCOORD6; -------------------------------------------------------------------------------- /shaders/sprite_AdvancedBackDistortion_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec4 a_color0 : COLOR0; 3 | vec4 a_normal : NORMAL; 4 | vec4 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec2 a_texcoord1 : TEXCOORD1; 7 | vec4 a_texcoord2 : TEXCOORD2; 8 | vec2 a_texcoord3 : TEXCOORD3; 9 | vec4 a_texcoord4 : TEXCOORD4; 10 | float a_texcoord5 : TEXCOORD5; 11 | float a_texcoord6 : TEXCOORD6; 12 | vec4 v_UV_Others : TEXCOORD0; 13 | vec4 v_ProjBinormal : TEXCOORD1; 14 | vec4 v_ProjTangent : TEXCOORD2; 15 | vec4 v_PosP : TEXCOORD3; 16 | vec4 v_Color : TEXCOORD4; 17 | vec4 v_Alpha_Dist_UV : TEXCOORD5; 18 | vec4 v_Blend_Alpha_Dist_UV : TEXCOORD6; 19 | vec4 v_Blend_FBNextIndex_UV : TEXCOORD7; -------------------------------------------------------------------------------- /shaders/sprite_AdvancedLit_varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec4 a_color0 : COLOR0; 3 | vec4 a_normal : NORMAL; 4 | vec4 a_tangent : TANGENT; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec2 a_texcoord1 : TEXCOORD1; 7 | vec4 a_texcoord2 : TEXCOORD2; 8 | vec2 a_texcoord3 : TEXCOORD3; 9 | vec4 a_texcoord4 : TEXCOORD4; 10 | float a_texcoord5 : TEXCOORD5; 11 | float a_texcoord6 : TEXCOORD6; 12 | vec4 v_Color : TEXCOORD0; 13 | vec4 v_UV_Others : TEXCOORD1; 14 | vec3 v_WorldN : TEXCOORD2; 15 | vec3 v_WorldB : TEXCOORD3; 16 | vec3 v_WorldT : TEXCOORD4; 17 | vec4 v_Alpha_Dist_UV : TEXCOORD5; 18 | vec4 v_Blend_Alpha_Dist_UV : TEXCOORD6; 19 | vec4 v_Blend_FBNextIndex_UV : TEXCOORD7; 20 | vec4 v_PosP : TEXCOORD8; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 codingnow.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /shaders/sprite_unlit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_color0 a_texcoord0 2 | $output v_Color v_UV v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCamera; 7 | uniform mat4 u_mCameraProj; 8 | uniform vec4 u_mUVInversed; 9 | uniform vec4 u_mflipbookParameter; 10 | 11 | 12 | struct VS_Input 13 | { 14 | vec3 Pos; 15 | vec4 Color; 16 | vec2 UV; 17 | }; 18 | 19 | struct VS_Output 20 | { 21 | vec4 PosVS; 22 | vec4 Color; 23 | vec2 UV; 24 | vec4 PosP; 25 | }; 26 | 27 | VS_Output _main(VS_Input Input) 28 | { 29 | VS_Output Output = (VS_Output)0; 30 | vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 31 | Output.PosVS = mul(u_mCameraProj, worldPos); 32 | Output.Color = Input.Color; 33 | vec2 uv1 = Input.UV; 34 | uv1.y = u_mUVInversed.x + (u_mUVInversed.y * uv1.y); 35 | Output.UV = uv1; 36 | Output.PosP = Output.PosVS; 37 | return Output; 38 | } 39 | 40 | void main() 41 | { 42 | VS_Input Input; 43 | Input.Pos = a_position; 44 | Input.Color = a_color0; 45 | Input.UV = a_texcoord0; 46 | VS_Output flattenTemp = _main(Input); 47 | vec4 _position = flattenTemp.PosVS; 48 | gl_Position = _position; 49 | v_Color = flattenTemp.Color; 50 | v_UV = flattenTemp.UV; 51 | v_PosP = flattenTemp.PosP; 52 | } 53 | -------------------------------------------------------------------------------- /renderer/bgfxrenderer.h: -------------------------------------------------------------------------------- 1 | #ifndef effekseer_bgfx_renderer_h 2 | #define effekseer_bgfx_renderer_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #if defined(_MSC_VER) && defined(EFXBGFX_DYNAMIC_LIB) 9 | # if EFXBGFX_EXPORTS 10 | # define EFXBGFX_API __declspec(dllexport) 11 | # else 12 | # define EFXBGFX_API __declspec(dllimport) 13 | # endif 14 | #else //!_MSC_VER 15 | # define EFXBGFX_API 16 | #endif //_MSC_VER 17 | 18 | #define TEXTURE_BACKGROUND 0 19 | #define TEXTURE_DEPTH 1 20 | 21 | namespace EffekseerRendererBGFX { 22 | struct DepthReconstructionParameter { 23 | float DepthBufferScale; 24 | float DepthBufferOffset; 25 | float ProjectionMatrix33; 26 | float ProjectionMatrix34; 27 | float ProjectionMatrix43; 28 | float ProjectionMatrix44; 29 | }; 30 | 31 | struct InitArgs { 32 | int squareMaxCount; 33 | bgfx_view_id_t viewid; 34 | bgfx_interface_vtbl_t *bgfx; 35 | bgfx_shader_handle_t (*shader_load)(const char *mat, const char *name, const char *type, void *ud); 36 | bgfx_texture_handle_t (*texture_get)(int texture_type, void *parm, void *ud); // background or depth (with param) 37 | int (*texture_load)(const char *name, int srgb, void *ud); 38 | void (*texture_unload)(int id, void *ud); 39 | bgfx_texture_handle_t (*texture_handle)(int id, void *ud); // translate id to handle 40 | void * ud; 41 | bool invz; 42 | }; 43 | 44 | EFXBGFX_API EffekseerRenderer::RendererRef CreateRenderer(struct InitArgs *init); 45 | EFXBGFX_API Effekseer::ModelRendererRef CreateModelRenderer(EffekseerRenderer::RendererRef renderer, struct InitArgs *init); 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | AR= ar rc 2 | RANLIB= ranlib 3 | RM= rm -f 4 | CC= gcc 5 | 6 | EFFEKSEER_DIR=../Effekseer/Dev/Cpp 7 | BGFX_DIR=../bgfx 8 | BX_DIR=../bx 9 | 10 | CFLAGS=-O2 -Wall -std=c++17 -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-sign-compare 11 | SHARED=--shared 12 | EFFEKSEER_INC=-I $(EFFEKSEER_DIR)/Effekseer -I $(EFFEKSEER_DIR) 13 | BGFX_INC=-I $(BGFX_DIR)/include -I $(BX_DIR)/include 14 | LIBS=-lws2_32 -lstdc++ 15 | BGFX_LIBS=-L$(BGFX_DIR)/.build/win64_mingw-gcc/bin -lbgfx-shared-libRelease 16 | LUA_INC=-I/usr/local/include 17 | LUA_LIB=-L/usr/local/bin -llua54 18 | 19 | EFK_SOURCE_DIRS:=$(wildcard $(EFFEKSEER_DIR)/Effekseer/Effekseer/*/) 20 | SOURCE_DIRS:=\ 21 | $(EFFEKSEER_DIR)/Effekseer/Effekseer/\ 22 | $(EFFEKSEER_DIR)/EffekseerMaterial/\ 23 | $(EFFEKSEER_DIR)/EffekseerRendererCommon/\ 24 | $(EFK_SOURCE_DIRS) 25 | 26 | find_files=$(wildcard $(dir)*.cpp) 27 | SOURCES:=$(foreach dir,$(SOURCE_DIRS),$(find_files)) 28 | OBJECTS:=$(SOURCES:.cpp=.o) 29 | 30 | all : efkbgfx.dll efkmat.dll effekseer.dll 31 | 32 | $(OBJECTS) : %.o : %.cpp 33 | $(CC) -c $(CFLAGS) -o $@ $^ $(EFFEKSEER_INC) 34 | 35 | libeffekseer.a : $(OBJECTS) 36 | $(AR) $@ $^ && $(RANLIB) $@ 37 | 38 | 39 | EFKMATC_SOURCES:=$(wildcard efkmatc/*.cpp) 40 | EFKBGFX_SOURCES:=$(wildcard renderer/*.cpp) 41 | 42 | efkmat.dll : $(EFKMATC_SOURCES) libeffekseer.a 43 | $(CC) -o $@ $(SHARED) $(CFLAGS) -o $@ $^ $(EFFEKSEER_INC) $(LIBS) $(LUA_INC) $(LUA_LIB) 44 | 45 | 46 | efkbgfx.dll : $(EFKBGFX_SOURCES) libeffekseer.a 47 | $(CC) -o $@ $(SHARED) $(CFLAGS) -DMaxInstanced=20 -o $@ $^ $(EFFEKSEER_INC) $(BGFX_INC) $(BGFX_LIBS) $(LIBS) 48 | 49 | effekseer.dll : luabinding/efkcallback.c 50 | $(CC) -o $@ $(SHARED) -O2 -Wall $^ $(LUA_INC) $(LUA_LIB) 51 | 52 | clean : 53 | $(RM) libeffekseer.a efkbgfx.dll efkmat.dll effekseer.dll $(OBJECTS) 54 | -------------------------------------------------------------------------------- /shaders/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | local fs = require "bee.filesystem" 3 | 4 | package.path = "./?.lua;../?.lua" 5 | 6 | require "buildscripts.common" 7 | 8 | lm:import "../efkmatc/make.lua" 9 | 10 | local cwd = fs.path(lm.workdir) 11 | local vulkan_shader_dir = (cwd / lm.EfkDir) / "Effekseer/Dev/Cpp/EffekseerRendererVulkan/EffekseerRendererVulkan/Shader" 12 | if not fs.exists(vulkan_shader_dir) then 13 | error("Vulkan shader path is not valid: " .. vulkan_shader_dir:string()) 14 | end 15 | local shader_output_dir = cwd 16 | 17 | local sc = require "buildscripts.shader_compile" 18 | 19 | local function print_cfg(cfg) 20 | for k, v in pairs(cfg) do 21 | print(k, tostring(v)) 22 | end 23 | end 24 | 25 | local function cvt2bgfxshader(input, output, shadertype, stage, modeltype) 26 | lm:build { 27 | "$luamake", "lua", "@../efkmatc/genbgfxshader.lua", "$in", "$out", shadertype, stage, modeltype, "@../efkmatc", lm.os, 28 | deps = "efkmat", 29 | description = "Compile sc: $out", 30 | input = input:string(), 31 | output = output:string(), 32 | } 33 | end 34 | 35 | local scfiles = {} 36 | 37 | local function get_shaders_info(src_shaderpath) 38 | local ss = {} 39 | for fn in fs.pairs(src_shaderpath) do 40 | local ext = fn:extension():string():lower() 41 | if ext == ".vert" or ext == ".frag" then 42 | ss[#ss+1] = ShaderInfoFromFilename(fn:filename():string()) 43 | end 44 | end 45 | 46 | return ss 47 | end 48 | 49 | for _, s in ipairs(get_shaders_info(vulkan_shader_dir)) do 50 | local input = vulkan_shader_dir / s.filename 51 | local scfile = shader_output_dir / fs.path(s.filename):replace_extension "sc" 52 | scfiles[#scfiles+1] = scfile 53 | cvt2bgfxshader(input, scfile, s.shadertype, s.stage, s.modeltype) 54 | end 55 | 56 | lm:phony "efxbgfx_shaders" { 57 | input = scfiles 58 | } -------------------------------------------------------------------------------- /shaders/model_unlit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_normal a_bitangent a_tangent a_texcoord0 a_color0 2 | $output v_Color v_UV v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCameraProj; 7 | uniform mat4 u_mModel_Inst[40]; 8 | uniform vec4 u_fUV[40]; 9 | uniform vec4 u_fModelColor[40]; 10 | uniform vec4 u_fLightDirection; 11 | uniform vec4 u_fLightColor; 12 | uniform vec4 u_fLightAmbient; 13 | uniform vec4 u_mUVInversed; 14 | 15 | 16 | struct VS_Input 17 | { 18 | vec3 Pos; 19 | vec3 Normal; 20 | vec3 Binormal; 21 | vec3 Tangent; 22 | vec2 UV; 23 | vec4 Color; 24 | uint Index; 25 | }; 26 | 27 | struct VS_Output 28 | { 29 | vec4 PosVS; 30 | vec4 Color; 31 | vec2 UV; 32 | vec4 PosP; 33 | }; 34 | 35 | VS_Output _main(VS_Input Input) 36 | { 37 | uint index = Input.Index; 38 | mat4 mModel = u_mModel_Inst[index]; 39 | vec4 uv = u_fUV[index]; 40 | vec4 modelColor = u_fModelColor[index] * Input.Color; 41 | VS_Output Output = (VS_Output)0; 42 | vec4 localPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 43 | vec4 worldPos = mul(mModel, localPos); 44 | Output.PosVS = mul(u_mCameraProj, worldPos); 45 | Output.Color = modelColor; 46 | vec2 outputUV = Input.UV; 47 | outputUV.x = (outputUV.x * uv.z) + uv.x; 48 | outputUV.y = (outputUV.y * uv.w) + uv.y; 49 | outputUV.y = u_mUVInversed.x + (u_mUVInversed.y * outputUV.y); 50 | Output.UV = outputUV; 51 | Output.PosP = Output.PosVS; 52 | return Output; 53 | } 54 | 55 | void main() 56 | { 57 | VS_Input Input; 58 | Input.Pos = a_position; 59 | Input.Normal = a_normal; 60 | Input.Binormal = a_bitangent; 61 | Input.Tangent = a_tangent; 62 | Input.UV = a_texcoord0; 63 | Input.Color = a_color0; 64 | Input.Index = uint(gl_InstanceIndex); 65 | VS_Output flattenTemp = _main(Input); 66 | vec4 _position = flattenTemp.PosVS; 67 | gl_Position = _position; 68 | v_Color = flattenTemp.Color; 69 | v_UV = flattenTemp.UV; 70 | v_PosP = flattenTemp.PosP; 71 | } 72 | -------------------------------------------------------------------------------- /renderer/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | 3 | package.path = "./?.lua;../?.lua" 4 | 5 | require "buildscripts.common" 6 | 7 | lm.builddir = lm.builddir or ("build/%s/%s"):format(Plat, lm.mode) 8 | lm.bindir = lm.bindir or ("bin/%s/%s"):format(Plat, lm.mode) 9 | 10 | local gcc_warnings = { 11 | "-Wno-sign-compare", 12 | "-Wno-unused-but-set-variable", 13 | "-Wno-format", 14 | "-Wno-unused-variable", 15 | } 16 | 17 | local clang_warnings = { 18 | "-Wno-delete-non-abstract-non-virtual-dtor", 19 | "-Wno-unused-but-set-variable", 20 | "-Wno-unused-variable", 21 | "-Wno-inconsistent-missing-override", 22 | } 23 | 24 | lm:source_set "source_efklib" { 25 | includes = EfkLib_Includes, 26 | sources = { 27 | EfkSrc / "Effekseer/Effekseer/**/*.cpp", 28 | EfkSrc / "EffekseerMaterial/*.cpp", 29 | EfkSrc / "EffekseerRendererCommon/**/*.cpp", 30 | }, 31 | gcc = { 32 | flags = gcc_warnings 33 | }, 34 | clang = { 35 | flags = clang_warnings, 36 | } 37 | } 38 | 39 | lm:lib "efklib" { 40 | deps = "source_efklib", 41 | } 42 | 43 | MaxInstanced = 20 44 | 45 | local function create_source_efkbgfx(defines) 46 | return { 47 | includes = { 48 | EfkLib_Includes, 49 | }, 50 | sources = { 51 | "bgfxrenderer.cpp", 52 | }, 53 | deps = { 54 | "source_efklib" 55 | }, 56 | defines = { 57 | "BX_CONFIG_DEBUG=" .. (lm.mode == "debug" and 1 or 0), 58 | "MaxInstanced=" .. MaxInstanced, 59 | defines, 60 | }, 61 | gcc = { 62 | flags = gcc_warnings 63 | }, 64 | clang = { 65 | flags = clang_warnings, 66 | } 67 | } 68 | end 69 | 70 | lm:source_set "source_efkbgfx_lib" ( 71 | create_source_efkbgfx() 72 | ) 73 | 74 | lm:source_set "source_efkbgfx" ( 75 | create_source_efkbgfx{ 76 | "EFXBGFX_DYNAMIC_LIB=1", 77 | "EFXBGFX_EXPORTS=1", 78 | } 79 | ) 80 | 81 | lm:dll "efkbgfx" { 82 | deps = {"source_efkbgfx"}, 83 | } 84 | -------------------------------------------------------------------------------- /shaders/sprite_lit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_color0 a_normal a_tangent a_texcoord0 a_texcoord1 2 | $output v_Color v_UV v_WorldN v_WorldB v_WorldT v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCamera; 7 | uniform mat4 u_mCameraProj; 8 | uniform vec4 u_mUVInversed; 9 | uniform vec4 u_mflipbookParameter; 10 | 11 | 12 | struct VS_Input 13 | { 14 | vec3 Pos; 15 | vec4 Color; 16 | vec4 Normal; 17 | vec4 Tangent; 18 | vec2 UV1; 19 | vec2 UV2; 20 | }; 21 | 22 | struct VS_Output 23 | { 24 | vec4 PosVS; 25 | vec4 Color; 26 | vec2 UV; 27 | vec3 WorldN; 28 | vec3 WorldB; 29 | vec3 WorldT; 30 | vec4 PosP; 31 | }; 32 | 33 | VS_Output _main(VS_Input Input) 34 | { 35 | VS_Output Output = (VS_Output)0; 36 | vec4 worldNormal = vec4((Input.Normal.xyz - vec3_splat(0.5)) * 2.0, 0.0); 37 | vec4 worldTangent = vec4((Input.Tangent.xyz - vec3_splat(0.5)) * 2.0, 0.0); 38 | vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0); 39 | vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 40 | Output.PosVS = mul(u_mCameraProj, worldPos); 41 | Output.Color = Input.Color; 42 | vec2 uv1 = Input.UV1; 43 | uv1.y = u_mUVInversed.x + (u_mUVInversed.y * uv1.y); 44 | Output.UV = uv1; 45 | Output.WorldN = worldNormal.xyz; 46 | Output.WorldB = worldBinormal.xyz; 47 | Output.WorldT = worldTangent.xyz; 48 | Output.PosP = Output.PosVS; 49 | return Output; 50 | } 51 | 52 | void main() 53 | { 54 | VS_Input Input; 55 | Input.Pos = a_position; 56 | Input.Color = a_color0; 57 | Input.Normal = a_normal; 58 | Input.Tangent = a_tangent; 59 | Input.UV1 = a_texcoord0; 60 | Input.UV2 = a_texcoord1; 61 | VS_Output flattenTemp = _main(Input); 62 | vec4 _position = flattenTemp.PosVS; 63 | gl_Position = _position; 64 | v_Color = flattenTemp.Color; 65 | v_UV = flattenTemp.UV; 66 | v_WorldN = flattenTemp.WorldN; 67 | v_WorldB = flattenTemp.WorldB; 68 | v_WorldT = flattenTemp.WorldT; 69 | v_PosP = flattenTemp.PosP; 70 | } 71 | -------------------------------------------------------------------------------- /shaders/sprite_distortion_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_color0 a_normal a_tangent a_texcoord0 a_texcoord1 2 | $output v_UV v_ProjBinormal v_ProjTangent v_PosP v_Color 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCamera; 7 | uniform mat4 u_mCameraProj; 8 | uniform vec4 u_mUVInversed; 9 | uniform vec4 u_mflipbookParameter; 10 | 11 | 12 | struct VS_Input 13 | { 14 | vec3 Pos; 15 | vec4 Color; 16 | vec4 Normal; 17 | vec4 Tangent; 18 | vec2 UV1; 19 | vec2 UV2; 20 | }; 21 | 22 | struct VS_Output 23 | { 24 | vec4 PosVS; 25 | vec2 UV; 26 | vec4 ProjBinormal; 27 | vec4 ProjTangent; 28 | vec4 PosP; 29 | vec4 Color; 30 | }; 31 | 32 | VS_Output _main(VS_Input Input) 33 | { 34 | VS_Output Output = (VS_Output)0; 35 | vec4 worldNormal = vec4((Input.Normal.xyz - vec3_splat(0.5)) * 2.0, 0.0); 36 | vec4 worldTangent = vec4((Input.Tangent.xyz - vec3_splat(0.5)) * 2.0, 0.0); 37 | vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0); 38 | vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 39 | Output.PosVS = mul(u_mCameraProj, worldPos); 40 | Output.Color = Input.Color; 41 | vec2 uv1 = Input.UV1; 42 | uv1.y = u_mUVInversed.x + (u_mUVInversed.y * uv1.y); 43 | Output.UV = uv1; 44 | Output.ProjTangent = mul(u_mCameraProj, (worldPos + worldTangent)); 45 | Output.ProjBinormal = mul(u_mCameraProj, (worldPos + worldBinormal)); 46 | Output.PosP = Output.PosVS; 47 | return Output; 48 | } 49 | 50 | void main() 51 | { 52 | VS_Input Input; 53 | Input.Pos = a_position; 54 | Input.Color = a_color0; 55 | Input.Normal = a_normal; 56 | Input.Tangent = a_tangent; 57 | Input.UV1 = a_texcoord0; 58 | Input.UV2 = a_texcoord1; 59 | VS_Output flattenTemp = _main(Input); 60 | vec4 _position = flattenTemp.PosVS; 61 | gl_Position = _position; 62 | v_UV = flattenTemp.UV; 63 | v_ProjBinormal = flattenTemp.ProjBinormal; 64 | v_ProjTangent = flattenTemp.ProjTangent; 65 | v_PosP = flattenTemp.PosP; 66 | v_Color = flattenTemp.Color; 67 | } 68 | -------------------------------------------------------------------------------- /shaders/model_lit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_normal a_bitangent a_tangent a_texcoord0 a_color0 2 | $output v_Color v_UV v_WorldN v_WorldB v_WorldT v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCameraProj; 7 | uniform mat4 u_mModel_Inst[40]; 8 | uniform vec4 u_fUV[40]; 9 | uniform vec4 u_fModelColor[40]; 10 | uniform vec4 u_fLightDirection; 11 | uniform vec4 u_fLightColor; 12 | uniform vec4 u_fLightAmbient; 13 | uniform vec4 u_mUVInversed; 14 | 15 | 16 | struct VS_Input 17 | { 18 | vec3 Pos; 19 | vec3 Normal; 20 | vec3 Binormal; 21 | vec3 Tangent; 22 | vec2 UV; 23 | vec4 Color; 24 | uint Index; 25 | }; 26 | 27 | struct VS_Output 28 | { 29 | vec4 PosVS; 30 | vec4 Color; 31 | vec2 UV; 32 | vec3 WorldN; 33 | vec3 WorldB; 34 | vec3 WorldT; 35 | vec4 PosP; 36 | }; 37 | 38 | VS_Output _main(VS_Input Input) 39 | { 40 | uint index = Input.Index; 41 | mat4 mModel = u_mModel_Inst[index]; 42 | vec4 uv = u_fUV[index]; 43 | vec4 modelColor = u_fModelColor[index] * Input.Color; 44 | VS_Output Output = (VS_Output)0; 45 | vec4 localPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 46 | vec4 worldPos = mul(mModel, localPos); 47 | Output.PosVS = mul(u_mCameraProj, worldPos); 48 | Output.Color = modelColor; 49 | vec2 outputUV = Input.UV; 50 | outputUV.x = (outputUV.x * uv.z) + uv.x; 51 | outputUV.y = (outputUV.y * uv.w) + uv.y; 52 | outputUV.y = u_mUVInversed.x + (u_mUVInversed.y * outputUV.y); 53 | Output.UV = outputUV; 54 | vec4 localNormal = vec4(Input.Normal.x, Input.Normal.y, Input.Normal.z, 0.0); 55 | vec4 localBinormal = vec4(Input.Binormal.x, Input.Binormal.y, Input.Binormal.z, 0.0); 56 | vec4 localTangent = vec4(Input.Tangent.x, Input.Tangent.y, Input.Tangent.z, 0.0); 57 | vec4 worldNormal = mul(mModel, localNormal); 58 | vec4 worldBinormal = mul(mModel, localBinormal); 59 | vec4 worldTangent = mul(mModel, localTangent); 60 | worldNormal = normalize(worldNormal); 61 | worldBinormal = normalize(worldBinormal); 62 | worldTangent = normalize(worldTangent); 63 | Output.WorldN = worldNormal.xyz; 64 | Output.WorldB = worldBinormal.xyz; 65 | Output.WorldT = worldTangent.xyz; 66 | Output.PosP = Output.PosVS; 67 | return Output; 68 | } 69 | 70 | void main() 71 | { 72 | VS_Input Input; 73 | Input.Pos = a_position; 74 | Input.Normal = a_normal; 75 | Input.Binormal = a_bitangent; 76 | Input.Tangent = a_tangent; 77 | Input.UV = a_texcoord0; 78 | Input.Color = a_color0; 79 | Input.Index = uint(gl_InstanceIndex); 80 | VS_Output flattenTemp = _main(Input); 81 | vec4 _position = flattenTemp.PosVS; 82 | gl_Position = _position; 83 | v_Color = flattenTemp.Color; 84 | v_UV = flattenTemp.UV; 85 | v_WorldN = flattenTemp.WorldN; 86 | v_WorldB = flattenTemp.WorldB; 87 | v_WorldT = flattenTemp.WorldT; 88 | v_PosP = flattenTemp.PosP; 89 | } 90 | -------------------------------------------------------------------------------- /shaders/model_distortion_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_normal a_bitangent a_tangent a_texcoord0 a_color0 2 | $output v_UV v_ProjBinormal v_ProjTangent v_PosP v_Color 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCameraProj; 7 | uniform mat4 u_mModel_Inst[40]; 8 | uniform vec4 u_fUV[40]; 9 | uniform vec4 u_fModelColor[40]; 10 | uniform vec4 u_fLightDirection; 11 | uniform vec4 u_fLightColor; 12 | uniform vec4 u_fLightAmbient; 13 | uniform vec4 u_mUVInversed; 14 | 15 | 16 | struct VS_Input 17 | { 18 | vec3 Pos; 19 | vec3 Normal; 20 | vec3 Binormal; 21 | vec3 Tangent; 22 | vec2 UV; 23 | vec4 Color; 24 | uint Index; 25 | }; 26 | 27 | struct VS_Output 28 | { 29 | vec4 PosVS; 30 | vec2 UV; 31 | vec4 ProjBinormal; 32 | vec4 ProjTangent; 33 | vec4 PosP; 34 | vec4 Color; 35 | }; 36 | 37 | VS_Output _main(VS_Input Input) 38 | { 39 | uint index = Input.Index; 40 | mat4 mModel = u_mModel_Inst[index]; 41 | vec4 uv = u_fUV[index]; 42 | vec4 modelColor = u_fModelColor[index] * Input.Color; 43 | VS_Output Output = (VS_Output)0; 44 | vec4 localPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 45 | vec4 worldPos = mul(mModel, localPos); 46 | Output.PosVS = mul(u_mCameraProj, worldPos); 47 | Output.Color = modelColor; 48 | vec2 outputUV = Input.UV; 49 | outputUV.x = (outputUV.x * uv.z) + uv.x; 50 | outputUV.y = (outputUV.y * uv.w) + uv.y; 51 | outputUV.y = u_mUVInversed.x + (u_mUVInversed.y * outputUV.y); 52 | Output.UV = outputUV; 53 | vec4 localNormal = vec4(Input.Normal.x, Input.Normal.y, Input.Normal.z, 0.0); 54 | vec4 localBinormal = vec4(Input.Binormal.x, Input.Binormal.y, Input.Binormal.z, 0.0); 55 | vec4 localTangent = vec4(Input.Tangent.x, Input.Tangent.y, Input.Tangent.z, 0.0); 56 | vec4 worldNormal = mul(mModel, localNormal); 57 | vec4 worldBinormal = mul(mModel, localBinormal); 58 | vec4 worldTangent = mul(mModel, localTangent); 59 | worldNormal = normalize(worldNormal); 60 | worldBinormal = normalize(worldBinormal); 61 | worldTangent = normalize(worldTangent); 62 | Output.ProjBinormal = mul(u_mCameraProj, (worldPos + worldBinormal)); 63 | Output.ProjTangent = mul(u_mCameraProj, (worldPos + worldTangent)); 64 | Output.PosP = Output.PosVS; 65 | return Output; 66 | } 67 | 68 | void main() 69 | { 70 | VS_Input Input; 71 | Input.Pos = a_position; 72 | Input.Normal = a_normal; 73 | Input.Binormal = a_bitangent; 74 | Input.Tangent = a_tangent; 75 | Input.UV = a_texcoord0; 76 | Input.Color = a_color0; 77 | Input.Index = uint(gl_InstanceIndex); 78 | VS_Output flattenTemp = _main(Input); 79 | vec4 _position = flattenTemp.PosVS; 80 | gl_Position = _position; 81 | v_UV = flattenTemp.UV; 82 | v_ProjBinormal = flattenTemp.ProjBinormal; 83 | v_ProjTangent = flattenTemp.ProjTangent; 84 | v_PosP = flattenTemp.PosP; 85 | v_Color = flattenTemp.Color; 86 | } 87 | -------------------------------------------------------------------------------- /shaders/model_distortion_ps.fx.sc: -------------------------------------------------------------------------------- 1 | $input v_UV v_ProjBinormal v_ProjTangent v_PosP v_Color 2 | 3 | #include 4 | #include "defines.sh" 5 | uniform vec4 u_fsg_scale; 6 | uniform vec4 u_fsmUVInversedBack; 7 | uniform vec4 u_fsfFlipbookParameter; 8 | uniform vec4 u_fsfUVDistortionParameter; 9 | uniform vec4 u_fsfBlendTextureParameter; 10 | uniform vec4 u_fssoftParticleParam; 11 | uniform vec4 u_fsreconstructionParam1; 12 | uniform vec4 u_fsreconstructionParam2; 13 | SAMPLER2D (s_colorTex,0); 14 | SAMPLER2D (s_backTex,1); 15 | SAMPLER2D (s_depthTex,2); 16 | 17 | struct PS_Input 18 | { 19 | vec4 PosVS; 20 | vec2 UV; 21 | vec4 ProjBinormal; 22 | vec4 ProjTangent; 23 | vec4 PosP; 24 | vec4 Color; 25 | }; 26 | 27 | float SoftParticle(float backgroundZ, float meshZ, vec4 softparticleParam, vec4 reconstruct1, vec4 reconstruct2) 28 | { 29 | float distanceFar = softparticleParam.x; 30 | float distanceNear = softparticleParam.y; 31 | float distanceNearOffset = softparticleParam.z; 32 | vec2 rescale = reconstruct1.xy; 33 | vec4 params = reconstruct2; 34 | vec2 zs = vec2((backgroundZ * rescale.x) + rescale.y, meshZ); 35 | vec2 depth = ((zs * params.w) - vec2_splat(params.y)) / (vec2_splat(params.x) - (zs * params.z)); 36 | float dir = sign(depth.x); 37 | depth *= dir; 38 | float alphaFar = (depth.x - depth.y) / distanceFar; 39 | float alphaNear = (depth.y - distanceNearOffset) / distanceNear; 40 | return min(max(min(alphaFar, alphaNear), 0.0), 1.0); 41 | } 42 | 43 | vec4 _main(PS_Input Input) 44 | { 45 | vec4 Output = texture2D(s_colorTex, Input.UV); 46 | Output.w *= Input.Color.w; 47 | vec2 pos = Input.PosP.xy / vec2_splat(Input.PosP.w); 48 | vec2 posR = Input.ProjTangent.xy / vec2_splat(Input.ProjTangent.w); 49 | vec2 posU = Input.ProjBinormal.xy / vec2_splat(Input.ProjBinormal.w); 50 | float xscale = (((Output.x * 2.0) - 1.0) * Input.Color.x) * u_fsg_scale.x; 51 | float yscale = (((Output.y * 2.0) - 1.0) * Input.Color.y) * u_fsg_scale.x; 52 | vec2 uv = (pos + ((posR - pos) * xscale)) + ((posU - pos) * yscale); 53 | uv.x = (uv.x + 1.0) * 0.5; 54 | uv.y = 1.0 - ((uv.y + 1.0) * 0.5); 55 | uv.y = u_fsmUVInversedBack.x + (u_fsmUVInversedBack.y * uv.y); 56 | vec3 color = vec3(texture2D(s_backTex, uv).xyz); 57 | Output.x = color.x; 58 | Output.y = color.y; 59 | Output.z = color.z; 60 | vec4 screenPos = Input.PosP / vec4_splat(Input.PosP.w); 61 | vec2 screenUV = (screenPos.xy + vec2_splat(1.0)) / vec2_splat(2.0); 62 | screenUV.y = 1.0 - screenUV.y; 63 | if (u_fssoftParticleParam.w != 0.0) 64 | { 65 | float backgroundZ = texture2D(s_depthTex, screenUV).x; 66 | float param = backgroundZ; 67 | float param_1 = screenPos.z; 68 | vec4 param_2 = u_fssoftParticleParam; 69 | vec4 param_3 = u_fsreconstructionParam1; 70 | vec4 param_4 = u_fsreconstructionParam2; 71 | Output.w *= SoftParticle(param, param_1, param_2, param_3, param_4); 72 | } 73 | if (Output.w == 0.0) 74 | { 75 | discard; 76 | } 77 | return Output; 78 | } 79 | 80 | void main() 81 | { 82 | PS_Input Input; 83 | Input.PosVS = gl_FragCoord; 84 | Input.UV = v_UV; 85 | Input.ProjBinormal = v_ProjBinormal; 86 | Input.ProjTangent = v_ProjTangent; 87 | Input.PosP = v_PosP; 88 | #ifdef LINEAR_INPUT_COLOR 89 | Input.Color = to_linear(v_Color); 90 | #else 91 | Input.Color = v_Color; 92 | #endif //LINEAR_INPUT_COLOR 93 | 94 | vec4 _314 = _main(Input); 95 | gl_FragColor = _314; 96 | } 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A bgfx renderer for effekseer runtime 2 | ===== 3 | 4 | * bgfx : https://github.com/bkaradzic/bgfx 5 | * effekseer : https://github.com/effekseer/Effekseer 6 | 7 | Status 8 | ====== 9 | 10 | It's ready to use, and it keeps up with the latest versions of bgfx and effekseer. 11 | 12 | All the predefined materials works, but user defined materials are not supported now. It will be supported in future. 13 | 14 | The callback APIs may change in future , but it will always be simple enough. 15 | 16 | Contributors are welcome. 17 | 18 | Build 19 | ===== 20 | 21 | Use luamake : https://github.com/actboy168/luamake 22 | 23 | Or put source files (in renderer) into your project, and link effekseer library. 24 | 25 | How to use 26 | ========== 27 | 28 | You should initialize a structure `EffekseerRendererBGFX::InitArgs` to create a bgfx renderer. 29 | 30 | ``` 31 | EFXBGFX_API EffekseerRenderer::RendererRef CreateRenderer(struct InitArgs *init); 32 | EFXBGFX_API Effekseer::ModelRendererRef CreateModelRenderer(EffekseerRenderer::RendererRef renderer, struct InitArgs *init); 33 | ``` 34 | 35 | These APIs could create the renderer and model renderer for effekseer, See examples for the details. 36 | 37 | ```C 38 | struct InitArgs { 39 | int squareMaxCount; // Max count of sprites 40 | bgfx_view_id_t viewid; // The ViewID that effekseer will render to. 41 | bgfx_interface_vtbl_t *bgfx; // The bgfx APIs. Use `bgfx_get_interface()`. 42 | 43 | // Some callback functions, See below for details. 44 | bgfx_shader_handle_t (*shader_load)(const char *mat, const char *name, const char *type, void *ud); 45 | bgfx_texture_handle_t (*texture_get)(int texture_type, void *parm, void *ud); // background or depth (with param) 46 | int (*texture_load)(const char *name, int srgb, void *ud); 47 | void (*texture_unload)(int id, void *ud); 48 | bgfx_texture_handle_t (*texture_handle)(int id, void *ud); // translate id to handle 49 | void * ud; 50 | }; 51 | ``` 52 | 53 | ```C 54 | bgfx_shader_handle_t shader_load(const char *mat, const char *name, const char *type, void *ud); 55 | ``` 56 | 57 | When renderer need a shader, it will call this function. 58 | * `mat` is the material name, NULL for predefined material. 59 | * `name` is the shader name. 60 | * `type` is "vs" or "fs". 61 | * `ud` is arguments from `InitArgs`. 62 | 63 | The predefined shaders for bgfx is at `shaders` dir, compile them with bgfx toolset by yourself. 64 | 65 | This function should return a valid bgfx shader handle. 66 | 67 | ```C 68 | int texture_load(const char *name, int srgb, void *ud); 69 | ``` 70 | 71 | When renderer need a texture, it will call this function. 72 | * `name` is the texture name. 73 | * `srgb` true means it should be created as a SRGB texture. 74 | * `ud` is arguments from `InitArgs`. 75 | 76 | This function should return a texture id. (-1 as invalid) 77 | You don't need load texture immediately, and you can just alloc an id for it. 78 | 79 | ```C 80 | void texture_unload(int id, void *ud); 81 | 82 | ``` 83 | If the texture loaded by `texture_load` has not be no longer used by renderer, this function will be called. 84 | 85 | ```C 86 | bgfx_texture_handle_t texture_handle(int id, void *ud); 87 | ``` 88 | 89 | When renderer use a texture, it will call this function to translate id to bgfx texture handle. 90 | 91 | 92 | ```C 93 | bgfx_texture_handle_t texture_get(int texture_type, void *parm, void *ud); 94 | ``` 95 | When renderer need the `TEXTURE_BACKGROUND` (usually it's a render target) or the `TEXTURE_DEPTH`, it will call this function. 96 | When the `texture_type` is `TEXTURE_DEPTH`, you should offer an additional argument `DepthReconstructionParameter`. 97 | 98 | ```C 99 | struct DepthReconstructionParameter { 100 | float DepthBufferScale; 101 | float DepthBufferOffset; 102 | float ProjectionMatrix33; 103 | float ProjectionMatrix34; 104 | float ProjectionMatrix43; 105 | float ProjectionMatrix44; 106 | }; 107 | ``` 108 | 109 | This function should return a valid bgfx texture handle. 110 | 111 | This callback function can be NULL for optional. If you haven't offer this callback, some features of effekseer will be disabled. 112 | -------------------------------------------------------------------------------- /shaders/model_unlit_ps.fx.sc: -------------------------------------------------------------------------------- 1 | $input v_Color v_UV v_PosP 2 | 3 | #include 4 | #include "defines.sh" 5 | uniform vec4 u_fsfLightDirection; 6 | uniform vec4 u_fsfLightColor; 7 | uniform vec4 u_fsfLightAmbient; 8 | uniform vec4 u_fsfFlipbookParameter; 9 | uniform vec4 u_fsfUVDistortionParameter; 10 | uniform vec4 u_fsfBlendTextureParameter; 11 | uniform vec4 u_fsfCameraFrontDirection; 12 | uniform vec4 u_fsfFalloffParameter; 13 | uniform vec4 u_fsfFalloffBeginColor; 14 | uniform vec4 u_fsfFalloffEndColor; 15 | uniform vec4 u_fsfEmissiveScaling; 16 | uniform vec4 u_fsfEdgeColor; 17 | uniform vec4 u_fsfEdgeParameter; 18 | uniform vec4 u_fssoftParticleParam; 19 | uniform vec4 u_fsreconstructionParam1; 20 | uniform vec4 u_fsreconstructionParam2; 21 | uniform vec4 u_fsmUVInversedBack; 22 | uniform vec4 u_fsmiscFlags; 23 | SAMPLER2D (s_colorTex,0); 24 | SAMPLER2D (s_depthTex,1); 25 | 26 | struct PS_Input 27 | { 28 | vec4 PosVS; 29 | vec4 Color; 30 | vec2 UV; 31 | vec4 PosP; 32 | }; 33 | 34 | vec3 PositivePow(vec3 base, vec3 power) 35 | { 36 | return pow(max(abs(base), vec3_splat(1.1920928955078125e-07)), power); 37 | } 38 | 39 | vec3 LinearToSRGB(vec3 c) 40 | { 41 | vec3 param = c; 42 | vec3 param_1 = vec3_splat(0.4166666567325592041015625); 43 | return max((PositivePow(param, param_1) * 1.05499994754791259765625) - vec3_splat(0.054999999701976776123046875), vec3_splat(0.0)); 44 | } 45 | 46 | vec4 LinearToSRGB(vec4 c) 47 | { 48 | vec3 param = c.xyz; 49 | return vec4(LinearToSRGB(param), c.w); 50 | } 51 | 52 | vec4 ConvertFromSRGBTexture(vec4 c, bool isValid) 53 | { 54 | if (!isValid) 55 | { 56 | return c; 57 | } 58 | vec4 param = c; 59 | return LinearToSRGB(param); 60 | } 61 | 62 | float SoftParticle(float backgroundZ, float meshZ, vec4 softparticleParam, vec4 reconstruct1, vec4 reconstruct2) 63 | { 64 | float distanceFar = softparticleParam.x; 65 | float distanceNear = softparticleParam.y; 66 | float distanceNearOffset = softparticleParam.z; 67 | vec2 rescale = reconstruct1.xy; 68 | vec4 params = reconstruct2; 69 | vec2 zs = vec2((backgroundZ * rescale.x) + rescale.y, meshZ); 70 | vec2 depth = ((zs * params.w) - vec2_splat(params.y)) / (vec2_splat(params.x) - (zs * params.z)); 71 | float dir = sign(depth.x); 72 | depth *= dir; 73 | float alphaFar = (depth.x - depth.y) / distanceFar; 74 | float alphaNear = (depth.y - distanceNearOffset) / distanceNear; 75 | return min(max(min(alphaFar, alphaNear), 0.0), 1.0); 76 | } 77 | 78 | vec3 SRGBToLinear(vec3 c) 79 | { 80 | return min(c, c * ((c * ((c * 0.305306017398834228515625) + vec3_splat(0.6821711063385009765625))) + vec3_splat(0.01252287812530994415283203125))); 81 | } 82 | 83 | vec4 SRGBToLinear(vec4 c) 84 | { 85 | vec3 param = c.xyz; 86 | return vec4(SRGBToLinear(param), c.w); 87 | } 88 | 89 | vec4 ConvertToScreen(vec4 c, bool isValid) 90 | { 91 | if (!isValid) 92 | { 93 | return c; 94 | } 95 | vec4 param = c; 96 | return SRGBToLinear(param); 97 | } 98 | 99 | vec4 _main(PS_Input Input) 100 | { 101 | bool convertColorSpace = u_fsmiscFlags.x != 0.0; 102 | vec4 param = texture2D(s_colorTex, Input.UV); 103 | bool param_1 = convertColorSpace; 104 | vec4 Output = ConvertFromSRGBTexture(param, param_1) * Input.Color; 105 | vec4 _256 = Output; 106 | vec3 _258 = _256.xyz * u_fsfEmissiveScaling.x; 107 | Output.x = _258.x; 108 | Output.y = _258.y; 109 | Output.z = _258.z; 110 | vec4 screenPos = Input.PosP / vec4_splat(Input.PosP.w); 111 | vec2 screenUV = (screenPos.xy + vec2_splat(1.0)) / vec2_splat(2.0); 112 | screenUV.y = 1.0 - screenUV.y; 113 | screenUV.y = u_fsmUVInversedBack.x + (u_fsmUVInversedBack.y * screenUV.y); 114 | if (u_fssoftParticleParam.w != 0.0) 115 | { 116 | float backgroundZ = texture2D(s_depthTex, screenUV).x; 117 | float param_2 = backgroundZ; 118 | float param_3 = screenPos.z; 119 | vec4 param_4 = u_fssoftParticleParam; 120 | vec4 param_5 = u_fsreconstructionParam1; 121 | vec4 param_6 = u_fsreconstructionParam2; 122 | Output.w *= SoftParticle(param_2, param_3, param_4, param_5, param_6); 123 | } 124 | if (Output.w == 0.0) 125 | { 126 | discard; 127 | } 128 | vec4 param_7 = Output; 129 | bool param_8 = convertColorSpace; 130 | return ConvertToScreen(param_7, param_8); 131 | } 132 | 133 | void main() 134 | { 135 | PS_Input Input; 136 | Input.PosVS = gl_FragCoord; 137 | #ifdef LINEAR_INPUT_COLOR 138 | Input.Color = to_linear(v_Color); 139 | #else 140 | Input.Color = v_Color; 141 | #endif //LINEAR_INPUT_COLOR 142 | 143 | Input.UV = v_UV; 144 | Input.PosP = v_PosP; 145 | vec4 _363 = _main(Input); 146 | gl_FragColor = _363; 147 | } 148 | -------------------------------------------------------------------------------- /shaders/model_lit_ps.fx.sc: -------------------------------------------------------------------------------- 1 | $input v_Color v_UV v_WorldN v_WorldB v_WorldT v_PosP 2 | 3 | #include 4 | #include "defines.sh" 5 | uniform vec4 u_fsfLightDirection; 6 | uniform vec4 u_fsfLightColor; 7 | uniform vec4 u_fsfLightAmbient; 8 | uniform vec4 u_fsfFlipbookParameter; 9 | uniform vec4 u_fsfUVDistortionParameter; 10 | uniform vec4 u_fsfBlendTextureParameter; 11 | uniform vec4 u_fsfCameraFrontDirection; 12 | uniform vec4 u_fsfFalloffParameter; 13 | uniform vec4 u_fsfFalloffBeginColor; 14 | uniform vec4 u_fsfFalloffEndColor; 15 | uniform vec4 u_fsfEmissiveScaling; 16 | uniform vec4 u_fsfEdgeColor; 17 | uniform vec4 u_fsfEdgeParameter; 18 | uniform vec4 u_fssoftParticleParam; 19 | uniform vec4 u_fsreconstructionParam1; 20 | uniform vec4 u_fsreconstructionParam2; 21 | uniform vec4 u_fsmUVInversedBack; 22 | uniform vec4 u_fsmiscFlags; 23 | SAMPLER2D (s_colorTex,0); 24 | SAMPLER2D (s_normalTex,1); 25 | SAMPLER2D (s_depthTex,2); 26 | 27 | struct PS_Input 28 | { 29 | vec4 PosVS; 30 | vec4 Color; 31 | vec2 UV; 32 | vec3 WorldN; 33 | vec3 WorldB; 34 | vec3 WorldT; 35 | vec4 PosP; 36 | }; 37 | 38 | vec3 PositivePow(vec3 base, vec3 power) 39 | { 40 | return pow(max(abs(base), vec3_splat(1.1920928955078125e-07)), power); 41 | } 42 | 43 | vec3 LinearToSRGB(vec3 c) 44 | { 45 | vec3 param = c; 46 | vec3 param_1 = vec3_splat(0.4166666567325592041015625); 47 | return max((PositivePow(param, param_1) * 1.05499994754791259765625) - vec3_splat(0.054999999701976776123046875), vec3_splat(0.0)); 48 | } 49 | 50 | vec4 LinearToSRGB(vec4 c) 51 | { 52 | vec3 param = c.xyz; 53 | return vec4(LinearToSRGB(param), c.w); 54 | } 55 | 56 | vec4 ConvertFromSRGBTexture(vec4 c, bool isValid) 57 | { 58 | if (!isValid) 59 | { 60 | return c; 61 | } 62 | vec4 param = c; 63 | return LinearToSRGB(param); 64 | } 65 | 66 | float SoftParticle(float backgroundZ, float meshZ, vec4 softparticleParam, vec4 reconstruct1, vec4 reconstruct2) 67 | { 68 | float distanceFar = softparticleParam.x; 69 | float distanceNear = softparticleParam.y; 70 | float distanceNearOffset = softparticleParam.z; 71 | vec2 rescale = reconstruct1.xy; 72 | vec4 params = reconstruct2; 73 | vec2 zs = vec2((backgroundZ * rescale.x) + rescale.y, meshZ); 74 | vec2 depth = ((zs * params.w) - vec2_splat(params.y)) / (vec2_splat(params.x) - (zs * params.z)); 75 | float dir = sign(depth.x); 76 | depth *= dir; 77 | float alphaFar = (depth.x - depth.y) / distanceFar; 78 | float alphaNear = (depth.y - distanceNearOffset) / distanceNear; 79 | return min(max(min(alphaFar, alphaNear), 0.0), 1.0); 80 | } 81 | 82 | vec3 SRGBToLinear(vec3 c) 83 | { 84 | return min(c, c * ((c * ((c * 0.305306017398834228515625) + vec3_splat(0.6821711063385009765625))) + vec3_splat(0.01252287812530994415283203125))); 85 | } 86 | 87 | vec4 SRGBToLinear(vec4 c) 88 | { 89 | vec3 param = c.xyz; 90 | return vec4(SRGBToLinear(param), c.w); 91 | } 92 | 93 | vec4 ConvertToScreen(vec4 c, bool isValid) 94 | { 95 | if (!isValid) 96 | { 97 | return c; 98 | } 99 | vec4 param = c; 100 | return SRGBToLinear(param); 101 | } 102 | 103 | vec4 _main(PS_Input Input) 104 | { 105 | bool convertColorSpace = u_fsmiscFlags.x != 0.0; 106 | vec4 param = texture2D(s_colorTex, Input.UV); 107 | bool param_1 = convertColorSpace; 108 | vec4 Output = ConvertFromSRGBTexture(param, param_1) * Input.Color; 109 | vec3 texNormal = (texture2D(s_normalTex, Input.UV).xyz - vec3_splat(0.5)) * 2.0; 110 | vec3 localNormal = normalize(mul(mtxFromCols(Input.WorldT, Input.WorldB, Input.WorldN), texNormal)); 111 | float diffuse = max(dot(u_fsfLightDirection.xyz, localNormal), 0.0); 112 | vec4 _300 = Output; 113 | vec3 _311 = _300.xyz * ((u_fsfLightColor.xyz * diffuse) + u_fsfLightAmbient.xyz); 114 | Output.x = _311.x; 115 | Output.y = _311.y; 116 | Output.z = _311.z; 117 | vec4 _321 = Output; 118 | vec3 _323 = _321.xyz * u_fsfEmissiveScaling.x; 119 | Output.x = _323.x; 120 | Output.y = _323.y; 121 | Output.z = _323.z; 122 | vec4 screenPos = Input.PosP / vec4_splat(Input.PosP.w); 123 | vec2 screenUV = (screenPos.xy + vec2_splat(1.0)) / vec2_splat(2.0); 124 | screenUV.y = 1.0 - screenUV.y; 125 | screenUV.y = u_fsmUVInversedBack.x + (u_fsmUVInversedBack.y * screenUV.y); 126 | if (u_fssoftParticleParam.w != 0.0) 127 | { 128 | float backgroundZ = texture2D(s_depthTex, screenUV).x; 129 | float param_2 = backgroundZ; 130 | float param_3 = screenPos.z; 131 | vec4 param_4 = u_fssoftParticleParam; 132 | vec4 param_5 = u_fsreconstructionParam1; 133 | vec4 param_6 = u_fsreconstructionParam2; 134 | Output.w *= SoftParticle(param_2, param_3, param_4, param_5, param_6); 135 | } 136 | if (Output.w == 0.0) 137 | { 138 | discard; 139 | } 140 | vec4 param_7 = Output; 141 | bool param_8 = convertColorSpace; 142 | return ConvertToScreen(param_7, param_8); 143 | } 144 | 145 | void main() 146 | { 147 | PS_Input Input; 148 | Input.PosVS = gl_FragCoord; 149 | #ifdef LINEAR_INPUT_COLOR 150 | Input.Color = to_linear(v_Color); 151 | #else 152 | Input.Color = v_Color; 153 | #endif //LINEAR_INPUT_COLOR 154 | 155 | Input.UV = v_UV; 156 | Input.WorldN = v_WorldN; 157 | Input.WorldB = v_WorldB; 158 | Input.WorldT = v_WorldT; 159 | Input.PosP = v_PosP; 160 | vec4 _435 = _main(Input); 161 | gl_FragColor = _435; 162 | } 163 | -------------------------------------------------------------------------------- /examples/make.lua: -------------------------------------------------------------------------------- 1 | local lm = require "luamake" 2 | local fs = require "bee.filesystem" 3 | 4 | package.path = "./?.lua;../?.lua" 5 | 6 | -- make bgfx module compile command: ..\bx\tools\bin\windows\genie.exe --with-dynamic-runtime --with-examples --with-windows=10.0 --with-shared-lib vs2022 7 | lm.mode = "debug" 8 | require "buildscripts.common" 9 | 10 | lm.builddir = ("build/%s/%s"):format(Plat, lm.mode) 11 | lm.bindir = ("bin/%s/%s"):format(Plat, lm.mode) 12 | 13 | local Help = [[ 14 | usage: 15 | EfkDir Effekseer project dir. EX: ../../Effekseer, EfkDir = ../../, default: ../ 16 | Bgfx/Bx/Bimg dirs will try to find from EfkDir 17 | BgfxDir bgfx project dir. EX: BgfxDir = ../../bgfx, default: $EfkDir/bgfx 18 | BxDir bx project dir. EX: BxDir = ../../bx, default: $EfkDir/bx 19 | BimgDir bimg project dir. EX: BimgDir = ../../bimg, default: $EfkDir/bimg 20 | BgfxBinDir bgfx compile binary dir.EX: BgfxBinDir = ../../bgfx/.build/win64_vs2022/bin default: $BgfxDir/.build/win64_vs2022/bin 21 | 22 | example: 23 | cd $efkbgfx/examples 24 | luamake -EfkDir ../.. 25 | ]] 26 | 27 | local function check_dir_exists() 28 | local function check_dir(n, dir) 29 | if not fs.exists(dir) then 30 | print(n, dir, " is not exist") 31 | end 32 | end 33 | 34 | check_dir("EfkDir: ", EfkDir) 35 | check_dir("BgfxDir: ", BgfxDir) 36 | check_dir("BgfxBinDir:", BgfxBinDir) 37 | check_dir("Shaderc:", Shaderc) 38 | end 39 | 40 | 41 | if not fs.exists(Shaderc) then 42 | check_dir_exists() 43 | print(Help) 44 | 45 | error(("shaderc:%s is not exist!"):format(Shaderc)) 46 | end 47 | 48 | local bx_libname = "bx" .. BgfxNameSuffix 49 | local bgfx_libname = "bgfx" .. BgfxNameSuffix 50 | local bimg_libname = "bimg" .. BgfxNameSuffix 51 | local bimgDecode_libname = "bimg_decode" .. BgfxNameSuffix 52 | local bgfx_example_dir = BgfxDir / "examples" 53 | local alloca_file_includes = { 54 | msvc = BxDir / "include/compat/msvc", 55 | mingw = BxDir / "include/compat/mingw", 56 | } 57 | 58 | local bgfxdll_name = lm.BgfxSharedDll or ("bgfx-shared-lib" .. BgfxNameSuffix .. ".dll") 59 | lm:copy "copy_bgfx" { 60 | input = (BgfxBinDir / bgfxdll_name):string(), 61 | output = lm.bindir .. "/" .. bgfxdll_name, 62 | } 63 | 64 | lm:import "../renderer/make.lua" 65 | lm:import "../shaders/make.lua" 66 | 67 | ---------------------------------------------------------------- 68 | local cwd = fs.path(lm.workdir) 69 | local sc = require "buildscripts.shader_compile" 70 | local cube_shader_dir = fs.path "cube/shaders" 71 | 72 | local function tosc(name) 73 | return { 74 | input = cwd / cube_shader_dir / name, 75 | stage = name:match "([vf]s)", 76 | } 77 | end 78 | 79 | local scfiles = { 80 | tosc "vs_fullscreen.sc", 81 | tosc "fs_fullscreen.sc", 82 | tosc "vs_cube.sc", 83 | tosc "fs_cube.sc", 84 | } 85 | 86 | local shader_folder = cwd / "../shaders" 87 | for fn in fs.pairs(shader_folder) do 88 | if not fn:string():match "varying.def.sc" then 89 | local ext = fn:extension():string():lower() 90 | if ext == ".sc" then 91 | local si = ShaderInfoFromFilename(fn:filename():string()) 92 | scfiles[#scfiles+1] = { 93 | input = shader_folder / si.filename, 94 | stage = si.stage, 95 | varying_path = shader_folder / ("%s_%s_varying.def.sc"):format(si.modeltype, si.shadertype), 96 | } 97 | end 98 | end 99 | end 100 | 101 | local shaderbin_files = {} 102 | for _, f in ipairs(scfiles) do 103 | local input = f.input 104 | local output = fs.path(input):replace_extension "bin" 105 | local cfg = { 106 | stage = f.stage, 107 | optimizelevel = 3, 108 | debug = true, 109 | varying_path = f.varying_path, 110 | includes = { 111 | cwd / BgfxDir / "src", 112 | cwd / bgfx_example_dir / "common", 113 | }, 114 | defines = { 115 | --NOTICE: only sRGB texture and framebuffer mode should add this macro 116 | --LINEAR_INPUT_COLOR=1, 117 | }, 118 | input = input:string(), 119 | output = output:string(), 120 | } 121 | shaderbin_files[#shaderbin_files+1] = output:string() 122 | local cmd = sc.gen_cmd(Shaderc:string(), cfg) 123 | cmd.description = "Compile shader bin: $out" 124 | lm:build(cmd) 125 | end 126 | 127 | lm:phony "shader_binaries" { 128 | deps = "efxbgfx_shaders", 129 | input = shaderbin_files, 130 | } 131 | 132 | --------------------------example 133 | lm:exe "example"{ 134 | deps = { 135 | "efklib", 136 | "efkbgfx", 137 | "efkmat", 138 | "shader_binaries", 139 | "copy_bgfx", 140 | }, 141 | includes = { 142 | alloca_file_includes[Plat]:string(), 143 | EfkLib_Includes, 144 | (bgfx_example_dir / "common"):string(), 145 | (BimgDir / "include"):string(), 146 | "../", 147 | }, 148 | sources = { 149 | "example.cpp", 150 | }, 151 | defines = { 152 | "BX_CONFIG_DEBUG=" .. (lm.mode == "debug" and 1 or 0), 153 | "ENTRY_CONFIG_IMPLEMENT_MAIN=1", 154 | }, 155 | links = { 156 | "example-common" .. BgfxNameSuffix, 157 | bx_libname, 158 | bimg_libname, 159 | bgfx_libname, 160 | bimgDecode_libname, 161 | "DelayImp", 162 | "gdi32", 163 | "psapi", 164 | "kernel32", 165 | "user32", 166 | "winspool", 167 | "comdlg32", 168 | "advapi32", 169 | "shell32", 170 | "ole32", 171 | "oleaut32", 172 | "uuid", 173 | "odbc32", 174 | "odbccp32" 175 | }, 176 | linkdirs = { 177 | BgfxBinDir:string(), 178 | } 179 | } -------------------------------------------------------------------------------- /luabinding/efkcallback.c: -------------------------------------------------------------------------------- 1 | #define LUA_LIB 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | typedef void (*voidf)(void); 9 | 10 | struct handle_t { 11 | uint16_t idx; 12 | }; 13 | 14 | static struct handle_t invalid_handle = { 0xffff }; 15 | 16 | #define CALLBACK_SHADER_LOAD 1 17 | #define CALLBACK_TEXTURE_LOAD 2 18 | #define CALLBACK_TEXTURE_UNLOAD 3 19 | #define TABLE_TEXTURE_MAP 4 20 | #define CALLBACK_ERROR_HANDLER 5 21 | #define CALLBACK_TOP 5 22 | 23 | #define TEXTURE_BACKGROUND 0 24 | #define TEXTURE_DEPTH 1 25 | #define TEXTURE_MAX 1024 26 | 27 | struct callback_ud { 28 | lua_State *L; 29 | int (*texture_transform)(int id); 30 | int error_handler; 31 | int texture_n; 32 | struct handle_t background; 33 | struct handle_t depth; 34 | struct handle_t default_texture; 35 | float depth_param[6]; 36 | int texture_id[TEXTURE_MAX]; 37 | }; 38 | 39 | static void 40 | set_callback(lua_State *L, struct callback_ud *ud, const char *name, int id) { 41 | if (lua_getfield(L, 1, name) != LUA_TFUNCTION) { 42 | luaL_error(L, "%s is not a function"); 43 | } 44 | lua_xmove(L, ud->L, 1); 45 | lua_replace(ud->L, id); 46 | } 47 | 48 | static void 49 | set_depth(lua_State *L, struct callback_ud *ud) { 50 | if (lua_getfield(L, 3, "handle") != LUA_TNUMBER) { 51 | luaL_error(L, "Missing depth.handle"); 52 | } 53 | if (!lua_isinteger(L, -1)) { 54 | luaL_error(L, "Invalid depth.handle"); 55 | } 56 | ud->depth.idx = lua_tointeger(L, -1) & 0xffff; 57 | lua_pop(L, 1); 58 | int i; 59 | for (i=0;i<6;i++) { 60 | if (lua_geti(L, 3, i+1) != LUA_TNUMBER) { 61 | luaL_error(L, "Missing depth params at %d", i+1); 62 | } 63 | ud->depth_param[i] = lua_tonumber(L, -1); 64 | lua_pop(L, 1); 65 | } 66 | } 67 | 68 | static int 69 | lset_texture(lua_State *L) { 70 | struct callback_ud *ud = (struct callback_ud *)lua_touserdata(L, 1); 71 | const char *name = luaL_checkstring(L, 2); 72 | if (strcmp(name, "background")==0) { 73 | uint16_t handle = luaL_checkinteger(L, 3) & 0xffff; 74 | ud->background.idx = handle; 75 | } else if (strcmp(name, "depth")==0) { 76 | luaL_checktype(L, 3, LUA_TTABLE); 77 | set_depth(L, ud); 78 | } else if (strcmp(name, "default")==0) { 79 | uint16_t handle = luaL_checkinteger(L, 3) & 0xffff; 80 | ud->default_texture.idx = handle; 81 | } else { 82 | return luaL_error(L, "Invalid attrib %s", name); 83 | } 84 | return 0; 85 | } 86 | 87 | static int 88 | lcallback(lua_State *L) { 89 | luaL_checktype(L, 1, LUA_TTABLE); 90 | struct callback_ud *ud = (struct callback_ud *)lua_newuserdatauv(L, sizeof(*ud), 1); 91 | ud->L = lua_newthread(L); 92 | ud->texture_transform = NULL; 93 | ud->texture_n = 0; 94 | if (lua_getfield(L, 1, "texture_transform") == LUA_TLIGHTUSERDATA) { 95 | ud->texture_transform = lua_touserdata(L, -1); 96 | } 97 | lua_pop(L, 1); 98 | ud->error_handler = 0; 99 | 100 | ud->background = invalid_handle; 101 | ud->depth = invalid_handle; 102 | ud->default_texture = invalid_handle; 103 | 104 | lua_setiuservalue(L, -2, 1); 105 | lua_settop(ud->L, CALLBACK_TOP); 106 | set_callback(L, ud, "shader_load", CALLBACK_SHADER_LOAD); 107 | set_callback(L, ud, "texture_load", CALLBACK_TEXTURE_LOAD); 108 | set_callback(L, ud, "texture_unload", CALLBACK_TEXTURE_UNLOAD); 109 | set_callback(L, ud, "texture_map", TABLE_TEXTURE_MAP); 110 | if (lua_getfield(L, 1, "error") == LUA_TFUNCTION) { 111 | lua_xmove(L, ud->L, 1); 112 | lua_replace(ud->L, CALLBACK_ERROR_HANDLER); 113 | ud->error_handler = CALLBACK_ERROR_HANDLER; 114 | } 115 | 116 | lua_newtable(L); 117 | lua_pushcfunction(L, lset_texture); 118 | lua_setfield(L, -2, "__newindex"); 119 | lua_setmetatable(L, -2); 120 | 121 | return 1; 122 | } 123 | 124 | static int 125 | ret_handle(struct callback_ud *ud, int args) { 126 | if (lua_pcall(ud->L, args, 1, ud->error_handler) != LUA_OK || !lua_isinteger(ud->L, -1)) { 127 | lua_pop(ud->L, 1); 128 | return 0xffff; 129 | } 130 | int ret = lua_tointeger(ud->L, -1); 131 | lua_pop(ud->L, 1); 132 | return ret; 133 | } 134 | 135 | static struct handle_t 136 | shader_load(const char *mat, const char *name, const char *type, struct callback_ud *ud) { 137 | lua_State *L = ud->L; 138 | lua_pushvalue(L, CALLBACK_SHADER_LOAD); 139 | if (mat == NULL) { 140 | lua_pushnil(L); 141 | } else { 142 | lua_pushstring(L, mat); 143 | } 144 | lua_pushstring(L, name); 145 | lua_pushstring(L, type); 146 | struct handle_t ret = { ret_handle(ud, 3) & 0xffff }; 147 | return ret; 148 | } 149 | 150 | static struct handle_t 151 | texture_load(const char *name, int srgb, struct callback_ud *ud) { 152 | int id = ud->texture_n++; 153 | if (id >= TEXTURE_MAX) { 154 | return invalid_handle; 155 | } 156 | lua_State *L = ud->L; 157 | lua_pushvalue(L, CALLBACK_TEXTURE_LOAD); 158 | lua_pushstring(L, name); 159 | lua_pushboolean(L, srgb); 160 | lua_pushinteger(L, id); 161 | ud->texture_id[id] = ret_handle(ud, 3); 162 | struct handle_t ret = { id }; 163 | return ret; 164 | } 165 | 166 | static void 167 | texture_unload(struct handle_t handle, struct callback_ud *ud) { 168 | lua_State *L = ud->L; 169 | lua_pushvalue(L, CALLBACK_TEXTURE_UNLOAD); 170 | lua_pushinteger(L, handle.idx); 171 | if (lua_pcall(L, 1, 0, ud->error_handler) != LUA_OK) { 172 | lua_pop(L, 1); 173 | } 174 | } 175 | 176 | static struct handle_t 177 | texture_get(int texture_type, void *param, struct callback_ud *ud) { 178 | switch (texture_type) { 179 | case TEXTURE_BACKGROUND: 180 | return ud->background; 181 | case TEXTURE_DEPTH: 182 | memcpy(param, ud->depth_param, sizeof(ud->depth_param)); 183 | return ud->depth; 184 | } 185 | return invalid_handle; 186 | } 187 | 188 | static struct handle_t 189 | texture_handle(int id, struct callback_ud *ud) { 190 | if (id < 0 || id >= ud->texture_n) 191 | return invalid_handle; 192 | int handle = ud->texture_id[id]; 193 | if (handle == 0xffff) { 194 | lua_State *L = ud->L; 195 | lua_pushvalue(L, TABLE_TEXTURE_MAP); 196 | lua_pushinteger(L, id); 197 | handle = ret_handle(ud, 1); 198 | ud->texture_id[id] = handle; 199 | if (handle == 0xffff) { 200 | return ud->default_texture; 201 | } 202 | } 203 | if (ud->texture_transform) { 204 | handle = ud->texture_transform(handle); 205 | } 206 | struct handle_t ret = { handle & 0xffff }; 207 | return ret; 208 | } 209 | 210 | static void 211 | set_capi(lua_State *L, const char *name, voidf f) { 212 | lua_pushlightuserdata(L, (void *)f); 213 | lua_setfield(L, -2, name); 214 | } 215 | 216 | LUAMOD_API int 217 | luaopen_effekseer_callback(lua_State *L) { 218 | luaL_checkversion(L); 219 | luaL_Reg l[] = { 220 | { "callback", lcallback }, 221 | { "shader_load", NULL }, 222 | { "texture_load", NULL }, 223 | { "texture_get", NULL }, 224 | { "texture_unload", NULL }, 225 | { NULL, NULL }, 226 | }; 227 | luaL_newlib(L, l); 228 | set_capi(L, "shader_load", (voidf)shader_load); 229 | set_capi(L, "texture_load", (voidf)texture_load); 230 | set_capi(L, "texture_get", (voidf)texture_get); 231 | set_capi(L, "texture_unload", (voidf)texture_unload); 232 | set_capi(L, "texture_handle", (voidf)texture_handle); 233 | return 1; 234 | } -------------------------------------------------------------------------------- /efkmatc/efkmat.cpp: -------------------------------------------------------------------------------- 1 | #define LUA_LIB 2 | 3 | extern "C" { 4 | #include 5 | #include 6 | } 7 | 8 | #include 9 | //#include 10 | #include 11 | 12 | static int 13 | lloadMat(lua_State *L) { 14 | size_t sz; 15 | const char *data = luaL_checklstring(L, 1, &sz); 16 | 17 | Effekseer::MaterialFile mat; 18 | if (!mat.Load((const uint8_t *)data, (int32_t)sz)) 19 | return luaL_error(L, "Invalid effekseer matrtial"); 20 | 21 | lua_newtable(L); 22 | switch (mat.GetShadingModel()) { 23 | case Effekseer::ShadingModelType::Lit : 24 | lua_pushstring(L, "Lit"); 25 | break; 26 | case Effekseer::ShadingModelType::Unlit : 27 | lua_pushstring(L, "Unlit"); 28 | break; 29 | default: 30 | lua_pushstring(L, "Unknown"); 31 | break; 32 | } 33 | lua_setfield(L, -2, "ShadingModel"); 34 | lua_pushboolean(L, mat.GetIsSimpleVertex()); 35 | lua_setfield(L, -2, "IsSimpleVertex"); 36 | lua_pushboolean(L, mat.GetHasRefraction()); 37 | lua_setfield(L, -2, "HasRefraction"); 38 | lua_pushstring(L, mat.GetGenericCode()); 39 | lua_setfield(L, -2, "Code"); 40 | lua_pushinteger(L, mat.GetGUID()); 41 | lua_setfield(L, -2, "GUID"); 42 | lua_pushinteger(L, mat.GetCustomData1Count()); 43 | lua_setfield(L, -2, "CustomData1Count"); 44 | lua_pushinteger(L, mat.GetCustomData2Count()); 45 | lua_setfield(L, -2, "CustomData2Count"); 46 | 47 | int i; 48 | int texture_n = mat.GetTextureCount(); 49 | lua_createtable(L, texture_n, 0); 50 | for (i=0;i; 103 | 104 | class VertexLayout : public Effekseer::Backend::VertexLayout { 105 | private: 106 | Effekseer::CustomVector elements_; 107 | public: 108 | VertexLayout(const Effekseer::Backend::VertexLayoutElement* elements, int32_t elementCount) { 109 | elements_.resize(elementCount); 110 | for (int32_t i = 0; i < elementCount; i++) { 111 | elements_[i] = elements[i]; 112 | } 113 | } 114 | ~VertexLayout() = default; 115 | const Effekseer::CustomVector& GetElements() const { 116 | return elements_; 117 | } 118 | }; 119 | 120 | class GraphicsDevice : public Effekseer::Backend::GraphicsDevice { 121 | public: 122 | GraphicsDevice() = default; 123 | ~GraphicsDevice() override = default; 124 | 125 | Effekseer::Backend::VertexLayoutRef CreateVertexLayout(const Effekseer::Backend::VertexLayoutElement* elements, int32_t elementCount) override { 126 | return Effekseer::MakeRefPtr(elements, elementCount); 127 | } 128 | }; 129 | 130 | static inline void 131 | push_layout(lua_State *L, Effekseer::Backend::VertexLayoutFormat format, const char* name, const char* semanticName, int32_t semanticIndex){ 132 | lua_newtable(L); 133 | switch (format) { 134 | case Effekseer::Backend::VertexLayoutFormat::R32_FLOAT : 135 | lua_pushstring(L, "R32_FLOAT"); 136 | break; 137 | case Effekseer::Backend::VertexLayoutFormat::R32G32_FLOAT : 138 | lua_pushstring(L, "R32G32_FLOAT"); 139 | break; 140 | case Effekseer::Backend::VertexLayoutFormat::R32G32B32_FLOAT : 141 | lua_pushstring(L, "R32G32B32_FLOAT"); 142 | break; 143 | case Effekseer::Backend::VertexLayoutFormat::R32G32B32A32_FLOAT : 144 | lua_pushstring(L, "R32G32B32A32_FLOAT"); 145 | break; 146 | case Effekseer::Backend::VertexLayoutFormat::R8G8B8A8_UNORM : 147 | lua_pushstring(L, "R8G8B8A8_UNORM"); 148 | break; 149 | case Effekseer::Backend::VertexLayoutFormat::R8G8B8A8_UINT : 150 | lua_pushstring(L, "R8G8B8A8_UINT"); 151 | break; 152 | default: 153 | luaL_error(L, "Invalid Format"); 154 | } 155 | lua_setfield(L, -2, "Format"); 156 | lua_pushstring(L, name); 157 | lua_setfield(L, -2, "Name"); 158 | lua_pushstring(L, semanticName); 159 | lua_setfield(L, -2, "SemanticName"); 160 | lua_pushinteger(L, semanticIndex); 161 | lua_setfield(L, -2, "SemanticIndex"); 162 | } 163 | 164 | 165 | static int 166 | push_layouts(lua_State *L, const Effekseer::CustomVector& elements){ 167 | size_t n = elements.size(); 168 | lua_createtable(L, (int)n, 0); 169 | for (size_t i = 0; i < n; i++) { 170 | const auto&e = elements[i]; 171 | push_layout(L, e.Format, e.Name.c_str(), e.SemanticName.c_str(), e.SemanticIndex); 172 | lua_rawseti(L, -2, i+1); 173 | } 174 | return 1; 175 | } 176 | 177 | static int 178 | llayout(lua_State *L) { 179 | lua_Integer t = luaL_checkinteger(L, 1); 180 | if (t < (lua_Integer) EffekseerRenderer::RendererShaderType::Unlit || t > (lua_Integer)EffekseerRenderer::RendererShaderType::AdvancedBackDistortion) { 181 | luaL_error(L, "Invalid shader type"); 182 | } 183 | VertexLayoutRef v = EffekseerRenderer::GetVertexLayout(Effekseer::MakeRefPtr(), (EffekseerRenderer::RendererShaderType)t).DownCast(); 184 | const auto &elements = v->GetElements(); 185 | return push_layouts(L, elements); 186 | } 187 | 188 | extern "C" { 189 | 190 | LUAMOD_API int 191 | luaopen_efkmat(lua_State *L) { 192 | luaL_checkversion(L); 193 | luaL_Reg l[] = { 194 | { "load", lloadMat }, 195 | { "layout", llayout }, 196 | { NULL, NULL }, 197 | }; 198 | luaL_newlib(L, l); 199 | 200 | // model layout 201 | lua_createtable(L, 6, 0); 202 | push_layout(L, Effekseer::Backend::VertexLayoutFormat::R32G32B32_FLOAT, "Input_Pos", "POSITION",0); lua_seti(L, -2, 1); 203 | push_layout(L, Effekseer::Backend::VertexLayoutFormat::R32G32B32_FLOAT, "Input_Normal", "NORMAL", 0); lua_seti(L, -2, 2); 204 | push_layout(L, Effekseer::Backend::VertexLayoutFormat::R32G32B32_FLOAT, "Input_Binormal","NORMAL", 1); lua_seti(L, -2, 3); 205 | push_layout(L, Effekseer::Backend::VertexLayoutFormat::R32G32B32_FLOAT, "Input_Tangent", "NORMAL", 2); lua_seti(L, -2, 4); 206 | push_layout(L, Effekseer::Backend::VertexLayoutFormat::R32G32_FLOAT, "Input_UV", "TEXCOORD", 0); lua_seti(L, -2, 5); 207 | push_layout(L, Effekseer::Backend::VertexLayoutFormat::R8G8B8A8_UNORM, "Input_Color", "NORMAL", 3); lua_seti(L, -2, 6); 208 | 209 | lua_setfield(L, -2, "model_layout"); 210 | return 1; 211 | } 212 | 213 | } -------------------------------------------------------------------------------- /shaders/ad_sprite_unlit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_color0 a_texcoord0 a_texcoord1 a_texcoord2 a_texcoord3 a_texcoord4 a_texcoord5 2 | $output v_Color v_UV_Others v_WorldN v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCamera; 7 | uniform mat4 u_mCameraProj; 8 | uniform vec4 u_mUVInversed; 9 | uniform vec4 u_flipbookParameter1; 10 | uniform vec4 u_flipbookParameter2; 11 | 12 | 13 | struct VS_Input 14 | { 15 | vec3 Pos; 16 | vec4 Color; 17 | vec2 UV; 18 | vec4 Alpha_Dist_UV; 19 | vec2 BlendUV; 20 | vec4 Blend_Alpha_Dist_UV; 21 | float FlipbookIndex; 22 | float AlphaThreshold; 23 | }; 24 | 25 | struct VS_Output 26 | { 27 | vec4 PosVS; 28 | vec4 Color; 29 | vec4 UV_Others; 30 | vec3 WorldN; 31 | vec4 Alpha_Dist_UV; 32 | vec4 Blend_Alpha_Dist_UV; 33 | vec4 Blend_FBNextIndex_UV; 34 | vec4 PosP; 35 | }; 36 | 37 | vec2 GetFlipbookOriginUV(vec2 FlipbookUV, float FlipbookIndex, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 38 | { 39 | vec2 DivideIndex; 40 | DivideIndex.x = float(int(FlipbookIndex) % int(DivideX)); 41 | DivideIndex.y = float(int(FlipbookIndex) / int(DivideX)); 42 | vec2 UVOffset = (DivideIndex * flipbookOneSize) + flipbookOffset; 43 | return FlipbookUV - UVOffset; 44 | } 45 | 46 | vec2 GetFlipbookUVForIndex(vec2 OriginUV, float Index, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 47 | { 48 | vec2 DivideIndex; 49 | DivideIndex.x = float(int(Index) % int(DivideX)); 50 | DivideIndex.y = float(int(Index) / int(DivideX)); 51 | return (OriginUV + (DivideIndex * flipbookOneSize)) + flipbookOffset; 52 | } 53 | 54 | void ApplyFlipbookVS(inout float flipbookRate, inout vec2 flipbookUV, vec4 flipbookParameter1, vec4 flipbookParameter2, float flipbookIndex, vec2 uv, vec2 uvInversed) 55 | { 56 | float flipbookEnabled = flipbookParameter1.x; 57 | float flipbookLoopType = flipbookParameter1.y; 58 | float divideX = flipbookParameter1.z; 59 | float divideY = flipbookParameter1.w; 60 | vec2 flipbookOneSize = flipbookParameter2.xy; 61 | vec2 flipbookOffset = flipbookParameter2.zw; 62 | if (flipbookEnabled > 0.0) 63 | { 64 | flipbookRate = fract(flipbookIndex); 65 | float Index = floor(flipbookIndex); 66 | float IndexOffset = 1.0; 67 | float NextIndex = Index + IndexOffset; 68 | float FlipbookMaxCount = divideX * divideY; 69 | if (flipbookLoopType == 0.0) 70 | { 71 | if (NextIndex >= FlipbookMaxCount) 72 | { 73 | NextIndex = FlipbookMaxCount - 1.0; 74 | Index = FlipbookMaxCount - 1.0; 75 | } 76 | } 77 | else 78 | { 79 | if (flipbookLoopType == 1.0) 80 | { 81 | Index = mod(Index, FlipbookMaxCount); 82 | NextIndex = mod(NextIndex, FlipbookMaxCount); 83 | } 84 | else 85 | { 86 | if (flipbookLoopType == 2.0) 87 | { 88 | bool Reverse = mod(floor(Index / FlipbookMaxCount), 2.0) == 1.0; 89 | Index = mod(Index, FlipbookMaxCount); 90 | if (Reverse) 91 | { 92 | Index = (FlipbookMaxCount - 1.0) - floor(Index); 93 | } 94 | Reverse = mod(floor(NextIndex / FlipbookMaxCount), 2.0) == 1.0; 95 | NextIndex = mod(NextIndex, FlipbookMaxCount); 96 | if (Reverse) 97 | { 98 | NextIndex = (FlipbookMaxCount - 1.0) - floor(NextIndex); 99 | } 100 | } 101 | } 102 | } 103 | vec2 notInversedUV = uv; 104 | notInversedUV.y = uvInversed.x + (uvInversed.y * notInversedUV.y); 105 | vec2 param = notInversedUV; 106 | float param_1 = Index; 107 | float param_2 = divideX; 108 | vec2 param_3 = flipbookOneSize; 109 | vec2 param_4 = flipbookOffset; 110 | vec2 OriginUV = GetFlipbookOriginUV(param, param_1, param_2, param_3, param_4); 111 | vec2 param_5 = OriginUV; 112 | float param_6 = NextIndex; 113 | float param_7 = divideX; 114 | vec2 param_8 = flipbookOneSize; 115 | vec2 param_9 = flipbookOffset; 116 | flipbookUV = GetFlipbookUVForIndex(param_5, param_6, param_7, param_8, param_9); 117 | flipbookUV.y = uvInversed.x + (uvInversed.y * flipbookUV.y); 118 | } 119 | } 120 | 121 | void CalculateAndStoreAdvancedParameter(VS_Input vsinput, inout VS_Output vsoutput) 122 | { 123 | vsoutput.Alpha_Dist_UV = vsinput.Alpha_Dist_UV; 124 | vsoutput.Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Alpha_Dist_UV.y); 125 | vsoutput.Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Alpha_Dist_UV.w); 126 | vsoutput.Blend_FBNextIndex_UV.x = vsinput.BlendUV.x; 127 | vsoutput.Blend_FBNextIndex_UV.y = vsinput.BlendUV.y; 128 | vsoutput.Blend_FBNextIndex_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.BlendUV.y); 129 | vsoutput.Blend_Alpha_Dist_UV = vsinput.Blend_Alpha_Dist_UV; 130 | vsoutput.Blend_Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Blend_Alpha_Dist_UV.y); 131 | vsoutput.Blend_Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Blend_Alpha_Dist_UV.w); 132 | float flipbookRate = 0.0; 133 | vec2 flipbookNextIndexUV = vec2_splat(0.0); 134 | float param = flipbookRate; 135 | vec2 param_1 = flipbookNextIndexUV; 136 | vec4 param_2 = u_flipbookParameter1; 137 | vec4 param_3 = u_flipbookParameter2; 138 | float param_4 = vsinput.FlipbookIndex; 139 | vec2 param_5 = vsoutput.UV_Others.xy; 140 | vec2 param_6 = vec2_splat(u_mUVInversed.xy); 141 | ApplyFlipbookVS(param, param_1, param_2, param_3, param_4, param_5, param_6); 142 | flipbookRate = param; 143 | flipbookNextIndexUV = param_1; 144 | vsoutput.Blend_FBNextIndex_UV.z = flipbookNextIndexUV.x; 145 | vsoutput.Blend_FBNextIndex_UV.w = flipbookNextIndexUV.y; 146 | vsoutput.UV_Others.z = flipbookRate; 147 | vsoutput.UV_Others.w = vsinput.AlphaThreshold; 148 | } 149 | 150 | VS_Output _main(VS_Input Input) 151 | { 152 | VS_Output Output = (VS_Output)0; 153 | vec2 uv1 = Input.UV; 154 | uv1.y = u_mUVInversed.x + (u_mUVInversed.y * uv1.y); 155 | Output.UV_Others.x = uv1.x; 156 | Output.UV_Others.y = uv1.y; 157 | vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 158 | Output.PosVS = mul(u_mCameraProj, worldPos); 159 | Output.Color = Input.Color; 160 | VS_Input param = Input; 161 | VS_Output param_1 = Output; 162 | CalculateAndStoreAdvancedParameter(param, param_1); 163 | Output = param_1; 164 | Output.PosP = Output.PosVS; 165 | return Output; 166 | } 167 | 168 | void main() 169 | { 170 | VS_Input Input; 171 | Input.Pos = a_position; 172 | Input.Color = a_color0; 173 | Input.UV = a_texcoord0; 174 | Input.Alpha_Dist_UV = a_texcoord1; 175 | Input.BlendUV = a_texcoord2; 176 | Input.Blend_Alpha_Dist_UV = a_texcoord3; 177 | Input.FlipbookIndex = a_texcoord4; 178 | Input.AlphaThreshold = a_texcoord5; 179 | VS_Output flattenTemp = _main(Input); 180 | vec4 _position = flattenTemp.PosVS; 181 | gl_Position = _position; 182 | v_Color = flattenTemp.Color; 183 | v_UV_Others = flattenTemp.UV_Others; 184 | v_WorldN = flattenTemp.WorldN; 185 | v_Alpha_Dist_UV = flattenTemp.Alpha_Dist_UV; 186 | v_Blend_Alpha_Dist_UV = flattenTemp.Blend_Alpha_Dist_UV; 187 | v_Blend_FBNextIndex_UV = flattenTemp.Blend_FBNextIndex_UV; 188 | v_PosP = flattenTemp.PosP; 189 | } 190 | -------------------------------------------------------------------------------- /shaders/ad_sprite_lit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_color0 a_normal a_tangent a_texcoord0 a_texcoord1 a_texcoord2 a_texcoord3 a_texcoord4 a_texcoord5 a_texcoord6 2 | $output v_Color v_UV_Others v_WorldN v_WorldB v_WorldT v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCamera; 7 | uniform mat4 u_mCameraProj; 8 | uniform vec4 u_mUVInversed; 9 | uniform vec4 u_flipbookParameter1; 10 | uniform vec4 u_flipbookParameter2; 11 | 12 | 13 | struct VS_Input 14 | { 15 | vec3 Pos; 16 | vec4 Color; 17 | vec4 Normal; 18 | vec4 Tangent; 19 | vec2 UV1; 20 | vec2 UV2; 21 | vec4 Alpha_Dist_UV; 22 | vec2 BlendUV; 23 | vec4 Blend_Alpha_Dist_UV; 24 | float FlipbookIndex; 25 | float AlphaThreshold; 26 | }; 27 | 28 | struct VS_Output 29 | { 30 | vec4 PosVS; 31 | vec4 Color; 32 | vec4 UV_Others; 33 | vec3 WorldN; 34 | vec3 WorldB; 35 | vec3 WorldT; 36 | vec4 Alpha_Dist_UV; 37 | vec4 Blend_Alpha_Dist_UV; 38 | vec4 Blend_FBNextIndex_UV; 39 | vec4 PosP; 40 | }; 41 | 42 | vec2 GetFlipbookOriginUV(vec2 FlipbookUV, float FlipbookIndex, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 43 | { 44 | vec2 DivideIndex; 45 | DivideIndex.x = float(int(FlipbookIndex) % int(DivideX)); 46 | DivideIndex.y = float(int(FlipbookIndex) / int(DivideX)); 47 | vec2 UVOffset = (DivideIndex * flipbookOneSize) + flipbookOffset; 48 | return FlipbookUV - UVOffset; 49 | } 50 | 51 | vec2 GetFlipbookUVForIndex(vec2 OriginUV, float Index, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 52 | { 53 | vec2 DivideIndex; 54 | DivideIndex.x = float(int(Index) % int(DivideX)); 55 | DivideIndex.y = float(int(Index) / int(DivideX)); 56 | return (OriginUV + (DivideIndex * flipbookOneSize)) + flipbookOffset; 57 | } 58 | 59 | void ApplyFlipbookVS(inout float flipbookRate, inout vec2 flipbookUV, vec4 flipbookParameter1, vec4 flipbookParameter2, float flipbookIndex, vec2 uv, vec2 uvInversed) 60 | { 61 | float flipbookEnabled = flipbookParameter1.x; 62 | float flipbookLoopType = flipbookParameter1.y; 63 | float divideX = flipbookParameter1.z; 64 | float divideY = flipbookParameter1.w; 65 | vec2 flipbookOneSize = flipbookParameter2.xy; 66 | vec2 flipbookOffset = flipbookParameter2.zw; 67 | if (flipbookEnabled > 0.0) 68 | { 69 | flipbookRate = fract(flipbookIndex); 70 | float Index = floor(flipbookIndex); 71 | float IndexOffset = 1.0; 72 | float NextIndex = Index + IndexOffset; 73 | float FlipbookMaxCount = divideX * divideY; 74 | if (flipbookLoopType == 0.0) 75 | { 76 | if (NextIndex >= FlipbookMaxCount) 77 | { 78 | NextIndex = FlipbookMaxCount - 1.0; 79 | Index = FlipbookMaxCount - 1.0; 80 | } 81 | } 82 | else 83 | { 84 | if (flipbookLoopType == 1.0) 85 | { 86 | Index = mod(Index, FlipbookMaxCount); 87 | NextIndex = mod(NextIndex, FlipbookMaxCount); 88 | } 89 | else 90 | { 91 | if (flipbookLoopType == 2.0) 92 | { 93 | bool Reverse = mod(floor(Index / FlipbookMaxCount), 2.0) == 1.0; 94 | Index = mod(Index, FlipbookMaxCount); 95 | if (Reverse) 96 | { 97 | Index = (FlipbookMaxCount - 1.0) - floor(Index); 98 | } 99 | Reverse = mod(floor(NextIndex / FlipbookMaxCount), 2.0) == 1.0; 100 | NextIndex = mod(NextIndex, FlipbookMaxCount); 101 | if (Reverse) 102 | { 103 | NextIndex = (FlipbookMaxCount - 1.0) - floor(NextIndex); 104 | } 105 | } 106 | } 107 | } 108 | vec2 notInversedUV = uv; 109 | notInversedUV.y = uvInversed.x + (uvInversed.y * notInversedUV.y); 110 | vec2 param = notInversedUV; 111 | float param_1 = Index; 112 | float param_2 = divideX; 113 | vec2 param_3 = flipbookOneSize; 114 | vec2 param_4 = flipbookOffset; 115 | vec2 OriginUV = GetFlipbookOriginUV(param, param_1, param_2, param_3, param_4); 116 | vec2 param_5 = OriginUV; 117 | float param_6 = NextIndex; 118 | float param_7 = divideX; 119 | vec2 param_8 = flipbookOneSize; 120 | vec2 param_9 = flipbookOffset; 121 | flipbookUV = GetFlipbookUVForIndex(param_5, param_6, param_7, param_8, param_9); 122 | flipbookUV.y = uvInversed.x + (uvInversed.y * flipbookUV.y); 123 | } 124 | } 125 | 126 | void CalculateAndStoreAdvancedParameter(VS_Input vsinput, inout VS_Output vsoutput) 127 | { 128 | vsoutput.Alpha_Dist_UV = vsinput.Alpha_Dist_UV; 129 | vsoutput.Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Alpha_Dist_UV.y); 130 | vsoutput.Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Alpha_Dist_UV.w); 131 | vsoutput.Blend_FBNextIndex_UV.x = vsinput.BlendUV.x; 132 | vsoutput.Blend_FBNextIndex_UV.y = vsinput.BlendUV.y; 133 | vsoutput.Blend_FBNextIndex_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.BlendUV.y); 134 | vsoutput.Blend_Alpha_Dist_UV = vsinput.Blend_Alpha_Dist_UV; 135 | vsoutput.Blend_Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Blend_Alpha_Dist_UV.y); 136 | vsoutput.Blend_Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Blend_Alpha_Dist_UV.w); 137 | float flipbookRate = 0.0; 138 | vec2 flipbookNextIndexUV = vec2_splat(0.0); 139 | float param = flipbookRate; 140 | vec2 param_1 = flipbookNextIndexUV; 141 | vec4 param_2 = u_flipbookParameter1; 142 | vec4 param_3 = u_flipbookParameter2; 143 | float param_4 = vsinput.FlipbookIndex; 144 | vec2 param_5 = vsoutput.UV_Others.xy; 145 | vec2 param_6 = vec2_splat(u_mUVInversed.xy); 146 | ApplyFlipbookVS(param, param_1, param_2, param_3, param_4, param_5, param_6); 147 | flipbookRate = param; 148 | flipbookNextIndexUV = param_1; 149 | vsoutput.Blend_FBNextIndex_UV.z = flipbookNextIndexUV.x; 150 | vsoutput.Blend_FBNextIndex_UV.w = flipbookNextIndexUV.y; 151 | vsoutput.UV_Others.z = flipbookRate; 152 | vsoutput.UV_Others.w = vsinput.AlphaThreshold; 153 | } 154 | 155 | VS_Output _main(VS_Input Input) 156 | { 157 | VS_Output Output = (VS_Output)0; 158 | vec4 worldNormal = vec4((Input.Normal.xyz - vec3_splat(0.5)) * 2.0, 0.0); 159 | vec4 worldTangent = vec4((Input.Tangent.xyz - vec3_splat(0.5)) * 2.0, 0.0); 160 | vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0); 161 | vec2 uv1 = Input.UV1; 162 | uv1.y = u_mUVInversed.x + (u_mUVInversed.y * uv1.y); 163 | Output.UV_Others.x = uv1.x; 164 | Output.UV_Others.y = uv1.y; 165 | vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 166 | Output.PosVS = mul(u_mCameraProj, worldPos); 167 | Output.WorldN = worldNormal.xyz; 168 | Output.WorldB = worldBinormal.xyz; 169 | Output.WorldT = worldTangent.xyz; 170 | Output.Color = Input.Color; 171 | VS_Input param = Input; 172 | VS_Output param_1 = Output; 173 | CalculateAndStoreAdvancedParameter(param, param_1); 174 | Output = param_1; 175 | Output.PosP = Output.PosVS; 176 | return Output; 177 | } 178 | 179 | void main() 180 | { 181 | VS_Input Input; 182 | Input.Pos = a_position; 183 | Input.Color = a_color0; 184 | Input.Normal = a_normal; 185 | Input.Tangent = a_tangent; 186 | Input.UV1 = a_texcoord0; 187 | Input.UV2 = a_texcoord1; 188 | Input.Alpha_Dist_UV = a_texcoord2; 189 | Input.BlendUV = a_texcoord3; 190 | Input.Blend_Alpha_Dist_UV = a_texcoord4; 191 | Input.FlipbookIndex = a_texcoord5; 192 | Input.AlphaThreshold = a_texcoord6; 193 | VS_Output flattenTemp = _main(Input); 194 | vec4 _position = flattenTemp.PosVS; 195 | gl_Position = _position; 196 | v_Color = flattenTemp.Color; 197 | v_UV_Others = flattenTemp.UV_Others; 198 | v_WorldN = flattenTemp.WorldN; 199 | v_WorldB = flattenTemp.WorldB; 200 | v_WorldT = flattenTemp.WorldT; 201 | v_Alpha_Dist_UV = flattenTemp.Alpha_Dist_UV; 202 | v_Blend_Alpha_Dist_UV = flattenTemp.Blend_Alpha_Dist_UV; 203 | v_Blend_FBNextIndex_UV = flattenTemp.Blend_FBNextIndex_UV; 204 | v_PosP = flattenTemp.PosP; 205 | } 206 | -------------------------------------------------------------------------------- /shaders/ad_sprite_distortion_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_color0 a_normal a_tangent a_texcoord0 a_texcoord1 a_texcoord2 a_texcoord3 a_texcoord4 a_texcoord5 a_texcoord6 2 | $output v_UV_Others v_ProjBinormal v_ProjTangent v_PosP v_Color v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCamera; 7 | uniform mat4 u_mCameraProj; 8 | uniform vec4 u_mUVInversed; 9 | uniform vec4 u_flipbookParameter1; 10 | uniform vec4 u_flipbookParameter2; 11 | 12 | 13 | struct VS_Input 14 | { 15 | vec3 Pos; 16 | vec4 Color; 17 | vec4 Normal; 18 | vec4 Tangent; 19 | vec2 UV1; 20 | vec2 UV2; 21 | vec4 Alpha_Dist_UV; 22 | vec2 BlendUV; 23 | vec4 Blend_Alpha_Dist_UV; 24 | float FlipbookIndex; 25 | float AlphaThreshold; 26 | }; 27 | 28 | struct VS_Output 29 | { 30 | vec4 PosVS; 31 | vec4 UV_Others; 32 | vec4 ProjBinormal; 33 | vec4 ProjTangent; 34 | vec4 PosP; 35 | vec4 Color; 36 | vec4 Alpha_Dist_UV; 37 | vec4 Blend_Alpha_Dist_UV; 38 | vec4 Blend_FBNextIndex_UV; 39 | }; 40 | 41 | vec2 GetFlipbookOriginUV(vec2 FlipbookUV, float FlipbookIndex, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 42 | { 43 | vec2 DivideIndex; 44 | DivideIndex.x = float(int(FlipbookIndex) % int(DivideX)); 45 | DivideIndex.y = float(int(FlipbookIndex) / int(DivideX)); 46 | vec2 UVOffset = (DivideIndex * flipbookOneSize) + flipbookOffset; 47 | return FlipbookUV - UVOffset; 48 | } 49 | 50 | vec2 GetFlipbookUVForIndex(vec2 OriginUV, float Index, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 51 | { 52 | vec2 DivideIndex; 53 | DivideIndex.x = float(int(Index) % int(DivideX)); 54 | DivideIndex.y = float(int(Index) / int(DivideX)); 55 | return (OriginUV + (DivideIndex * flipbookOneSize)) + flipbookOffset; 56 | } 57 | 58 | void ApplyFlipbookVS(inout float flipbookRate, inout vec2 flipbookUV, vec4 flipbookParameter1, vec4 flipbookParameter2, float flipbookIndex, vec2 uv, vec2 uvInversed) 59 | { 60 | float flipbookEnabled = flipbookParameter1.x; 61 | float flipbookLoopType = flipbookParameter1.y; 62 | float divideX = flipbookParameter1.z; 63 | float divideY = flipbookParameter1.w; 64 | vec2 flipbookOneSize = flipbookParameter2.xy; 65 | vec2 flipbookOffset = flipbookParameter2.zw; 66 | if (flipbookEnabled > 0.0) 67 | { 68 | flipbookRate = fract(flipbookIndex); 69 | float Index = floor(flipbookIndex); 70 | float IndexOffset = 1.0; 71 | float NextIndex = Index + IndexOffset; 72 | float FlipbookMaxCount = divideX * divideY; 73 | if (flipbookLoopType == 0.0) 74 | { 75 | if (NextIndex >= FlipbookMaxCount) 76 | { 77 | NextIndex = FlipbookMaxCount - 1.0; 78 | Index = FlipbookMaxCount - 1.0; 79 | } 80 | } 81 | else 82 | { 83 | if (flipbookLoopType == 1.0) 84 | { 85 | Index = mod(Index, FlipbookMaxCount); 86 | NextIndex = mod(NextIndex, FlipbookMaxCount); 87 | } 88 | else 89 | { 90 | if (flipbookLoopType == 2.0) 91 | { 92 | bool Reverse = mod(floor(Index / FlipbookMaxCount), 2.0) == 1.0; 93 | Index = mod(Index, FlipbookMaxCount); 94 | if (Reverse) 95 | { 96 | Index = (FlipbookMaxCount - 1.0) - floor(Index); 97 | } 98 | Reverse = mod(floor(NextIndex / FlipbookMaxCount), 2.0) == 1.0; 99 | NextIndex = mod(NextIndex, FlipbookMaxCount); 100 | if (Reverse) 101 | { 102 | NextIndex = (FlipbookMaxCount - 1.0) - floor(NextIndex); 103 | } 104 | } 105 | } 106 | } 107 | vec2 notInversedUV = uv; 108 | notInversedUV.y = uvInversed.x + (uvInversed.y * notInversedUV.y); 109 | vec2 param = notInversedUV; 110 | float param_1 = Index; 111 | float param_2 = divideX; 112 | vec2 param_3 = flipbookOneSize; 113 | vec2 param_4 = flipbookOffset; 114 | vec2 OriginUV = GetFlipbookOriginUV(param, param_1, param_2, param_3, param_4); 115 | vec2 param_5 = OriginUV; 116 | float param_6 = NextIndex; 117 | float param_7 = divideX; 118 | vec2 param_8 = flipbookOneSize; 119 | vec2 param_9 = flipbookOffset; 120 | flipbookUV = GetFlipbookUVForIndex(param_5, param_6, param_7, param_8, param_9); 121 | flipbookUV.y = uvInversed.x + (uvInversed.y * flipbookUV.y); 122 | } 123 | } 124 | 125 | void CalculateAndStoreAdvancedParameter(VS_Input vsinput, inout VS_Output vsoutput) 126 | { 127 | vsoutput.Alpha_Dist_UV = vsinput.Alpha_Dist_UV; 128 | vsoutput.Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Alpha_Dist_UV.y); 129 | vsoutput.Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Alpha_Dist_UV.w); 130 | vsoutput.Blend_FBNextIndex_UV.x = vsinput.BlendUV.x; 131 | vsoutput.Blend_FBNextIndex_UV.y = vsinput.BlendUV.y; 132 | vsoutput.Blend_FBNextIndex_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.BlendUV.y); 133 | vsoutput.Blend_Alpha_Dist_UV = vsinput.Blend_Alpha_Dist_UV; 134 | vsoutput.Blend_Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Blend_Alpha_Dist_UV.y); 135 | vsoutput.Blend_Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsinput.Blend_Alpha_Dist_UV.w); 136 | float flipbookRate = 0.0; 137 | vec2 flipbookNextIndexUV = vec2_splat(0.0); 138 | float param = flipbookRate; 139 | vec2 param_1 = flipbookNextIndexUV; 140 | vec4 param_2 = u_flipbookParameter1; 141 | vec4 param_3 = u_flipbookParameter2; 142 | float param_4 = vsinput.FlipbookIndex; 143 | vec2 param_5 = vsoutput.UV_Others.xy; 144 | vec2 param_6 = vec2_splat(u_mUVInversed.xy); 145 | ApplyFlipbookVS(param, param_1, param_2, param_3, param_4, param_5, param_6); 146 | flipbookRate = param; 147 | flipbookNextIndexUV = param_1; 148 | vsoutput.Blend_FBNextIndex_UV.z = flipbookNextIndexUV.x; 149 | vsoutput.Blend_FBNextIndex_UV.w = flipbookNextIndexUV.y; 150 | vsoutput.UV_Others.z = flipbookRate; 151 | vsoutput.UV_Others.w = vsinput.AlphaThreshold; 152 | } 153 | 154 | VS_Output _main(VS_Input Input) 155 | { 156 | VS_Output Output = (VS_Output)0; 157 | vec4 worldNormal = vec4((Input.Normal.xyz - vec3_splat(0.5)) * 2.0, 0.0); 158 | vec4 worldTangent = vec4((Input.Tangent.xyz - vec3_splat(0.5)) * 2.0, 0.0); 159 | vec4 worldBinormal = vec4(cross(worldNormal.xyz, worldTangent.xyz), 0.0); 160 | vec2 uv1 = Input.UV1; 161 | uv1.y = u_mUVInversed.x + (u_mUVInversed.y * uv1.y); 162 | Output.UV_Others.x = uv1.x; 163 | Output.UV_Others.y = uv1.y; 164 | vec4 worldPos = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 165 | Output.PosVS = mul(u_mCameraProj, worldPos); 166 | Output.ProjTangent = mul(u_mCameraProj, (worldPos + worldTangent)); 167 | Output.ProjBinormal = mul(u_mCameraProj, (worldPos + worldBinormal)); 168 | Output.Color = Input.Color; 169 | VS_Input param = Input; 170 | VS_Output param_1 = Output; 171 | CalculateAndStoreAdvancedParameter(param, param_1); 172 | Output = param_1; 173 | Output.PosP = Output.PosVS; 174 | return Output; 175 | } 176 | 177 | void main() 178 | { 179 | VS_Input Input; 180 | Input.Pos = a_position; 181 | Input.Color = a_color0; 182 | Input.Normal = a_normal; 183 | Input.Tangent = a_tangent; 184 | Input.UV1 = a_texcoord0; 185 | Input.UV2 = a_texcoord1; 186 | Input.Alpha_Dist_UV = a_texcoord2; 187 | Input.BlendUV = a_texcoord3; 188 | Input.Blend_Alpha_Dist_UV = a_texcoord4; 189 | Input.FlipbookIndex = a_texcoord5; 190 | Input.AlphaThreshold = a_texcoord6; 191 | VS_Output flattenTemp = _main(Input); 192 | vec4 _position = flattenTemp.PosVS; 193 | gl_Position = _position; 194 | v_UV_Others = flattenTemp.UV_Others; 195 | v_ProjBinormal = flattenTemp.ProjBinormal; 196 | v_ProjTangent = flattenTemp.ProjTangent; 197 | v_PosP = flattenTemp.PosP; 198 | v_Color = flattenTemp.Color; 199 | v_Alpha_Dist_UV = flattenTemp.Alpha_Dist_UV; 200 | v_Blend_Alpha_Dist_UV = flattenTemp.Blend_Alpha_Dist_UV; 201 | v_Blend_FBNextIndex_UV = flattenTemp.Blend_FBNextIndex_UV; 202 | } 203 | -------------------------------------------------------------------------------- /shaders/ad_model_unlit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_normal a_bitangent a_tangent a_texcoord0 a_color0 2 | $output v_Color v_UV_Others v_WorldN v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCameraProj; 7 | uniform mat4 u_mModel_Inst[40]; 8 | uniform vec4 u_fUV[40]; 9 | uniform vec4 u_fAlphaUV[40]; 10 | uniform vec4 u_fUVDistortionUV[40]; 11 | uniform vec4 u_fBlendUV[40]; 12 | uniform vec4 u_fBlendAlphaUV[40]; 13 | uniform vec4 u_fBlendUVDistortionUV[40]; 14 | uniform vec4 u_flipbookParameter1; 15 | uniform vec4 u_flipbookParameter2; 16 | uniform vec4 u_fFlipbookIndexAndNextRate[40]; 17 | uniform vec4 u_fModelAlphaThreshold[40]; 18 | uniform vec4 u_fModelColor[40]; 19 | uniform vec4 u_fLightDirection; 20 | uniform vec4 u_fLightColor; 21 | uniform vec4 u_fLightAmbient; 22 | uniform vec4 u_mUVInversed; 23 | 24 | 25 | struct VS_Output 26 | { 27 | vec4 PosVS; 28 | vec4 Color; 29 | vec4 UV_Others; 30 | vec3 WorldN; 31 | vec4 Alpha_Dist_UV; 32 | vec4 Blend_Alpha_Dist_UV; 33 | vec4 Blend_FBNextIndex_UV; 34 | vec4 PosP; 35 | }; 36 | 37 | struct VS_Input 38 | { 39 | vec3 Pos; 40 | vec3 Normal; 41 | vec3 Binormal; 42 | vec3 Tangent; 43 | vec2 UV; 44 | vec4 Color; 45 | uint Index; 46 | }; 47 | 48 | vec2 GetFlipbookOriginUV(vec2 FlipbookUV, float FlipbookIndex, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 49 | { 50 | vec2 DivideIndex; 51 | DivideIndex.x = float(int(FlipbookIndex) % int(DivideX)); 52 | DivideIndex.y = float(int(FlipbookIndex) / int(DivideX)); 53 | vec2 UVOffset = (DivideIndex * flipbookOneSize) + flipbookOffset; 54 | return FlipbookUV - UVOffset; 55 | } 56 | 57 | vec2 GetFlipbookUVForIndex(vec2 OriginUV, float Index, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 58 | { 59 | vec2 DivideIndex; 60 | DivideIndex.x = float(int(Index) % int(DivideX)); 61 | DivideIndex.y = float(int(Index) / int(DivideX)); 62 | return (OriginUV + (DivideIndex * flipbookOneSize)) + flipbookOffset; 63 | } 64 | 65 | void ApplyFlipbookVS(inout float flipbookRate, inout vec2 flipbookUV, vec4 flipbookParameter1, vec4 flipbookParameter2, float flipbookIndex, vec2 uv, vec2 uvInversed) 66 | { 67 | float flipbookEnabled = flipbookParameter1.x; 68 | float flipbookLoopType = flipbookParameter1.y; 69 | float divideX = flipbookParameter1.z; 70 | float divideY = flipbookParameter1.w; 71 | vec2 flipbookOneSize = flipbookParameter2.xy; 72 | vec2 flipbookOffset = flipbookParameter2.zw; 73 | if (flipbookEnabled > 0.0) 74 | { 75 | flipbookRate = fract(flipbookIndex); 76 | float Index = floor(flipbookIndex); 77 | float IndexOffset = 1.0; 78 | float NextIndex = Index + IndexOffset; 79 | float FlipbookMaxCount = divideX * divideY; 80 | if (flipbookLoopType == 0.0) 81 | { 82 | if (NextIndex >= FlipbookMaxCount) 83 | { 84 | NextIndex = FlipbookMaxCount - 1.0; 85 | Index = FlipbookMaxCount - 1.0; 86 | } 87 | } 88 | else 89 | { 90 | if (flipbookLoopType == 1.0) 91 | { 92 | Index = mod(Index, FlipbookMaxCount); 93 | NextIndex = mod(NextIndex, FlipbookMaxCount); 94 | } 95 | else 96 | { 97 | if (flipbookLoopType == 2.0) 98 | { 99 | bool Reverse = mod(floor(Index / FlipbookMaxCount), 2.0) == 1.0; 100 | Index = mod(Index, FlipbookMaxCount); 101 | if (Reverse) 102 | { 103 | Index = (FlipbookMaxCount - 1.0) - floor(Index); 104 | } 105 | Reverse = mod(floor(NextIndex / FlipbookMaxCount), 2.0) == 1.0; 106 | NextIndex = mod(NextIndex, FlipbookMaxCount); 107 | if (Reverse) 108 | { 109 | NextIndex = (FlipbookMaxCount - 1.0) - floor(NextIndex); 110 | } 111 | } 112 | } 113 | } 114 | vec2 notInversedUV = uv; 115 | notInversedUV.y = uvInversed.x + (uvInversed.y * notInversedUV.y); 116 | vec2 param = notInversedUV; 117 | float param_1 = Index; 118 | float param_2 = divideX; 119 | vec2 param_3 = flipbookOneSize; 120 | vec2 param_4 = flipbookOffset; 121 | vec2 OriginUV = GetFlipbookOriginUV(param, param_1, param_2, param_3, param_4); 122 | vec2 param_5 = OriginUV; 123 | float param_6 = NextIndex; 124 | float param_7 = divideX; 125 | vec2 param_8 = flipbookOneSize; 126 | vec2 param_9 = flipbookOffset; 127 | flipbookUV = GetFlipbookUVForIndex(param_5, param_6, param_7, param_8, param_9); 128 | flipbookUV.y = uvInversed.x + (uvInversed.y * flipbookUV.y); 129 | } 130 | } 131 | 132 | void CalculateAndStoreAdvancedParameter(vec2 uv, vec2 uv1, vec4 alphaUV, vec4 uvDistortionUV, vec4 blendUV, vec4 blendAlphaUV, vec4 blendUVDistortionUV, float flipbookIndexAndNextRate, float modelAlphaThreshold, inout VS_Output vsoutput) 133 | { 134 | vsoutput.Alpha_Dist_UV.x = (uv.x * alphaUV.z) + alphaUV.x; 135 | vsoutput.Alpha_Dist_UV.y = (uv.y * alphaUV.w) + alphaUV.y; 136 | vsoutput.Alpha_Dist_UV.z = (uv.x * uvDistortionUV.z) + uvDistortionUV.x; 137 | vsoutput.Alpha_Dist_UV.w = (uv.y * uvDistortionUV.w) + uvDistortionUV.y; 138 | vsoutput.Blend_FBNextIndex_UV.x = (uv.x * blendUV.z) + blendUV.x; 139 | vsoutput.Blend_FBNextIndex_UV.y = (uv.y * blendUV.w) + blendUV.y; 140 | vsoutput.Blend_Alpha_Dist_UV.x = (uv.x * blendAlphaUV.z) + blendAlphaUV.x; 141 | vsoutput.Blend_Alpha_Dist_UV.y = (uv.y * blendAlphaUV.w) + blendAlphaUV.y; 142 | vsoutput.Blend_Alpha_Dist_UV.z = (uv.x * blendUVDistortionUV.z) + blendUVDistortionUV.x; 143 | vsoutput.Blend_Alpha_Dist_UV.w = (uv.y * blendUVDistortionUV.w) + blendUVDistortionUV.y; 144 | float flipbookRate = 0.0; 145 | vec2 flipbookNextIndexUV = vec2_splat(0.0); 146 | float param = flipbookRate; 147 | vec2 param_1 = flipbookNextIndexUV; 148 | vec4 param_2 = u_flipbookParameter1; 149 | vec4 param_3 = u_flipbookParameter2; 150 | float param_4 = flipbookIndexAndNextRate; 151 | vec2 param_5 = uv1; 152 | vec2 param_6 = vec2_splat(u_mUVInversed.xy); 153 | ApplyFlipbookVS(param, param_1, param_2, param_3, param_4, param_5, param_6); 154 | flipbookRate = param; 155 | flipbookNextIndexUV = param_1; 156 | vsoutput.Blend_FBNextIndex_UV.z = flipbookNextIndexUV.x; 157 | vsoutput.Blend_FBNextIndex_UV.w = flipbookNextIndexUV.y; 158 | vsoutput.UV_Others.z = flipbookRate; 159 | vsoutput.UV_Others.w = modelAlphaThreshold; 160 | vsoutput.Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Alpha_Dist_UV.y); 161 | vsoutput.Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Alpha_Dist_UV.w); 162 | vsoutput.Blend_FBNextIndex_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_FBNextIndex_UV.y); 163 | vsoutput.Blend_Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_Alpha_Dist_UV.y); 164 | vsoutput.Blend_Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_Alpha_Dist_UV.w); 165 | } 166 | 167 | VS_Output _main(VS_Input Input) 168 | { 169 | uint index = Input.Index; 170 | mat4 mModel = u_mModel_Inst[index]; 171 | vec4 uv = u_fUV[index]; 172 | vec4 alphaUV = u_fAlphaUV[index]; 173 | vec4 uvDistortionUV = u_fUVDistortionUV[index]; 174 | vec4 blendUV = u_fBlendUV[index]; 175 | vec4 blendAlphaUV = u_fBlendAlphaUV[index]; 176 | vec4 blendUVDistortionUV = u_fBlendUVDistortionUV[index]; 177 | vec4 modelColor = u_fModelColor[index] * Input.Color; 178 | float flipbookIndexAndNextRate = u_fFlipbookIndexAndNextRate[index].x; 179 | float modelAlphaThreshold = u_fModelAlphaThreshold[index].x; 180 | VS_Output Output = (VS_Output)0; 181 | vec4 localPosition = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 182 | vec4 worldPos = mul(mModel, localPosition); 183 | Output.PosVS = mul(u_mCameraProj, worldPos); 184 | vec2 outputUV = Input.UV; 185 | outputUV.x = (outputUV.x * uv.z) + uv.x; 186 | outputUV.y = (outputUV.y * uv.w) + uv.y; 187 | outputUV.y = u_mUVInversed.x + (u_mUVInversed.y * outputUV.y); 188 | Output.UV_Others.x = outputUV.x; 189 | Output.UV_Others.y = outputUV.y; 190 | vec4 localNormal = vec4(Input.Normal.x, Input.Normal.y, Input.Normal.z, 0.0); 191 | localNormal = normalize(mul(mModel, localNormal)); 192 | Output.WorldN = localNormal.xyz; 193 | Output.Color = modelColor; 194 | vec2 param = Input.UV; 195 | vec2 param_1 = Output.UV_Others.xy; 196 | vec4 param_2 = alphaUV; 197 | vec4 param_3 = uvDistortionUV; 198 | vec4 param_4 = blendUV; 199 | vec4 param_5 = blendAlphaUV; 200 | vec4 param_6 = blendUVDistortionUV; 201 | float param_7 = flipbookIndexAndNextRate; 202 | float param_8 = modelAlphaThreshold; 203 | VS_Output param_9 = Output; 204 | CalculateAndStoreAdvancedParameter(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7, param_8, param_9); 205 | Output = param_9; 206 | Output.PosP = Output.PosVS; 207 | return Output; 208 | } 209 | 210 | void main() 211 | { 212 | VS_Input Input; 213 | Input.Pos = a_position; 214 | Input.Normal = a_normal; 215 | Input.Binormal = a_bitangent; 216 | Input.Tangent = a_tangent; 217 | Input.UV = a_texcoord0; 218 | Input.Color = a_color0; 219 | Input.Index = uint(gl_InstanceIndex); 220 | VS_Output flattenTemp = _main(Input); 221 | vec4 _position = flattenTemp.PosVS; 222 | gl_Position = _position; 223 | v_Color = flattenTemp.Color; 224 | v_UV_Others = flattenTemp.UV_Others; 225 | v_WorldN = flattenTemp.WorldN; 226 | v_Alpha_Dist_UV = flattenTemp.Alpha_Dist_UV; 227 | v_Blend_Alpha_Dist_UV = flattenTemp.Blend_Alpha_Dist_UV; 228 | v_Blend_FBNextIndex_UV = flattenTemp.Blend_FBNextIndex_UV; 229 | v_PosP = flattenTemp.PosP; 230 | } 231 | -------------------------------------------------------------------------------- /shaders/ad_model_distortion_ps.fx.sc: -------------------------------------------------------------------------------- 1 | $input v_UV_Others v_ProjBinormal v_ProjTangent v_PosP v_Color v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV 2 | 3 | #include 4 | #include "defines.sh" 5 | uniform vec4 u_fsg_scale; 6 | uniform vec4 u_fsmUVInversedBack; 7 | uniform vec4 u_fsfFlipbookParameter; 8 | uniform vec4 u_fsfUVDistortionParameter; 9 | uniform vec4 u_fsfBlendTextureParameter; 10 | uniform vec4 u_fssoftParticleParam; 11 | uniform vec4 u_fsreconstructionParam1; 12 | uniform vec4 u_fsreconstructionParam2; 13 | SAMPLER2D (s_uvDistortionTex,3); 14 | SAMPLER2D (s_colorTex,0); 15 | SAMPLER2D (s_alphaTex,2); 16 | SAMPLER2D (s_blendUVDistortionTex,6); 17 | SAMPLER2D (s_blendTex,4); 18 | SAMPLER2D (s_blendAlphaTex,5); 19 | SAMPLER2D (s_backTex,1); 20 | SAMPLER2D (s_depthTex,7); 21 | 22 | struct PS_Input 23 | { 24 | vec4 PosVS; 25 | vec4 UV_Others; 26 | vec4 ProjBinormal; 27 | vec4 ProjTangent; 28 | vec4 PosP; 29 | vec4 Color; 30 | vec4 Alpha_Dist_UV; 31 | vec4 Blend_Alpha_Dist_UV; 32 | vec4 Blend_FBNextIndex_UV; 33 | }; 34 | 35 | struct AdvancedParameter 36 | { 37 | vec2 AlphaUV; 38 | vec2 UVDistortionUV; 39 | vec2 BlendUV; 40 | vec2 BlendAlphaUV; 41 | vec2 BlendUVDistortionUV; 42 | vec2 FlipbookNextIndexUV; 43 | float FlipbookRate; 44 | float AlphaThreshold; 45 | }; 46 | 47 | AdvancedParameter DisolveAdvancedParameter(PS_Input psinput) 48 | { 49 | AdvancedParameter ret; 50 | ret.AlphaUV = psinput.Alpha_Dist_UV.xy; 51 | ret.UVDistortionUV = psinput.Alpha_Dist_UV.zw; 52 | ret.BlendUV = psinput.Blend_FBNextIndex_UV.xy; 53 | ret.BlendAlphaUV = psinput.Blend_Alpha_Dist_UV.xy; 54 | ret.BlendUVDistortionUV = psinput.Blend_Alpha_Dist_UV.zw; 55 | ret.FlipbookNextIndexUV = psinput.Blend_FBNextIndex_UV.zw; 56 | ret.FlipbookRate = psinput.UV_Others.z; 57 | ret.AlphaThreshold = psinput.UV_Others.w; 58 | return ret; 59 | } 60 | 61 | vec3 PositivePow(vec3 base, vec3 power) 62 | { 63 | return pow(max(abs(base), vec3_splat(1.1920928955078125e-07)), power); 64 | } 65 | 66 | vec3 LinearToSRGB(vec3 c) 67 | { 68 | vec3 param = c; 69 | vec3 param_1 = vec3_splat(0.4166666567325592041015625); 70 | return max((PositivePow(param, param_1) * 1.05499994754791259765625) - vec3_splat(0.054999999701976776123046875), vec3_splat(0.0)); 71 | } 72 | 73 | vec4 LinearToSRGB(vec4 c) 74 | { 75 | vec3 param = c.xyz; 76 | return vec4(LinearToSRGB(param), c.w); 77 | } 78 | 79 | vec4 ConvertFromSRGBTexture(vec4 c, bool isValid) 80 | { 81 | if (!isValid) 82 | { 83 | return c; 84 | } 85 | vec4 param = c; 86 | return LinearToSRGB(param); 87 | } 88 | 89 | vec2 UVDistortionOffset(vec2 uv, vec2 uvInversed, bool convertFromSRGB, struct BgfxSampler2D SPIRV_Cross_Combinedts) 90 | { 91 | vec4 sampledColor = texture2D(SPIRV_Cross_Combinedts, uv); 92 | if (convertFromSRGB) 93 | { 94 | vec4 param = sampledColor; 95 | bool param_1 = convertFromSRGB; 96 | sampledColor = ConvertFromSRGBTexture(param, param_1); 97 | } 98 | vec2 UVOffset = (sampledColor.xy * 2.0) - vec2_splat(1.0); 99 | UVOffset.y *= (-1.0); 100 | UVOffset.y = uvInversed.x + (uvInversed.y * UVOffset.y); 101 | return UVOffset; 102 | } 103 | 104 | void ApplyFlipbook(inout vec4 dst, vec4 flipbookParameter, vec4 vcolor, vec2 nextUV, float flipbookRate, bool convertFromSRGB, struct BgfxSampler2D SPIRV_Cross_Combinedts) 105 | { 106 | if (flipbookParameter.x > 0.0) 107 | { 108 | vec4 sampledColor = texture2D(SPIRV_Cross_Combinedts, nextUV); 109 | if (convertFromSRGB) 110 | { 111 | vec4 param = sampledColor; 112 | bool param_1 = convertFromSRGB; 113 | sampledColor = ConvertFromSRGBTexture(param, param_1); 114 | } 115 | vec4 NextPixelColor = sampledColor * vcolor; 116 | if (flipbookParameter.y == 1.0) 117 | { 118 | dst = mix(dst, NextPixelColor, vec4_splat(flipbookRate)); 119 | } 120 | } 121 | } 122 | 123 | void ApplyTextureBlending(inout vec4 dstColor, vec4 blendColor, float blendType) 124 | { 125 | if (blendType == 0.0) 126 | { 127 | vec4 _169 = dstColor; 128 | vec3 _172 = (blendColor.xyz * blendColor.w) + (_169.xyz * (1.0 - blendColor.w)); 129 | dstColor.x = _172.x; 130 | dstColor.y = _172.y; 131 | dstColor.z = _172.z; 132 | } 133 | else 134 | { 135 | if (blendType == 1.0) 136 | { 137 | vec4 _187 = dstColor; 138 | vec3 _189 = _187.xyz + (blendColor.xyz * blendColor.w); 139 | dstColor.x = _189.x; 140 | dstColor.y = _189.y; 141 | dstColor.z = _189.z; 142 | } 143 | else 144 | { 145 | if (blendType == 2.0) 146 | { 147 | vec4 _204 = dstColor; 148 | vec3 _206 = _204.xyz - (blendColor.xyz * blendColor.w); 149 | dstColor.x = _206.x; 150 | dstColor.y = _206.y; 151 | dstColor.z = _206.z; 152 | } 153 | else 154 | { 155 | if (blendType == 3.0) 156 | { 157 | vec4 _221 = dstColor; 158 | vec3 _223 = _221.xyz * (blendColor.xyz * blendColor.w); 159 | dstColor.x = _223.x; 160 | dstColor.y = _223.y; 161 | dstColor.z = _223.z; 162 | } 163 | } 164 | } 165 | } 166 | } 167 | 168 | float SoftParticle(float backgroundZ, float meshZ, vec4 softparticleParam, vec4 reconstruct1, vec4 reconstruct2) 169 | { 170 | float distanceFar = softparticleParam.x; 171 | float distanceNear = softparticleParam.y; 172 | float distanceNearOffset = softparticleParam.z; 173 | vec2 rescale = reconstruct1.xy; 174 | vec4 params = reconstruct2; 175 | vec2 zs = vec2((backgroundZ * rescale.x) + rescale.y, meshZ); 176 | vec2 depth = ((zs * params.w) - vec2_splat(params.y)) / (vec2_splat(params.x) - (zs * params.z)); 177 | float dir = sign(depth.x); 178 | depth *= dir; 179 | float alphaFar = (depth.x - depth.y) / distanceFar; 180 | float alphaNear = (depth.y - distanceNearOffset) / distanceNear; 181 | return min(max(min(alphaFar, alphaNear), 0.0), 1.0); 182 | } 183 | 184 | vec4 _main(PS_Input Input) 185 | { 186 | PS_Input param = Input; 187 | AdvancedParameter advancedParam = DisolveAdvancedParameter(param); 188 | vec2 param_1 = advancedParam.UVDistortionUV; 189 | vec2 param_2 = u_fsfUVDistortionParameter.zw; 190 | bool param_3 = false; 191 | vec2 UVOffset = UVDistortionOffset(param_1, param_2, param_3, s_uvDistortionTex); 192 | UVOffset *= u_fsfUVDistortionParameter.x; 193 | vec4 Output = texture2D(s_colorTex, vec2_splat(Input.UV_Others.xy) + UVOffset); 194 | Output.w *= Input.Color.w; 195 | vec4 param_4 = Output; 196 | float param_5 = advancedParam.FlipbookRate; 197 | bool param_6 = false; 198 | ApplyFlipbook(param_4, u_fsfFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, param_5, param_6, s_colorTex); 199 | Output = param_4; 200 | vec4 AlphaTexColor = texture2D(s_alphaTex, advancedParam.AlphaUV + UVOffset); 201 | Output.w *= (AlphaTexColor.x * AlphaTexColor.w); 202 | vec2 param_7 = advancedParam.BlendUVDistortionUV; 203 | vec2 param_8 = u_fsfUVDistortionParameter.zw; 204 | bool param_9 = false; 205 | vec2 BlendUVOffset = UVDistortionOffset(param_7, param_8, param_9, s_blendUVDistortionTex); 206 | BlendUVOffset *= u_fsfUVDistortionParameter.y; 207 | vec4 BlendTextureColor = texture2D(s_blendTex, advancedParam.BlendUV + BlendUVOffset); 208 | vec4 BlendAlphaTextureColor = texture2D(s_blendAlphaTex, advancedParam.BlendAlphaUV + BlendUVOffset); 209 | BlendTextureColor.w *= (BlendAlphaTextureColor.x * BlendAlphaTextureColor.w); 210 | vec4 param_10 = Output; 211 | ApplyTextureBlending(param_10, BlendTextureColor, u_fsfBlendTextureParameter.x); 212 | Output = param_10; 213 | if (Output.w <= max(0.0, advancedParam.AlphaThreshold)) 214 | { 215 | discard; 216 | } 217 | vec2 pos = Input.PosP.xy / vec2_splat(Input.PosP.w); 218 | vec2 posR = Input.ProjTangent.xy / vec2_splat(Input.ProjTangent.w); 219 | vec2 posU = Input.ProjBinormal.xy / vec2_splat(Input.ProjBinormal.w); 220 | float xscale = (((Output.x * 2.0) - 1.0) * Input.Color.x) * u_fsg_scale.x; 221 | float yscale = (((Output.y * 2.0) - 1.0) * Input.Color.y) * u_fsg_scale.x; 222 | vec2 uv = (pos + ((posR - pos) * xscale)) + ((posU - pos) * yscale); 223 | uv.x = (uv.x + 1.0) * 0.5; 224 | uv.y = 1.0 - ((uv.y + 1.0) * 0.5); 225 | uv.y = u_fsmUVInversedBack.x + (u_fsmUVInversedBack.y * uv.y); 226 | vec3 color = vec3(texture2D(s_backTex, uv).xyz); 227 | Output.x = color.x; 228 | Output.y = color.y; 229 | Output.z = color.z; 230 | vec4 screenPos = Input.PosP / vec4_splat(Input.PosP.w); 231 | vec2 screenUV = (screenPos.xy + vec2_splat(1.0)) / vec2_splat(2.0); 232 | screenUV.y = 1.0 - screenUV.y; 233 | if (u_fssoftParticleParam.w != 0.0) 234 | { 235 | float backgroundZ = texture2D(s_depthTex, screenUV).x; 236 | float param_11 = backgroundZ; 237 | float param_12 = screenPos.z; 238 | vec4 param_13 = u_fssoftParticleParam; 239 | vec4 param_14 = u_fsreconstructionParam1; 240 | vec4 param_15 = u_fsreconstructionParam2; 241 | Output.w *= SoftParticle(param_11, param_12, param_13, param_14, param_15); 242 | } 243 | return Output; 244 | } 245 | 246 | void main() 247 | { 248 | PS_Input Input; 249 | Input.PosVS = gl_FragCoord; 250 | Input.UV_Others = v_UV_Others; 251 | Input.ProjBinormal = v_ProjBinormal; 252 | Input.ProjTangent = v_ProjTangent; 253 | Input.PosP = v_PosP; 254 | #ifdef LINEAR_INPUT_COLOR 255 | Input.Color = to_linear(v_Color); 256 | #else 257 | Input.Color = v_Color; 258 | #endif //LINEAR_INPUT_COLOR 259 | 260 | Input.Alpha_Dist_UV = v_Alpha_Dist_UV; 261 | Input.Blend_Alpha_Dist_UV = v_Blend_Alpha_Dist_UV; 262 | Input.Blend_FBNextIndex_UV = v_Blend_FBNextIndex_UV; 263 | vec4 _706 = _main(Input); 264 | gl_FragColor = _706; 265 | } 266 | -------------------------------------------------------------------------------- /shaders/ad_model_lit_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_normal a_bitangent a_tangent a_texcoord0 a_color0 2 | $output v_Color v_UV_Others v_WorldN v_WorldB v_WorldT v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV v_PosP 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCameraProj; 7 | uniform mat4 u_mModel_Inst[40]; 8 | uniform vec4 u_fUV[40]; 9 | uniform vec4 u_fAlphaUV[40]; 10 | uniform vec4 u_fUVDistortionUV[40]; 11 | uniform vec4 u_fBlendUV[40]; 12 | uniform vec4 u_fBlendAlphaUV[40]; 13 | uniform vec4 u_fBlendUVDistortionUV[40]; 14 | uniform vec4 u_flipbookParameter1; 15 | uniform vec4 u_flipbookParameter2; 16 | uniform vec4 u_fFlipbookIndexAndNextRate[40]; 17 | uniform vec4 u_fModelAlphaThreshold[40]; 18 | uniform vec4 u_fModelColor[40]; 19 | uniform vec4 u_fLightDirection; 20 | uniform vec4 u_fLightColor; 21 | uniform vec4 u_fLightAmbient; 22 | uniform vec4 u_mUVInversed; 23 | 24 | 25 | struct VS_Output 26 | { 27 | vec4 PosVS; 28 | vec4 Color; 29 | vec4 UV_Others; 30 | vec3 WorldN; 31 | vec3 WorldB; 32 | vec3 WorldT; 33 | vec4 Alpha_Dist_UV; 34 | vec4 Blend_Alpha_Dist_UV; 35 | vec4 Blend_FBNextIndex_UV; 36 | vec4 PosP; 37 | }; 38 | 39 | struct VS_Input 40 | { 41 | vec3 Pos; 42 | vec3 Normal; 43 | vec3 Binormal; 44 | vec3 Tangent; 45 | vec2 UV; 46 | vec4 Color; 47 | uint Index; 48 | }; 49 | 50 | vec2 GetFlipbookOriginUV(vec2 FlipbookUV, float FlipbookIndex, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 51 | { 52 | vec2 DivideIndex; 53 | DivideIndex.x = float(int(FlipbookIndex) % int(DivideX)); 54 | DivideIndex.y = float(int(FlipbookIndex) / int(DivideX)); 55 | vec2 UVOffset = (DivideIndex * flipbookOneSize) + flipbookOffset; 56 | return FlipbookUV - UVOffset; 57 | } 58 | 59 | vec2 GetFlipbookUVForIndex(vec2 OriginUV, float Index, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 60 | { 61 | vec2 DivideIndex; 62 | DivideIndex.x = float(int(Index) % int(DivideX)); 63 | DivideIndex.y = float(int(Index) / int(DivideX)); 64 | return (OriginUV + (DivideIndex * flipbookOneSize)) + flipbookOffset; 65 | } 66 | 67 | void ApplyFlipbookVS(inout float flipbookRate, inout vec2 flipbookUV, vec4 flipbookParameter1, vec4 flipbookParameter2, float flipbookIndex, vec2 uv, vec2 uvInversed) 68 | { 69 | float flipbookEnabled = flipbookParameter1.x; 70 | float flipbookLoopType = flipbookParameter1.y; 71 | float divideX = flipbookParameter1.z; 72 | float divideY = flipbookParameter1.w; 73 | vec2 flipbookOneSize = flipbookParameter2.xy; 74 | vec2 flipbookOffset = flipbookParameter2.zw; 75 | if (flipbookEnabled > 0.0) 76 | { 77 | flipbookRate = fract(flipbookIndex); 78 | float Index = floor(flipbookIndex); 79 | float IndexOffset = 1.0; 80 | float NextIndex = Index + IndexOffset; 81 | float FlipbookMaxCount = divideX * divideY; 82 | if (flipbookLoopType == 0.0) 83 | { 84 | if (NextIndex >= FlipbookMaxCount) 85 | { 86 | NextIndex = FlipbookMaxCount - 1.0; 87 | Index = FlipbookMaxCount - 1.0; 88 | } 89 | } 90 | else 91 | { 92 | if (flipbookLoopType == 1.0) 93 | { 94 | Index = mod(Index, FlipbookMaxCount); 95 | NextIndex = mod(NextIndex, FlipbookMaxCount); 96 | } 97 | else 98 | { 99 | if (flipbookLoopType == 2.0) 100 | { 101 | bool Reverse = mod(floor(Index / FlipbookMaxCount), 2.0) == 1.0; 102 | Index = mod(Index, FlipbookMaxCount); 103 | if (Reverse) 104 | { 105 | Index = (FlipbookMaxCount - 1.0) - floor(Index); 106 | } 107 | Reverse = mod(floor(NextIndex / FlipbookMaxCount), 2.0) == 1.0; 108 | NextIndex = mod(NextIndex, FlipbookMaxCount); 109 | if (Reverse) 110 | { 111 | NextIndex = (FlipbookMaxCount - 1.0) - floor(NextIndex); 112 | } 113 | } 114 | } 115 | } 116 | vec2 notInversedUV = uv; 117 | notInversedUV.y = uvInversed.x + (uvInversed.y * notInversedUV.y); 118 | vec2 param = notInversedUV; 119 | float param_1 = Index; 120 | float param_2 = divideX; 121 | vec2 param_3 = flipbookOneSize; 122 | vec2 param_4 = flipbookOffset; 123 | vec2 OriginUV = GetFlipbookOriginUV(param, param_1, param_2, param_3, param_4); 124 | vec2 param_5 = OriginUV; 125 | float param_6 = NextIndex; 126 | float param_7 = divideX; 127 | vec2 param_8 = flipbookOneSize; 128 | vec2 param_9 = flipbookOffset; 129 | flipbookUV = GetFlipbookUVForIndex(param_5, param_6, param_7, param_8, param_9); 130 | flipbookUV.y = uvInversed.x + (uvInversed.y * flipbookUV.y); 131 | } 132 | } 133 | 134 | void CalculateAndStoreAdvancedParameter(vec2 uv, vec2 uv1, vec4 alphaUV, vec4 uvDistortionUV, vec4 blendUV, vec4 blendAlphaUV, vec4 blendUVDistortionUV, float flipbookIndexAndNextRate, float modelAlphaThreshold, inout VS_Output vsoutput) 135 | { 136 | vsoutput.Alpha_Dist_UV.x = (uv.x * alphaUV.z) + alphaUV.x; 137 | vsoutput.Alpha_Dist_UV.y = (uv.y * alphaUV.w) + alphaUV.y; 138 | vsoutput.Alpha_Dist_UV.z = (uv.x * uvDistortionUV.z) + uvDistortionUV.x; 139 | vsoutput.Alpha_Dist_UV.w = (uv.y * uvDistortionUV.w) + uvDistortionUV.y; 140 | vsoutput.Blend_FBNextIndex_UV.x = (uv.x * blendUV.z) + blendUV.x; 141 | vsoutput.Blend_FBNextIndex_UV.y = (uv.y * blendUV.w) + blendUV.y; 142 | vsoutput.Blend_Alpha_Dist_UV.x = (uv.x * blendAlphaUV.z) + blendAlphaUV.x; 143 | vsoutput.Blend_Alpha_Dist_UV.y = (uv.y * blendAlphaUV.w) + blendAlphaUV.y; 144 | vsoutput.Blend_Alpha_Dist_UV.z = (uv.x * blendUVDistortionUV.z) + blendUVDistortionUV.x; 145 | vsoutput.Blend_Alpha_Dist_UV.w = (uv.y * blendUVDistortionUV.w) + blendUVDistortionUV.y; 146 | float flipbookRate = 0.0; 147 | vec2 flipbookNextIndexUV = vec2_splat(0.0); 148 | float param = flipbookRate; 149 | vec2 param_1 = flipbookNextIndexUV; 150 | vec4 param_2 = u_flipbookParameter1; 151 | vec4 param_3 = u_flipbookParameter2; 152 | float param_4 = flipbookIndexAndNextRate; 153 | vec2 param_5 = uv1; 154 | vec2 param_6 = vec2_splat(u_mUVInversed.xy); 155 | ApplyFlipbookVS(param, param_1, param_2, param_3, param_4, param_5, param_6); 156 | flipbookRate = param; 157 | flipbookNextIndexUV = param_1; 158 | vsoutput.Blend_FBNextIndex_UV.z = flipbookNextIndexUV.x; 159 | vsoutput.Blend_FBNextIndex_UV.w = flipbookNextIndexUV.y; 160 | vsoutput.UV_Others.z = flipbookRate; 161 | vsoutput.UV_Others.w = modelAlphaThreshold; 162 | vsoutput.Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Alpha_Dist_UV.y); 163 | vsoutput.Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Alpha_Dist_UV.w); 164 | vsoutput.Blend_FBNextIndex_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_FBNextIndex_UV.y); 165 | vsoutput.Blend_Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_Alpha_Dist_UV.y); 166 | vsoutput.Blend_Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_Alpha_Dist_UV.w); 167 | } 168 | 169 | VS_Output _main(VS_Input Input) 170 | { 171 | uint index = Input.Index; 172 | mat4 mModel = u_mModel_Inst[index]; 173 | vec4 uv = u_fUV[index]; 174 | vec4 alphaUV = u_fAlphaUV[index]; 175 | vec4 uvDistortionUV = u_fUVDistortionUV[index]; 176 | vec4 blendUV = u_fBlendUV[index]; 177 | vec4 blendAlphaUV = u_fBlendAlphaUV[index]; 178 | vec4 blendUVDistortionUV = u_fBlendUVDistortionUV[index]; 179 | vec4 modelColor = u_fModelColor[index] * Input.Color; 180 | float flipbookIndexAndNextRate = u_fFlipbookIndexAndNextRate[index].x; 181 | float modelAlphaThreshold = u_fModelAlphaThreshold[index].x; 182 | VS_Output Output = (VS_Output)0; 183 | vec4 localPosition = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 184 | vec4 worldPos = mul(mModel, localPosition); 185 | Output.PosVS = mul(u_mCameraProj, worldPos); 186 | vec2 outputUV = Input.UV; 187 | outputUV.x = (outputUV.x * uv.z) + uv.x; 188 | outputUV.y = (outputUV.y * uv.w) + uv.y; 189 | outputUV.y = u_mUVInversed.x + (u_mUVInversed.y * outputUV.y); 190 | Output.UV_Others.x = outputUV.x; 191 | Output.UV_Others.y = outputUV.y; 192 | vec4 localNormal = vec4(Input.Normal.x, Input.Normal.y, Input.Normal.z, 0.0); 193 | vec4 localBinormal = vec4(Input.Binormal.x, Input.Binormal.y, Input.Binormal.z, 0.0); 194 | vec4 localTangent = vec4(Input.Tangent.x, Input.Tangent.y, Input.Tangent.z, 0.0); 195 | vec4 worldNormal = mul(mModel, localNormal); 196 | vec4 worldBinormal = mul(mModel, localBinormal); 197 | vec4 worldTangent = mul(mModel, localTangent); 198 | worldNormal = normalize(worldNormal); 199 | worldBinormal = normalize(worldBinormal); 200 | worldTangent = normalize(worldTangent); 201 | Output.WorldN = worldNormal.xyz; 202 | Output.WorldB = worldBinormal.xyz; 203 | Output.WorldT = worldTangent.xyz; 204 | Output.Color = modelColor; 205 | vec2 param = Input.UV; 206 | vec2 param_1 = Output.UV_Others.xy; 207 | vec4 param_2 = alphaUV; 208 | vec4 param_3 = uvDistortionUV; 209 | vec4 param_4 = blendUV; 210 | vec4 param_5 = blendAlphaUV; 211 | vec4 param_6 = blendUVDistortionUV; 212 | float param_7 = flipbookIndexAndNextRate; 213 | float param_8 = modelAlphaThreshold; 214 | VS_Output param_9 = Output; 215 | CalculateAndStoreAdvancedParameter(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7, param_8, param_9); 216 | Output = param_9; 217 | Output.PosP = Output.PosVS; 218 | return Output; 219 | } 220 | 221 | void main() 222 | { 223 | VS_Input Input; 224 | Input.Pos = a_position; 225 | Input.Normal = a_normal; 226 | Input.Binormal = a_bitangent; 227 | Input.Tangent = a_tangent; 228 | Input.UV = a_texcoord0; 229 | Input.Color = a_color0; 230 | Input.Index = uint(gl_InstanceIndex); 231 | VS_Output flattenTemp = _main(Input); 232 | vec4 _position = flattenTemp.PosVS; 233 | gl_Position = _position; 234 | v_Color = flattenTemp.Color; 235 | v_UV_Others = flattenTemp.UV_Others; 236 | v_WorldN = flattenTemp.WorldN; 237 | v_WorldB = flattenTemp.WorldB; 238 | v_WorldT = flattenTemp.WorldT; 239 | v_Alpha_Dist_UV = flattenTemp.Alpha_Dist_UV; 240 | v_Blend_Alpha_Dist_UV = flattenTemp.Blend_Alpha_Dist_UV; 241 | v_Blend_FBNextIndex_UV = flattenTemp.Blend_FBNextIndex_UV; 242 | v_PosP = flattenTemp.PosP; 243 | } 244 | -------------------------------------------------------------------------------- /shaders/ad_model_distortion_vs.fx.sc: -------------------------------------------------------------------------------- 1 | $input a_position a_normal a_bitangent a_tangent a_texcoord0 a_color0 2 | $output v_UV_Others v_ProjBinormal v_ProjTangent v_PosP v_Color v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV 3 | 4 | #include 5 | #include "defines.sh" 6 | uniform mat4 u_mCameraProj; 7 | uniform mat4 u_mModel_Inst[40]; 8 | uniform vec4 u_fUV[40]; 9 | uniform vec4 u_fAlphaUV[40]; 10 | uniform vec4 u_fUVDistortionUV[40]; 11 | uniform vec4 u_fBlendUV[40]; 12 | uniform vec4 u_fBlendAlphaUV[40]; 13 | uniform vec4 u_fBlendUVDistortionUV[40]; 14 | uniform vec4 u_flipbookParameter1; 15 | uniform vec4 u_flipbookParameter2; 16 | uniform vec4 u_fFlipbookIndexAndNextRate[40]; 17 | uniform vec4 u_fModelAlphaThreshold[40]; 18 | uniform vec4 u_fModelColor[40]; 19 | uniform vec4 u_fLightDirection; 20 | uniform vec4 u_fLightColor; 21 | uniform vec4 u_fLightAmbient; 22 | uniform vec4 u_mUVInversed; 23 | 24 | 25 | struct VS_Output 26 | { 27 | vec4 PosVS; 28 | vec4 UV_Others; 29 | vec4 ProjBinormal; 30 | vec4 ProjTangent; 31 | vec4 PosP; 32 | vec4 Color; 33 | vec4 Alpha_Dist_UV; 34 | vec4 Blend_Alpha_Dist_UV; 35 | vec4 Blend_FBNextIndex_UV; 36 | }; 37 | 38 | struct VS_Input 39 | { 40 | vec3 Pos; 41 | vec3 Normal; 42 | vec3 Binormal; 43 | vec3 Tangent; 44 | vec2 UV; 45 | vec4 Color; 46 | uint Index; 47 | }; 48 | 49 | vec2 GetFlipbookOriginUV(vec2 FlipbookUV, float FlipbookIndex, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 50 | { 51 | vec2 DivideIndex; 52 | DivideIndex.x = float(int(FlipbookIndex) % int(DivideX)); 53 | DivideIndex.y = float(int(FlipbookIndex) / int(DivideX)); 54 | vec2 UVOffset = (DivideIndex * flipbookOneSize) + flipbookOffset; 55 | return FlipbookUV - UVOffset; 56 | } 57 | 58 | vec2 GetFlipbookUVForIndex(vec2 OriginUV, float Index, float DivideX, vec2 flipbookOneSize, vec2 flipbookOffset) 59 | { 60 | vec2 DivideIndex; 61 | DivideIndex.x = float(int(Index) % int(DivideX)); 62 | DivideIndex.y = float(int(Index) / int(DivideX)); 63 | return (OriginUV + (DivideIndex * flipbookOneSize)) + flipbookOffset; 64 | } 65 | 66 | void ApplyFlipbookVS(inout float flipbookRate, inout vec2 flipbookUV, vec4 flipbookParameter1, vec4 flipbookParameter2, float flipbookIndex, vec2 uv, vec2 uvInversed) 67 | { 68 | float flipbookEnabled = flipbookParameter1.x; 69 | float flipbookLoopType = flipbookParameter1.y; 70 | float divideX = flipbookParameter1.z; 71 | float divideY = flipbookParameter1.w; 72 | vec2 flipbookOneSize = flipbookParameter2.xy; 73 | vec2 flipbookOffset = flipbookParameter2.zw; 74 | if (flipbookEnabled > 0.0) 75 | { 76 | flipbookRate = fract(flipbookIndex); 77 | float Index = floor(flipbookIndex); 78 | float IndexOffset = 1.0; 79 | float NextIndex = Index + IndexOffset; 80 | float FlipbookMaxCount = divideX * divideY; 81 | if (flipbookLoopType == 0.0) 82 | { 83 | if (NextIndex >= FlipbookMaxCount) 84 | { 85 | NextIndex = FlipbookMaxCount - 1.0; 86 | Index = FlipbookMaxCount - 1.0; 87 | } 88 | } 89 | else 90 | { 91 | if (flipbookLoopType == 1.0) 92 | { 93 | Index = mod(Index, FlipbookMaxCount); 94 | NextIndex = mod(NextIndex, FlipbookMaxCount); 95 | } 96 | else 97 | { 98 | if (flipbookLoopType == 2.0) 99 | { 100 | bool Reverse = mod(floor(Index / FlipbookMaxCount), 2.0) == 1.0; 101 | Index = mod(Index, FlipbookMaxCount); 102 | if (Reverse) 103 | { 104 | Index = (FlipbookMaxCount - 1.0) - floor(Index); 105 | } 106 | Reverse = mod(floor(NextIndex / FlipbookMaxCount), 2.0) == 1.0; 107 | NextIndex = mod(NextIndex, FlipbookMaxCount); 108 | if (Reverse) 109 | { 110 | NextIndex = (FlipbookMaxCount - 1.0) - floor(NextIndex); 111 | } 112 | } 113 | } 114 | } 115 | vec2 notInversedUV = uv; 116 | notInversedUV.y = uvInversed.x + (uvInversed.y * notInversedUV.y); 117 | vec2 param = notInversedUV; 118 | float param_1 = Index; 119 | float param_2 = divideX; 120 | vec2 param_3 = flipbookOneSize; 121 | vec2 param_4 = flipbookOffset; 122 | vec2 OriginUV = GetFlipbookOriginUV(param, param_1, param_2, param_3, param_4); 123 | vec2 param_5 = OriginUV; 124 | float param_6 = NextIndex; 125 | float param_7 = divideX; 126 | vec2 param_8 = flipbookOneSize; 127 | vec2 param_9 = flipbookOffset; 128 | flipbookUV = GetFlipbookUVForIndex(param_5, param_6, param_7, param_8, param_9); 129 | flipbookUV.y = uvInversed.x + (uvInversed.y * flipbookUV.y); 130 | } 131 | } 132 | 133 | void CalculateAndStoreAdvancedParameter(vec2 uv, vec2 uv1, vec4 alphaUV, vec4 uvDistortionUV, vec4 blendUV, vec4 blendAlphaUV, vec4 blendUVDistortionUV, float flipbookIndexAndNextRate, float modelAlphaThreshold, inout VS_Output vsoutput) 134 | { 135 | vsoutput.Alpha_Dist_UV.x = (uv.x * alphaUV.z) + alphaUV.x; 136 | vsoutput.Alpha_Dist_UV.y = (uv.y * alphaUV.w) + alphaUV.y; 137 | vsoutput.Alpha_Dist_UV.z = (uv.x * uvDistortionUV.z) + uvDistortionUV.x; 138 | vsoutput.Alpha_Dist_UV.w = (uv.y * uvDistortionUV.w) + uvDistortionUV.y; 139 | vsoutput.Blend_FBNextIndex_UV.x = (uv.x * blendUV.z) + blendUV.x; 140 | vsoutput.Blend_FBNextIndex_UV.y = (uv.y * blendUV.w) + blendUV.y; 141 | vsoutput.Blend_Alpha_Dist_UV.x = (uv.x * blendAlphaUV.z) + blendAlphaUV.x; 142 | vsoutput.Blend_Alpha_Dist_UV.y = (uv.y * blendAlphaUV.w) + blendAlphaUV.y; 143 | vsoutput.Blend_Alpha_Dist_UV.z = (uv.x * blendUVDistortionUV.z) + blendUVDistortionUV.x; 144 | vsoutput.Blend_Alpha_Dist_UV.w = (uv.y * blendUVDistortionUV.w) + blendUVDistortionUV.y; 145 | float flipbookRate = 0.0; 146 | vec2 flipbookNextIndexUV = vec2_splat(0.0); 147 | float param = flipbookRate; 148 | vec2 param_1 = flipbookNextIndexUV; 149 | vec4 param_2 = u_flipbookParameter1; 150 | vec4 param_3 = u_flipbookParameter2; 151 | float param_4 = flipbookIndexAndNextRate; 152 | vec2 param_5 = uv1; 153 | vec2 param_6 = vec2_splat(u_mUVInversed.xy); 154 | ApplyFlipbookVS(param, param_1, param_2, param_3, param_4, param_5, param_6); 155 | flipbookRate = param; 156 | flipbookNextIndexUV = param_1; 157 | vsoutput.Blend_FBNextIndex_UV.z = flipbookNextIndexUV.x; 158 | vsoutput.Blend_FBNextIndex_UV.w = flipbookNextIndexUV.y; 159 | vsoutput.UV_Others.z = flipbookRate; 160 | vsoutput.UV_Others.w = modelAlphaThreshold; 161 | vsoutput.Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Alpha_Dist_UV.y); 162 | vsoutput.Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Alpha_Dist_UV.w); 163 | vsoutput.Blend_FBNextIndex_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_FBNextIndex_UV.y); 164 | vsoutput.Blend_Alpha_Dist_UV.y = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_Alpha_Dist_UV.y); 165 | vsoutput.Blend_Alpha_Dist_UV.w = u_mUVInversed.x + (u_mUVInversed.y * vsoutput.Blend_Alpha_Dist_UV.w); 166 | } 167 | 168 | VS_Output _main(VS_Input Input) 169 | { 170 | uint index = Input.Index; 171 | mat4 mModel = u_mModel_Inst[index]; 172 | vec4 uv = u_fUV[index]; 173 | vec4 alphaUV = u_fAlphaUV[index]; 174 | vec4 uvDistortionUV = u_fUVDistortionUV[index]; 175 | vec4 blendUV = u_fBlendUV[index]; 176 | vec4 blendAlphaUV = u_fBlendAlphaUV[index]; 177 | vec4 blendUVDistortionUV = u_fBlendUVDistortionUV[index]; 178 | vec4 modelColor = u_fModelColor[index] * Input.Color; 179 | float flipbookIndexAndNextRate = u_fFlipbookIndexAndNextRate[index].x; 180 | float modelAlphaThreshold = u_fModelAlphaThreshold[index].x; 181 | VS_Output Output = (VS_Output)0; 182 | vec4 localPosition = vec4(Input.Pos.x, Input.Pos.y, Input.Pos.z, 1.0); 183 | vec4 worldPos = mul(mModel, localPosition); 184 | Output.PosVS = mul(u_mCameraProj, worldPos); 185 | vec2 outputUV = Input.UV; 186 | outputUV.x = (outputUV.x * uv.z) + uv.x; 187 | outputUV.y = (outputUV.y * uv.w) + uv.y; 188 | outputUV.y = u_mUVInversed.x + (u_mUVInversed.y * outputUV.y); 189 | Output.UV_Others.x = outputUV.x; 190 | Output.UV_Others.y = outputUV.y; 191 | vec4 localNormal = vec4(Input.Normal.x, Input.Normal.y, Input.Normal.z, 0.0); 192 | vec4 localBinormal = vec4(Input.Binormal.x, Input.Binormal.y, Input.Binormal.z, 0.0); 193 | vec4 localTangent = vec4(Input.Tangent.x, Input.Tangent.y, Input.Tangent.z, 0.0); 194 | vec4 worldNormal = mul(mModel, localNormal); 195 | vec4 worldBinormal = mul(mModel, localBinormal); 196 | vec4 worldTangent = mul(mModel, localTangent); 197 | worldNormal = normalize(worldNormal); 198 | worldBinormal = normalize(worldBinormal); 199 | worldTangent = normalize(worldTangent); 200 | Output.ProjTangent = mul(u_mCameraProj, (worldPos + worldTangent)); 201 | Output.ProjBinormal = mul(u_mCameraProj, (worldPos + worldBinormal)); 202 | Output.Color = modelColor; 203 | vec2 param = Input.UV; 204 | vec2 param_1 = Output.UV_Others.xy; 205 | vec4 param_2 = alphaUV; 206 | vec4 param_3 = uvDistortionUV; 207 | vec4 param_4 = blendUV; 208 | vec4 param_5 = blendAlphaUV; 209 | vec4 param_6 = blendUVDistortionUV; 210 | float param_7 = flipbookIndexAndNextRate; 211 | float param_8 = modelAlphaThreshold; 212 | VS_Output param_9 = Output; 213 | CalculateAndStoreAdvancedParameter(param, param_1, param_2, param_3, param_4, param_5, param_6, param_7, param_8, param_9); 214 | Output = param_9; 215 | Output.PosP = Output.PosVS; 216 | return Output; 217 | } 218 | 219 | void main() 220 | { 221 | VS_Input Input; 222 | Input.Pos = a_position; 223 | Input.Normal = a_normal; 224 | Input.Binormal = a_bitangent; 225 | Input.Tangent = a_tangent; 226 | Input.UV = a_texcoord0; 227 | Input.Color = a_color0; 228 | Input.Index = uint(gl_InstanceIndex); 229 | VS_Output flattenTemp = _main(Input); 230 | vec4 _position = flattenTemp.PosVS; 231 | gl_Position = _position; 232 | v_UV_Others = flattenTemp.UV_Others; 233 | v_ProjBinormal = flattenTemp.ProjBinormal; 234 | v_ProjTangent = flattenTemp.ProjTangent; 235 | v_PosP = flattenTemp.PosP; 236 | v_Color = flattenTemp.Color; 237 | v_Alpha_Dist_UV = flattenTemp.Alpha_Dist_UV; 238 | v_Blend_Alpha_Dist_UV = flattenTemp.Blend_Alpha_Dist_UV; 239 | v_Blend_FBNextIndex_UV = flattenTemp.Blend_FBNextIndex_UV; 240 | } 241 | -------------------------------------------------------------------------------- /shaders/ad_model_unlit_ps.fx.sc: -------------------------------------------------------------------------------- 1 | $input v_Color v_UV_Others v_WorldN v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV v_PosP 2 | 3 | #include 4 | #include "defines.sh" 5 | uniform vec4 u_fsfLightDirection; 6 | uniform vec4 u_fsfLightColor; 7 | uniform vec4 u_fsfLightAmbient; 8 | uniform vec4 u_fsfFlipbookParameter; 9 | uniform vec4 u_fsfUVDistortionParameter; 10 | uniform vec4 u_fsfBlendTextureParameter; 11 | uniform vec4 u_fsfCameraFrontDirection; 12 | uniform vec4 u_fsfFalloffParameter; 13 | uniform vec4 u_fsfFalloffBeginColor; 14 | uniform vec4 u_fsfFalloffEndColor; 15 | uniform vec4 u_fsfEmissiveScaling; 16 | uniform vec4 u_fsfEdgeColor; 17 | uniform vec4 u_fsfEdgeParameter; 18 | uniform vec4 u_fssoftParticleParam; 19 | uniform vec4 u_fsreconstructionParam1; 20 | uniform vec4 u_fsreconstructionParam2; 21 | uniform vec4 u_fsmUVInversedBack; 22 | uniform vec4 u_fsmiscFlags; 23 | SAMPLER2D (s_uvDistortionTex,2); 24 | SAMPLER2D (s_colorTex,0); 25 | SAMPLER2D (s_alphaTex,1); 26 | SAMPLER2D (s_blendUVDistortionTex,5); 27 | SAMPLER2D (s_blendTex,3); 28 | SAMPLER2D (s_blendAlphaTex,4); 29 | SAMPLER2D (s_depthTex,6); 30 | 31 | struct PS_Input 32 | { 33 | vec4 PosVS; 34 | vec4 Color; 35 | vec4 UV_Others; 36 | vec3 WorldN; 37 | vec4 Alpha_Dist_UV; 38 | vec4 Blend_Alpha_Dist_UV; 39 | vec4 Blend_FBNextIndex_UV; 40 | vec4 PosP; 41 | }; 42 | 43 | struct AdvancedParameter 44 | { 45 | vec2 AlphaUV; 46 | vec2 UVDistortionUV; 47 | vec2 BlendUV; 48 | vec2 BlendAlphaUV; 49 | vec2 BlendUVDistortionUV; 50 | vec2 FlipbookNextIndexUV; 51 | float FlipbookRate; 52 | float AlphaThreshold; 53 | }; 54 | 55 | AdvancedParameter DisolveAdvancedParameter(PS_Input psinput) 56 | { 57 | AdvancedParameter ret; 58 | ret.AlphaUV = psinput.Alpha_Dist_UV.xy; 59 | ret.UVDistortionUV = psinput.Alpha_Dist_UV.zw; 60 | ret.BlendUV = psinput.Blend_FBNextIndex_UV.xy; 61 | ret.BlendAlphaUV = psinput.Blend_Alpha_Dist_UV.xy; 62 | ret.BlendUVDistortionUV = psinput.Blend_Alpha_Dist_UV.zw; 63 | ret.FlipbookNextIndexUV = psinput.Blend_FBNextIndex_UV.zw; 64 | ret.FlipbookRate = psinput.UV_Others.z; 65 | ret.AlphaThreshold = psinput.UV_Others.w; 66 | return ret; 67 | } 68 | 69 | vec3 PositivePow(vec3 base, vec3 power) 70 | { 71 | return pow(max(abs(base), vec3_splat(1.1920928955078125e-07)), power); 72 | } 73 | 74 | vec3 LinearToSRGB(vec3 c) 75 | { 76 | vec3 param = c; 77 | vec3 param_1 = vec3_splat(0.4166666567325592041015625); 78 | return max((PositivePow(param, param_1) * 1.05499994754791259765625) - vec3_splat(0.054999999701976776123046875), vec3_splat(0.0)); 79 | } 80 | 81 | vec4 LinearToSRGB(vec4 c) 82 | { 83 | vec3 param = c.xyz; 84 | return vec4(LinearToSRGB(param), c.w); 85 | } 86 | 87 | vec4 ConvertFromSRGBTexture(vec4 c, bool isValid) 88 | { 89 | if (!isValid) 90 | { 91 | return c; 92 | } 93 | vec4 param = c; 94 | return LinearToSRGB(param); 95 | } 96 | 97 | vec2 UVDistortionOffset(vec2 uv, vec2 uvInversed, bool convertFromSRGB, struct BgfxSampler2D SPIRV_Cross_Combinedts) 98 | { 99 | vec4 sampledColor = texture2D(SPIRV_Cross_Combinedts, uv); 100 | if (convertFromSRGB) 101 | { 102 | vec4 param = sampledColor; 103 | bool param_1 = convertFromSRGB; 104 | sampledColor = ConvertFromSRGBTexture(param, param_1); 105 | } 106 | vec2 UVOffset = (sampledColor.xy * 2.0) - vec2_splat(1.0); 107 | UVOffset.y *= (-1.0); 108 | UVOffset.y = uvInversed.x + (uvInversed.y * UVOffset.y); 109 | return UVOffset; 110 | } 111 | 112 | void ApplyFlipbook(inout vec4 dst, vec4 flipbookParameter, vec4 vcolor, vec2 nextUV, float flipbookRate, bool convertFromSRGB, struct BgfxSampler2D SPIRV_Cross_Combinedts) 113 | { 114 | if (flipbookParameter.x > 0.0) 115 | { 116 | vec4 sampledColor = texture2D(SPIRV_Cross_Combinedts, nextUV); 117 | if (convertFromSRGB) 118 | { 119 | vec4 param = sampledColor; 120 | bool param_1 = convertFromSRGB; 121 | sampledColor = ConvertFromSRGBTexture(param, param_1); 122 | } 123 | vec4 NextPixelColor = sampledColor * vcolor; 124 | if (flipbookParameter.y == 1.0) 125 | { 126 | dst = mix(dst, NextPixelColor, vec4_splat(flipbookRate)); 127 | } 128 | } 129 | } 130 | 131 | void ApplyTextureBlending(inout vec4 dstColor, vec4 blendColor, float blendType) 132 | { 133 | if (blendType == 0.0) 134 | { 135 | vec4 _219 = dstColor; 136 | vec3 _222 = (blendColor.xyz * blendColor.w) + (_219.xyz * (1.0 - blendColor.w)); 137 | dstColor.x = _222.x; 138 | dstColor.y = _222.y; 139 | dstColor.z = _222.z; 140 | } 141 | else 142 | { 143 | if (blendType == 1.0) 144 | { 145 | vec4 _237 = dstColor; 146 | vec3 _239 = _237.xyz + (blendColor.xyz * blendColor.w); 147 | dstColor.x = _239.x; 148 | dstColor.y = _239.y; 149 | dstColor.z = _239.z; 150 | } 151 | else 152 | { 153 | if (blendType == 2.0) 154 | { 155 | vec4 _254 = dstColor; 156 | vec3 _256 = _254.xyz - (blendColor.xyz * blendColor.w); 157 | dstColor.x = _256.x; 158 | dstColor.y = _256.y; 159 | dstColor.z = _256.z; 160 | } 161 | else 162 | { 163 | if (blendType == 3.0) 164 | { 165 | vec4 _271 = dstColor; 166 | vec3 _273 = _271.xyz * (blendColor.xyz * blendColor.w); 167 | dstColor.x = _273.x; 168 | dstColor.y = _273.y; 169 | dstColor.z = _273.z; 170 | } 171 | } 172 | } 173 | } 174 | } 175 | 176 | float SoftParticle(float backgroundZ, float meshZ, vec4 softparticleParam, vec4 reconstruct1, vec4 reconstruct2) 177 | { 178 | float distanceFar = softparticleParam.x; 179 | float distanceNear = softparticleParam.y; 180 | float distanceNearOffset = softparticleParam.z; 181 | vec2 rescale = reconstruct1.xy; 182 | vec4 params = reconstruct2; 183 | vec2 zs = vec2((backgroundZ * rescale.x) + rescale.y, meshZ); 184 | vec2 depth = ((zs * params.w) - vec2_splat(params.y)) / (vec2_splat(params.x) - (zs * params.z)); 185 | float dir = sign(depth.x); 186 | depth *= dir; 187 | float alphaFar = (depth.x - depth.y) / distanceFar; 188 | float alphaNear = (depth.y - distanceNearOffset) / distanceNear; 189 | return min(max(min(alphaFar, alphaNear), 0.0), 1.0); 190 | } 191 | 192 | vec3 SRGBToLinear(vec3 c) 193 | { 194 | return min(c, c * ((c * ((c * 0.305306017398834228515625) + vec3_splat(0.6821711063385009765625))) + vec3_splat(0.01252287812530994415283203125))); 195 | } 196 | 197 | vec4 SRGBToLinear(vec4 c) 198 | { 199 | vec3 param = c.xyz; 200 | return vec4(SRGBToLinear(param), c.w); 201 | } 202 | 203 | vec4 ConvertToScreen(vec4 c, bool isValid) 204 | { 205 | if (!isValid) 206 | { 207 | return c; 208 | } 209 | vec4 param = c; 210 | return SRGBToLinear(param); 211 | } 212 | 213 | vec4 _main(PS_Input Input) 214 | { 215 | bool convertColorSpace = u_fsmiscFlags.x != 0.0; 216 | PS_Input param = Input; 217 | AdvancedParameter advancedParam = DisolveAdvancedParameter(param); 218 | vec2 param_1 = advancedParam.UVDistortionUV; 219 | vec2 param_2 = u_fsfUVDistortionParameter.zw; 220 | bool param_3 = convertColorSpace; 221 | vec2 UVOffset = UVDistortionOffset(param_1, param_2, param_3, s_uvDistortionTex); 222 | UVOffset *= u_fsfUVDistortionParameter.x; 223 | vec4 param_4 = texture2D(s_colorTex, Input.UV_Others.xy + UVOffset); 224 | bool param_5 = convertColorSpace; 225 | vec4 Output = ConvertFromSRGBTexture(param_4, param_5) * Input.Color; 226 | vec4 param_6 = Output; 227 | float param_7 = advancedParam.FlipbookRate; 228 | bool param_8 = convertColorSpace; 229 | ApplyFlipbook(param_6, u_fsfFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, param_7, param_8, s_colorTex); 230 | Output = param_6; 231 | vec4 param_9 = texture2D(s_alphaTex, advancedParam.AlphaUV + UVOffset); 232 | bool param_10 = convertColorSpace; 233 | vec4 AlphaTexColor = ConvertFromSRGBTexture(param_9, param_10); 234 | Output.w *= (AlphaTexColor.x * AlphaTexColor.w); 235 | vec2 param_11 = advancedParam.BlendUVDistortionUV; 236 | vec2 param_12 = u_fsfUVDistortionParameter.zw; 237 | bool param_13 = convertColorSpace; 238 | vec2 BlendUVOffset = UVDistortionOffset(param_11, param_12, param_13, s_blendUVDistortionTex); 239 | BlendUVOffset *= u_fsfUVDistortionParameter.y; 240 | vec4 param_14 = texture2D(s_blendTex, advancedParam.BlendUV + BlendUVOffset); 241 | bool param_15 = convertColorSpace; 242 | vec4 BlendTextureColor = ConvertFromSRGBTexture(param_14, param_15); 243 | vec4 param_16 = texture2D(s_blendAlphaTex, advancedParam.BlendAlphaUV + BlendUVOffset); 244 | bool param_17 = convertColorSpace; 245 | vec4 BlendAlphaTextureColor = ConvertFromSRGBTexture(param_16, param_17); 246 | BlendTextureColor.w *= (BlendAlphaTextureColor.x * BlendAlphaTextureColor.w); 247 | vec4 param_18 = Output; 248 | ApplyTextureBlending(param_18, BlendTextureColor, u_fsfBlendTextureParameter.x); 249 | Output = param_18; 250 | if (u_fsfFalloffParameter.x == 1.0) 251 | { 252 | vec3 cameraVec = normalize(-u_fsfCameraFrontDirection.xyz); 253 | float CdotN = clamp(dot(cameraVec, normalize(Input.WorldN)), 0.0, 1.0); 254 | vec4 FalloffBlendColor = mix(u_fsfFalloffEndColor, u_fsfFalloffBeginColor, vec4_splat(pow(CdotN, u_fsfFalloffParameter.z))); 255 | if (u_fsfFalloffParameter.y == 0.0) 256 | { 257 | vec4 _625 = Output; 258 | vec3 _627 = _625.xyz + FalloffBlendColor.xyz; 259 | Output.x = _627.x; 260 | Output.y = _627.y; 261 | Output.z = _627.z; 262 | } 263 | else 264 | { 265 | if (u_fsfFalloffParameter.y == 1.0) 266 | { 267 | vec4 _642 = Output; 268 | vec3 _644 = _642.xyz - FalloffBlendColor.xyz; 269 | Output.x = _644.x; 270 | Output.y = _644.y; 271 | Output.z = _644.z; 272 | } 273 | else 274 | { 275 | if (u_fsfFalloffParameter.y == 2.0) 276 | { 277 | vec4 _659 = Output; 278 | vec3 _661 = _659.xyz * FalloffBlendColor.xyz; 279 | Output.x = _661.x; 280 | Output.y = _661.y; 281 | Output.z = _661.z; 282 | } 283 | } 284 | } 285 | Output.w *= FalloffBlendColor.w; 286 | } 287 | vec4 _677 = Output; 288 | vec3 _679 = _677.xyz * u_fsfEmissiveScaling.x; 289 | Output.x = _679.x; 290 | Output.y = _679.y; 291 | Output.z = _679.z; 292 | vec4 screenPos = Input.PosP / vec4_splat(Input.PosP.w); 293 | vec2 screenUV = (screenPos.xy + vec2_splat(1.0)) / vec2_splat(2.0); 294 | screenUV.y = 1.0 - screenUV.y; 295 | screenUV.y = u_fsmUVInversedBack.x + (u_fsmUVInversedBack.y * screenUV.y); 296 | if (u_fssoftParticleParam.w != 0.0) 297 | { 298 | float backgroundZ = texture2D(s_depthTex, screenUV).x; 299 | float param_19 = backgroundZ; 300 | float param_20 = screenPos.z; 301 | vec4 param_21 = u_fssoftParticleParam; 302 | vec4 param_22 = u_fsreconstructionParam1; 303 | vec4 param_23 = u_fsreconstructionParam2; 304 | Output.w *= SoftParticle(param_19, param_20, param_21, param_22, param_23); 305 | } 306 | if (Output.w <= max(0.0, advancedParam.AlphaThreshold)) 307 | { 308 | discard; 309 | } 310 | vec4 _765 = Output; 311 | float _768 = Output.w; 312 | vec3 _777 = mix(u_fsfEdgeColor.xyz * u_fsfEdgeParameter.y, _765.xyz, vec3_splat(ceil((_768 - advancedParam.AlphaThreshold) - u_fsfEdgeParameter.x))); 313 | Output.x = _777.x; 314 | Output.y = _777.y; 315 | Output.z = _777.z; 316 | vec4 param_24 = Output; 317 | bool param_25 = convertColorSpace; 318 | return ConvertToScreen(param_24, param_25); 319 | } 320 | 321 | void main() 322 | { 323 | PS_Input Input; 324 | Input.PosVS = gl_FragCoord; 325 | #ifdef LINEAR_INPUT_COLOR 326 | Input.Color = to_linear(v_Color); 327 | #else 328 | Input.Color = v_Color; 329 | #endif //LINEAR_INPUT_COLOR 330 | 331 | Input.UV_Others = v_UV_Others; 332 | Input.WorldN = v_WorldN; 333 | Input.Alpha_Dist_UV = v_Alpha_Dist_UV; 334 | Input.Blend_Alpha_Dist_UV = v_Blend_Alpha_Dist_UV; 335 | Input.Blend_FBNextIndex_UV = v_Blend_FBNextIndex_UV; 336 | Input.PosP = v_PosP; 337 | vec4 _821 = _main(Input); 338 | gl_FragColor = _821; 339 | } 340 | -------------------------------------------------------------------------------- /efkmatc/genbgfxshader.lua: -------------------------------------------------------------------------------- 1 | local input = arg[1] 2 | local output = arg[2] 3 | local shadertype = arg[3] 4 | local stage = arg[4] 5 | local modeltype = arg[5] 6 | local cpath = arg[6] 7 | local plat = arg[7] 8 | 9 | plat = plat:lower() 10 | local plat_suffix = { 11 | macos = ".so", 12 | windows = ".dll", 13 | ios = ".so", 14 | } 15 | 16 | local suffix = plat_suffix[plat] 17 | if suffix == nil then 18 | error(("not support platform:"):format(plat or "")) 19 | end 20 | 21 | local function topath(p) 22 | return p .. "/?" .. suffix 23 | end 24 | package.cpath = table.concat({ 25 | topath(cpath), 26 | topath ".", 27 | topath "efkmatc", 28 | }, ";") 29 | 30 | local efkmat = require "efkmat" 31 | 32 | local ShaderType = { 33 | Unlit = 0, 34 | Lit = 1, 35 | BackDistortion = 2, 36 | AdvancedUnlit = 3, 37 | AdvancedLit = 4, 38 | AdvancedBackDistortion = 5, 39 | } 40 | 41 | local SlotIndeices = { 42 | color = { 0, 0, 0, 0, 0, 0}, 43 | back = { 1, 1, 1, 1, 1, 1}, 44 | normal = { 1, 1, 1, 1, 1, 1}, 45 | alpha = {-1, -1, -1, 1, 2, 2}, 46 | uvDistortion = {-1, -1, -1, 2, 3, 3}, 47 | blend = {-1, -1, -1, 3, 4, 4}, 48 | blendAlpha = {-1, -1, -1, 4, 5, 5}, 49 | blendUVDistortion = {-1, -1, -1, 5, 6, 6}, 50 | depth = { 1, 2, 2, 6, 7, 7}, 51 | } 52 | 53 | local function gen(filename) 54 | local line = { "" } 55 | for l in io.lines(filename) do 56 | if l:find "^##" then 57 | -- skip 58 | else 59 | if l:find "[^%s]" then 60 | table.insert(line, l ) 61 | end 62 | end 63 | end 64 | 65 | local source = table.concat(line , "\n") 66 | local shader = { 67 | struct = {}, 68 | layout = {}, 69 | uniform = {}, 70 | func = {}, 71 | texture = {}, 72 | } 73 | local valid_lines = {} 74 | -- struct name {}; 75 | for name, data in source:gmatch "\n(struct%s+[%w_]+%s*)\n(%b{};)" do 76 | table.insert(valid_lines, name) 77 | table.insert(valid_lines, data) 78 | 79 | local struct = { name = name:match "struct%s+([%w_]+)", data = data } 80 | for k,v in data:gmatch "\n%s+(%w+)%s+([%w_]+);" do 81 | table.insert(struct, { name = v, type = k }) 82 | end 83 | table.insert(shader.struct, struct) 84 | end 85 | -- layout(...) ... name; 86 | for layout in source:gmatch "\n(layout[^\n]+;)" do 87 | table.insert(valid_lines, layout) 88 | local attrib, type, name = layout:match "layout(%b())%s+(.+)%s+([%w_]+);$" 89 | if type == "uniform sampler2D" then 90 | local id = tonumber(attrib:match "binding%s*=%s*(%d+)") 91 | if id == nil then 92 | error(("Invalid layout:%s"):format(layout)) 93 | end 94 | assert(type == "uniform sampler2D") 95 | table.insert(shader.texture, { 96 | binding = id, 97 | name = name, 98 | }) 99 | else 100 | local id = tonumber(attrib:match "location%s*=%s*(%d+)") 101 | if id == nil then 102 | error(("Invalid layout:%s"):format(layout)) 103 | end 104 | local inout, t = type:match "(in) (%w+)" 105 | if inout == nil then 106 | inout, t = type:match "(out) (%w+)" 107 | end 108 | table.insert(shader.layout, { 109 | name = name, 110 | inout = inout, 111 | type = t, 112 | id = id, 113 | }) 114 | end 115 | end 116 | -- uniform 117 | for layout, data in source:gmatch "\n(layout.-)\n(%b{}%s+[%w_]+;)" do 118 | table.insert(valid_lines, layout) 119 | table.insert(valid_lines, data) 120 | local attrib, type = layout:match "layout(%b())%s+(.+)%s*$" 121 | local kv, name = data:match "(%b{})%s*([%w_]+);" 122 | local layout = { 123 | type = type, 124 | attrib = attrib, 125 | name = name, 126 | } 127 | for k,v in kv:gmatch "\n%s+(.-)%s+([%w_%[%]]+);" do 128 | k = k:match "[%w_]*$" 129 | local name, array = v:match "(.+)%[(%d+)%]" 130 | if name then 131 | array = tonumber(array) 132 | else 133 | name = v 134 | end 135 | table.insert(layout, { type = k, name = name, array = array }) 136 | end 137 | table.insert(shader.uniform, layout) 138 | end 139 | for func, data in source:gmatch "\n(%w+[^\n]-%b())\n(%b{})" do 140 | table.insert(valid_lines, func) 141 | table.insert(valid_lines, data) 142 | local funcname = func:match "[%w_]+ ([%w_]+)%s*%(" 143 | local t = { 144 | desc = func, 145 | imp = data, 146 | } 147 | table.insert(shader.func, t) 148 | shader.func[funcname] = t 149 | end 150 | 151 | local text = table.concat(valid_lines, "\n") 152 | 153 | -- check source 154 | for id, l in ipairs(line) do 155 | if l:sub(1,1) ~= "#" then 156 | if l:find "[^%s]" then 157 | if not text:find(l, 1, true) then 158 | error(string.format("%s : (%d) %s", filename, id, l)) 159 | end 160 | end 161 | end 162 | end 163 | 164 | return shader 165 | end 166 | 167 | local SPRITE_SEMANTIC = { 168 | POSITION0 = {"a_position", "POSITION"}, 169 | TEXCOORD0 = {"a_texcoord0", "TEXCOORD0"}, 170 | NORMAL0 = {"a_color0", "COLOR0"}, 171 | NORMAL1 = {"a_normal", "NORMAL"}, 172 | NORMAL2 = {"a_tangent", "TANGENT"}, 173 | TEXCOORD1 = {"a_texcoord1", "TEXCOORD1"}, 174 | TEXCOORD2 = {"a_texcoord2", "TEXCOORD2"}, 175 | TEXCOORD3 = {"a_texcoord3", "TEXCOORD3"}, 176 | TEXCOORD4 = {"a_texcoord4", "TEXCOORD4"}, 177 | TEXCOORD5 = {"a_texcoord5", "TEXCOORD5"}, 178 | TEXCOORD6 = {"a_texcoord6", "TEXCOORD6"}, 179 | } 180 | 181 | local MODEL_SEMANTIC = { 182 | POSITION0 = {"a_position", "POSITION"}, 183 | TEXCOORD0 = {"a_texcoord0", "TEXCOORD0"}, 184 | NORMAL0 = {"a_normal", "NORMAL"}, 185 | NORMAL1 = {"a_bitangent", "BITANGENT"}, 186 | NORMAL2 = {"a_tangent", "TANGENT"}, 187 | NORMAL3 = {"a_color0", "COLOR0"}, 188 | } 189 | 190 | local VAYRING_pat = "%s %s : %s;" 191 | 192 | local function load_vs_varying(s, shadertype, modeltype) 193 | local input, output = {}, {} 194 | local input_names, output_names = {}, {} 195 | local map = {} 196 | local layout = modeltype == "model" and efkmat.model_layout or efkmat.layout(ShaderType[shadertype]) 197 | local mapper = modeltype == "model" and MODEL_SEMANTIC or SPRITE_SEMANTIC 198 | 199 | for i, v in ipairs(s.layout) do 200 | local location = v.id + 1 201 | if v.inout == "in" then 202 | local shader_layout = layout[location] 203 | local m = mapper[shader_layout.SemanticName .. shader_layout.SemanticIndex] 204 | local name, type = m[1], m[2] 205 | map[v.name] = name 206 | input[location] = VAYRING_pat:format(v.type, name, type) 207 | input_names[location] = name 208 | else 209 | assert(v.inout == "out") 210 | local name = v.name:gsub("_entryPointOutput_", "v_") 211 | map[v.name] = name 212 | output[location] = VAYRING_pat:format(v.type, name, "TEXCOORD" .. v.id) 213 | output_names[location] = name 214 | end 215 | end 216 | 217 | return { 218 | file = table.concat(input, "\n") .. "\n" .. table.concat(output, "\n"), 219 | map = map, 220 | header = ("$input %s\n$output %s"):format( 221 | table.concat(input_names, " "), table.concat(output_names, " ")) 222 | } 223 | end 224 | 225 | local function load_fs_varying(s) 226 | local input_names = {} 227 | local map = {} 228 | for i, v in ipairs(s.layout) do 229 | local location = v.id + 1 230 | if v.inout == "in" then 231 | local sn = v.name:match "Input_([%w_]+)" 232 | local name = "v_" .. sn 233 | map[v.name] = name 234 | input_names[location] = name 235 | end 236 | end 237 | 238 | return { 239 | map = map, 240 | header = "$input " .. table.concat(input_names, " ") 241 | } 242 | end 243 | 244 | local function gen_varying(s, stagetype, shadertype, modeltype) 245 | if stagetype == "vs" then 246 | return load_vs_varying(s, shadertype, modeltype) 247 | end 248 | 249 | return load_fs_varying(s) 250 | end 251 | 252 | local function gen_uniform(s, stage) 253 | local uniform = {} 254 | local map = {} 255 | local u = s.uniform[1] 256 | for i,item in ipairs(u) do 257 | local uname = stage == "vs" and "u_" .. item.name or "u_fs" .. item.name 258 | if item.array then 259 | table.insert(uniform, string.format("uniform %s %s[%d];",item.type, uname, item.array)) 260 | else 261 | table.insert(uniform, string.format("uniform %s %s;",item.type, uname)) 262 | end 263 | map[u.name .. "." .. item.name] = uname 264 | end 265 | return { 266 | uniform = table.concat(uniform, "\n"), 267 | map = map, 268 | } 269 | end 270 | 271 | local function gen_texture(s, type) 272 | local shaderidx = 1 + ( ShaderType[type] or error (("Invalid type:%s"):format(type)) ) 273 | if shaderidx <= 0 or shaderidx > 6 then 274 | error "Invalid shader index, it should in range:[0, 5]" 275 | end 276 | local texture = {} 277 | local map = {} 278 | for i, item in ipairs(s.texture) do 279 | local name = item.name:match "_%w+$" 280 | local slotname = name:match "_(%w+)Tex" 281 | local indices = SlotIndeices[slotname] or error (("Invalid sampler name:%s"):format(name)) 282 | table.insert(texture, string.format("SAMPLER2D (s%s,%d);", name, indices[shaderidx])) 283 | item.new_name = "s" .. name 284 | map["texture("..item.name] = "texture2D("..item.new_name 285 | end 286 | return { 287 | texture = table.concat(texture, "\n"), 288 | map = map, 289 | } 290 | end 291 | 292 | local shader_temp=[[ 293 | $header 294 | 295 | #include 296 | #include "defines.sh" 297 | $uniform 298 | $texture 299 | 300 | $struct 301 | 302 | $source 303 | ]] 304 | 305 | local function genshader(fullname, stagetype, type, modeltype) 306 | local s = gen(fullname) 307 | local varying = gen_varying(s, stagetype, type, modeltype) 308 | local uniform = gen_uniform(s, stagetype) 309 | local texture = gen_texture(s, type) 310 | 311 | local func = s.func 312 | local main = func.main.imp:gsub("[%w_]+", varying.map) 313 | if stage == "fs" then 314 | main = main:gsub("([ %t]*)Input%.Color%s*=%s*([%w_]+)%s*;", [[ 315 | #ifdef LINEAR_INPUT_COLOR 316 | %1Input.Color = to_linear(%2); 317 | #else 318 | %1Input.Color = %2; 319 | #endif //LINEAR_INPUT_COLOR 320 | ]] 321 | ) 322 | end 323 | main = main:gsub("_entryPointOutput", "gl_FragColor") 324 | main = main:gsub("\n%s*_position.y%s*=%s*-_position.y;", "") 325 | func.main.imp = main 326 | 327 | for i, f in ipairs(func) do 328 | -- uniform 329 | f.imp = f.imp:gsub("[%w_]+", uniform.map) 330 | f.imp = f.imp:gsub("[%w_]+%.[%w_]+", uniform.map) 331 | 332 | --texture 333 | f.desc = f.desc:gsub("sampler2D", "struct BgfxSampler2D") 334 | f.imp = f.imp:gsub("texture%([%w_]+", function(m) 335 | local n = texture.map[m] 336 | if n then 337 | return n 338 | end 339 | 340 | local tn = m:match "%(([%w_]+)" 341 | if f.desc:match(tn) == nil then 342 | error(("texture name not match:%s"):format(m)) 343 | end 344 | return "texture2D(" .. tn 345 | end) 346 | 347 | for _, t in ipairs(s.texture) do 348 | f.imp = f.imp:gsub(t.name, t.new_name) 349 | end 350 | 351 | --shader dependent code 352 | do 353 | local tangentTransFmt = ("mat3(vec3(Input.WorldT),vec3(Input.WorldB),vec3(Input.WorldN))"):gsub("%(", "%%s*%%(") 354 | tangentTransFmt = tangentTransFmt:gsub("%)", "%%s*%%)") 355 | tangentTransFmt = tangentTransFmt:gsub(",", "%%s*,%%s*") 356 | tangentTransFmt = tangentTransFmt .. "%s*%*%s*([%w+_]+)" 357 | f.imp = f.imp:gsub(tangentTransFmt, "mul(mtxFromCols(Input.WorldT, Input.WorldB, Input.WorldN), %1)") 358 | end 359 | 360 | do 361 | local vec_pat = "vec([432])(%b())" 362 | local vec_handler 363 | vec_handler = function (m1, m2) 364 | m2 = m2:gsub(vec_pat, vec_handler) 365 | local pat = "vec%s_splat%s" 366 | -- for number, like: vec3(0.5e-7) or vec3(pow(x, 0.5)) 367 | if m2:match "^%([-%w_.]+%)$" or m2:match "^%([-%w_.]+%b()%)$" then 368 | return pat:format(m1, m2) 369 | end 370 | 371 | --check no function call and parameter more than 1 372 | if (not ((m2:match "[%w_]+%b()%s*,") or m2:match ",%s*[%w_]+%b()")) and (not m2:find ",") then 373 | return pat:format(m1, m2) 374 | end 375 | return ("vec%s%s"):format(m1, m2) 376 | end 377 | 378 | f.imp = f.imp:gsub(vec_pat, vec_handler) 379 | end 380 | 381 | f.imp = f.imp:gsub("(VS_Output%s+Output%s+=)%s*[^;]+;", "%1 (VS_Output)0;") 382 | 383 | do 384 | local pat1 = "([%w_.]+)" 385 | local pat2 = "(%b())" 386 | local mul = "%s*%*%s*" 387 | 388 | local function matrixmul(rv) 389 | local pats = { 390 | pat1 .. mul .. rv, 391 | pat2 .. mul .. rv, 392 | } 393 | 394 | for _, pat in ipairs(pats) do 395 | f.imp = f.imp:gsub(pat, ("mul(%s, %%1)"):format(rv)) 396 | end 397 | end 398 | 399 | matrixmul "u_mCameraProj" 400 | matrixmul "u_mCamera" 401 | matrixmul "mModel" 402 | end 403 | end 404 | 405 | local source = {} 406 | for i, v in ipairs(s.func) do 407 | source[i] = v.desc .. "\n" .. v.imp 408 | end 409 | local struct = {} 410 | for i,v in ipairs(s.struct) do 411 | struct[i] = string.format("struct %s\n%s", v.name, v.data) 412 | end 413 | 414 | return { 415 | source = shader_temp:gsub("$(%l+)", { 416 | header = varying.header, 417 | uniform = uniform.uniform, 418 | texture = texture.texture, 419 | struct = table.concat(struct, "\n\n"), 420 | source = table.concat(source, "\n\n"), 421 | }), 422 | varying = varying.file, 423 | } 424 | end 425 | 426 | local function writefile(filename, text) 427 | local f = assert(io.open(filename, "wb")) 428 | f:write(text) 429 | f:close() 430 | end 431 | 432 | local r = genshader(input, stage, shadertype, modeltype) 433 | if r.varying then 434 | local ppath = output:match "(.+[/\\]).+$" 435 | local outputVaryingFile = ("%s/%s_%s_varying.def.sc"):format(ppath, modeltype, shadertype) 436 | writefile(outputVaryingFile, r.varying) 437 | end 438 | 439 | writefile(output, r.source) 440 | 441 | -------------------------------------------------------------------------------- /shaders/ad_model_lit_ps.fx.sc: -------------------------------------------------------------------------------- 1 | $input v_Color v_UV_Others v_WorldN v_WorldB v_WorldT v_Alpha_Dist_UV v_Blend_Alpha_Dist_UV v_Blend_FBNextIndex_UV v_PosP 2 | 3 | #include 4 | #include "defines.sh" 5 | uniform vec4 u_fsfLightDirection; 6 | uniform vec4 u_fsfLightColor; 7 | uniform vec4 u_fsfLightAmbient; 8 | uniform vec4 u_fsfFlipbookParameter; 9 | uniform vec4 u_fsfUVDistortionParameter; 10 | uniform vec4 u_fsfBlendTextureParameter; 11 | uniform vec4 u_fsfCameraFrontDirection; 12 | uniform vec4 u_fsfFalloffParameter; 13 | uniform vec4 u_fsfFalloffBeginColor; 14 | uniform vec4 u_fsfFalloffEndColor; 15 | uniform vec4 u_fsfEmissiveScaling; 16 | uniform vec4 u_fsfEdgeColor; 17 | uniform vec4 u_fsfEdgeParameter; 18 | uniform vec4 u_fssoftParticleParam; 19 | uniform vec4 u_fsreconstructionParam1; 20 | uniform vec4 u_fsreconstructionParam2; 21 | uniform vec4 u_fsmUVInversedBack; 22 | uniform vec4 u_fsmiscFlags; 23 | SAMPLER2D (s_uvDistortionTex,3); 24 | SAMPLER2D (s_colorTex,0); 25 | SAMPLER2D (s_normalTex,1); 26 | SAMPLER2D (s_alphaTex,2); 27 | SAMPLER2D (s_blendUVDistortionTex,6); 28 | SAMPLER2D (s_blendTex,4); 29 | SAMPLER2D (s_blendAlphaTex,5); 30 | SAMPLER2D (s_depthTex,7); 31 | 32 | struct PS_Input 33 | { 34 | vec4 PosVS; 35 | vec4 Color; 36 | vec4 UV_Others; 37 | vec3 WorldN; 38 | vec3 WorldB; 39 | vec3 WorldT; 40 | vec4 Alpha_Dist_UV; 41 | vec4 Blend_Alpha_Dist_UV; 42 | vec4 Blend_FBNextIndex_UV; 43 | vec4 PosP; 44 | }; 45 | 46 | struct AdvancedParameter 47 | { 48 | vec2 AlphaUV; 49 | vec2 UVDistortionUV; 50 | vec2 BlendUV; 51 | vec2 BlendAlphaUV; 52 | vec2 BlendUVDistortionUV; 53 | vec2 FlipbookNextIndexUV; 54 | float FlipbookRate; 55 | float AlphaThreshold; 56 | }; 57 | 58 | AdvancedParameter DisolveAdvancedParameter(PS_Input psinput) 59 | { 60 | AdvancedParameter ret; 61 | ret.AlphaUV = psinput.Alpha_Dist_UV.xy; 62 | ret.UVDistortionUV = psinput.Alpha_Dist_UV.zw; 63 | ret.BlendUV = psinput.Blend_FBNextIndex_UV.xy; 64 | ret.BlendAlphaUV = psinput.Blend_Alpha_Dist_UV.xy; 65 | ret.BlendUVDistortionUV = psinput.Blend_Alpha_Dist_UV.zw; 66 | ret.FlipbookNextIndexUV = psinput.Blend_FBNextIndex_UV.zw; 67 | ret.FlipbookRate = psinput.UV_Others.z; 68 | ret.AlphaThreshold = psinput.UV_Others.w; 69 | return ret; 70 | } 71 | 72 | vec3 PositivePow(vec3 base, vec3 power) 73 | { 74 | return pow(max(abs(base), vec3_splat(1.1920928955078125e-07)), power); 75 | } 76 | 77 | vec3 LinearToSRGB(vec3 c) 78 | { 79 | vec3 param = c; 80 | vec3 param_1 = vec3_splat(0.4166666567325592041015625); 81 | return max((PositivePow(param, param_1) * 1.05499994754791259765625) - vec3_splat(0.054999999701976776123046875), vec3_splat(0.0)); 82 | } 83 | 84 | vec4 LinearToSRGB(vec4 c) 85 | { 86 | vec3 param = c.xyz; 87 | return vec4(LinearToSRGB(param), c.w); 88 | } 89 | 90 | vec4 ConvertFromSRGBTexture(vec4 c, bool isValid) 91 | { 92 | if (!isValid) 93 | { 94 | return c; 95 | } 96 | vec4 param = c; 97 | return LinearToSRGB(param); 98 | } 99 | 100 | vec2 UVDistortionOffset(vec2 uv, vec2 uvInversed, bool convertFromSRGB, struct BgfxSampler2D SPIRV_Cross_Combinedts) 101 | { 102 | vec4 sampledColor = texture2D(SPIRV_Cross_Combinedts, uv); 103 | if (convertFromSRGB) 104 | { 105 | vec4 param = sampledColor; 106 | bool param_1 = convertFromSRGB; 107 | sampledColor = ConvertFromSRGBTexture(param, param_1); 108 | } 109 | vec2 UVOffset = (sampledColor.xy * 2.0) - vec2_splat(1.0); 110 | UVOffset.y *= (-1.0); 111 | UVOffset.y = uvInversed.x + (uvInversed.y * UVOffset.y); 112 | return UVOffset; 113 | } 114 | 115 | void ApplyFlipbook(inout vec4 dst, vec4 flipbookParameter, vec4 vcolor, vec2 nextUV, float flipbookRate, bool convertFromSRGB, struct BgfxSampler2D SPIRV_Cross_Combinedts) 116 | { 117 | if (flipbookParameter.x > 0.0) 118 | { 119 | vec4 sampledColor = texture2D(SPIRV_Cross_Combinedts, nextUV); 120 | if (convertFromSRGB) 121 | { 122 | vec4 param = sampledColor; 123 | bool param_1 = convertFromSRGB; 124 | sampledColor = ConvertFromSRGBTexture(param, param_1); 125 | } 126 | vec4 NextPixelColor = sampledColor * vcolor; 127 | if (flipbookParameter.y == 1.0) 128 | { 129 | dst = mix(dst, NextPixelColor, vec4_splat(flipbookRate)); 130 | } 131 | } 132 | } 133 | 134 | void ApplyTextureBlending(inout vec4 dstColor, vec4 blendColor, float blendType) 135 | { 136 | if (blendType == 0.0) 137 | { 138 | vec4 _219 = dstColor; 139 | vec3 _222 = (blendColor.xyz * blendColor.w) + (_219.xyz * (1.0 - blendColor.w)); 140 | dstColor.x = _222.x; 141 | dstColor.y = _222.y; 142 | dstColor.z = _222.z; 143 | } 144 | else 145 | { 146 | if (blendType == 1.0) 147 | { 148 | vec4 _237 = dstColor; 149 | vec3 _239 = _237.xyz + (blendColor.xyz * blendColor.w); 150 | dstColor.x = _239.x; 151 | dstColor.y = _239.y; 152 | dstColor.z = _239.z; 153 | } 154 | else 155 | { 156 | if (blendType == 2.0) 157 | { 158 | vec4 _254 = dstColor; 159 | vec3 _256 = _254.xyz - (blendColor.xyz * blendColor.w); 160 | dstColor.x = _256.x; 161 | dstColor.y = _256.y; 162 | dstColor.z = _256.z; 163 | } 164 | else 165 | { 166 | if (blendType == 3.0) 167 | { 168 | vec4 _271 = dstColor; 169 | vec3 _273 = _271.xyz * (blendColor.xyz * blendColor.w); 170 | dstColor.x = _273.x; 171 | dstColor.y = _273.y; 172 | dstColor.z = _273.z; 173 | } 174 | } 175 | } 176 | } 177 | } 178 | 179 | float SoftParticle(float backgroundZ, float meshZ, vec4 softparticleParam, vec4 reconstruct1, vec4 reconstruct2) 180 | { 181 | float distanceFar = softparticleParam.x; 182 | float distanceNear = softparticleParam.y; 183 | float distanceNearOffset = softparticleParam.z; 184 | vec2 rescale = reconstruct1.xy; 185 | vec4 params = reconstruct2; 186 | vec2 zs = vec2((backgroundZ * rescale.x) + rescale.y, meshZ); 187 | vec2 depth = ((zs * params.w) - vec2_splat(params.y)) / (vec2_splat(params.x) - (zs * params.z)); 188 | float dir = sign(depth.x); 189 | depth *= dir; 190 | float alphaFar = (depth.x - depth.y) / distanceFar; 191 | float alphaNear = (depth.y - distanceNearOffset) / distanceNear; 192 | return min(max(min(alphaFar, alphaNear), 0.0), 1.0); 193 | } 194 | 195 | vec3 SRGBToLinear(vec3 c) 196 | { 197 | return min(c, c * ((c * ((c * 0.305306017398834228515625) + vec3_splat(0.6821711063385009765625))) + vec3_splat(0.01252287812530994415283203125))); 198 | } 199 | 200 | vec4 SRGBToLinear(vec4 c) 201 | { 202 | vec3 param = c.xyz; 203 | return vec4(SRGBToLinear(param), c.w); 204 | } 205 | 206 | vec4 ConvertToScreen(vec4 c, bool isValid) 207 | { 208 | if (!isValid) 209 | { 210 | return c; 211 | } 212 | vec4 param = c; 213 | return SRGBToLinear(param); 214 | } 215 | 216 | vec4 _main(PS_Input Input) 217 | { 218 | bool convertColorSpace = u_fsmiscFlags.x != 0.0; 219 | PS_Input param = Input; 220 | AdvancedParameter advancedParam = DisolveAdvancedParameter(param); 221 | vec2 param_1 = advancedParam.UVDistortionUV; 222 | vec2 param_2 = u_fsfUVDistortionParameter.zw; 223 | bool param_3 = convertColorSpace; 224 | vec2 UVOffset = UVDistortionOffset(param_1, param_2, param_3, s_uvDistortionTex); 225 | UVOffset *= u_fsfUVDistortionParameter.x; 226 | vec4 param_4 = texture2D(s_colorTex, Input.UV_Others.xy + UVOffset); 227 | bool param_5 = convertColorSpace; 228 | vec4 Output = ConvertFromSRGBTexture(param_4, param_5) * Input.Color; 229 | vec3 texNormal = (texture2D(s_normalTex, Input.UV_Others.xy + UVOffset).xyz - vec3_splat(0.5)) * 2.0; 230 | vec3 localNormal = normalize(mul(mtxFromCols(Input.WorldT, Input.WorldB, Input.WorldN), texNormal)); 231 | vec4 param_6 = Output; 232 | float param_7 = advancedParam.FlipbookRate; 233 | bool param_8 = convertColorSpace; 234 | ApplyFlipbook(param_6, u_fsfFlipbookParameter, Input.Color, advancedParam.FlipbookNextIndexUV + UVOffset, param_7, param_8, s_colorTex); 235 | Output = param_6; 236 | vec4 param_9 = texture2D(s_alphaTex, advancedParam.AlphaUV + UVOffset); 237 | bool param_10 = convertColorSpace; 238 | vec4 AlphaTexColor = ConvertFromSRGBTexture(param_9, param_10); 239 | Output.w *= (AlphaTexColor.x * AlphaTexColor.w); 240 | vec2 param_11 = advancedParam.BlendUVDistortionUV; 241 | vec2 param_12 = u_fsfUVDistortionParameter.zw; 242 | bool param_13 = convertColorSpace; 243 | vec2 BlendUVOffset = UVDistortionOffset(param_11, param_12, param_13, s_blendUVDistortionTex); 244 | BlendUVOffset *= u_fsfUVDistortionParameter.y; 245 | vec4 param_14 = texture2D(s_blendTex, advancedParam.BlendUV + BlendUVOffset); 246 | bool param_15 = convertColorSpace; 247 | vec4 BlendTextureColor = ConvertFromSRGBTexture(param_14, param_15); 248 | vec4 param_16 = texture2D(s_blendAlphaTex, advancedParam.BlendAlphaUV + BlendUVOffset); 249 | bool param_17 = convertColorSpace; 250 | vec4 BlendAlphaTextureColor = ConvertFromSRGBTexture(param_16, param_17); 251 | BlendTextureColor.w *= (BlendAlphaTextureColor.x * BlendAlphaTextureColor.w); 252 | vec4 param_18 = Output; 253 | ApplyTextureBlending(param_18, BlendTextureColor, u_fsfBlendTextureParameter.x); 254 | Output = param_18; 255 | float diffuse = max(dot(u_fsfLightDirection.xyz, localNormal), 0.0); 256 | vec4 _633 = Output; 257 | vec3 _644 = _633.xyz * ((u_fsfLightColor.xyz * diffuse) + u_fsfLightAmbient.xyz); 258 | Output.x = _644.x; 259 | Output.y = _644.y; 260 | Output.z = _644.z; 261 | if (u_fsfFalloffParameter.x == 1.0) 262 | { 263 | vec3 cameraVec = normalize(-u_fsfCameraFrontDirection.xyz); 264 | float CdotN = clamp(dot(cameraVec, vec3(localNormal.x, localNormal.y, localNormal.z)), 0.0, 1.0); 265 | vec4 FalloffBlendColor = mix(u_fsfFalloffEndColor, u_fsfFalloffBeginColor, vec4_splat(pow(CdotN, u_fsfFalloffParameter.z))); 266 | if (u_fsfFalloffParameter.y == 0.0) 267 | { 268 | vec4 _692 = Output; 269 | vec3 _694 = _692.xyz + FalloffBlendColor.xyz; 270 | Output.x = _694.x; 271 | Output.y = _694.y; 272 | Output.z = _694.z; 273 | } 274 | else 275 | { 276 | if (u_fsfFalloffParameter.y == 1.0) 277 | { 278 | vec4 _709 = Output; 279 | vec3 _711 = _709.xyz - FalloffBlendColor.xyz; 280 | Output.x = _711.x; 281 | Output.y = _711.y; 282 | Output.z = _711.z; 283 | } 284 | else 285 | { 286 | if (u_fsfFalloffParameter.y == 2.0) 287 | { 288 | vec4 _726 = Output; 289 | vec3 _728 = _726.xyz * FalloffBlendColor.xyz; 290 | Output.x = _728.x; 291 | Output.y = _728.y; 292 | Output.z = _728.z; 293 | } 294 | } 295 | } 296 | Output.w *= FalloffBlendColor.w; 297 | } 298 | vec4 _744 = Output; 299 | vec3 _746 = _744.xyz * u_fsfEmissiveScaling.x; 300 | Output.x = _746.x; 301 | Output.y = _746.y; 302 | Output.z = _746.z; 303 | vec4 screenPos = Input.PosP / vec4_splat(Input.PosP.w); 304 | vec2 screenUV = (screenPos.xy + vec2_splat(1.0)) / vec2_splat(2.0); 305 | screenUV.y = 1.0 - screenUV.y; 306 | screenUV.y = u_fsmUVInversedBack.x + (u_fsmUVInversedBack.y * screenUV.y); 307 | if (u_fssoftParticleParam.w != 0.0) 308 | { 309 | float backgroundZ = texture2D(s_depthTex, screenUV).x; 310 | float param_19 = backgroundZ; 311 | float param_20 = screenPos.z; 312 | vec4 param_21 = u_fssoftParticleParam; 313 | vec4 param_22 = u_fsreconstructionParam1; 314 | vec4 param_23 = u_fsreconstructionParam2; 315 | Output.w *= SoftParticle(param_19, param_20, param_21, param_22, param_23); 316 | } 317 | if (Output.w <= max(0.0, advancedParam.AlphaThreshold)) 318 | { 319 | discard; 320 | } 321 | vec4 _832 = Output; 322 | float _835 = Output.w; 323 | vec3 _844 = mix(u_fsfEdgeColor.xyz * u_fsfEdgeParameter.y, _832.xyz, vec3_splat(ceil((_835 - advancedParam.AlphaThreshold) - u_fsfEdgeParameter.x))); 324 | Output.x = _844.x; 325 | Output.y = _844.y; 326 | Output.z = _844.z; 327 | vec4 param_24 = Output; 328 | bool param_25 = convertColorSpace; 329 | return ConvertToScreen(param_24, param_25); 330 | } 331 | 332 | void main() 333 | { 334 | PS_Input Input; 335 | Input.PosVS = gl_FragCoord; 336 | #ifdef LINEAR_INPUT_COLOR 337 | Input.Color = to_linear(v_Color); 338 | #else 339 | Input.Color = v_Color; 340 | #endif //LINEAR_INPUT_COLOR 341 | 342 | Input.UV_Others = v_UV_Others; 343 | Input.WorldN = v_WorldN; 344 | Input.WorldB = v_WorldB; 345 | Input.WorldT = v_WorldT; 346 | Input.Alpha_Dist_UV = v_Alpha_Dist_UV; 347 | Input.Blend_Alpha_Dist_UV = v_Blend_Alpha_Dist_UV; 348 | Input.Blend_FBNextIndex_UV = v_Blend_FBNextIndex_UV; 349 | Input.PosP = v_PosP; 350 | vec4 _894 = _main(Input); 351 | gl_FragColor = _894; 352 | } 353 | -------------------------------------------------------------------------------- /examples/example.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2022 Branimir Karadzic. All rights reserved. 3 | * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "renderer/bgfxrenderer.h" 18 | 19 | static const bgfx::ViewId g_sceneViewId = 0; 20 | static const bgfx::ViewId g_defaultViewId = 1; 21 | 22 | #include 23 | namespace 24 | { 25 | 26 | class EffekseerBgfxTest : public entry::AppI 27 | { 28 | public: 29 | EffekseerBgfxTest(const char* _name, const char* _description, const char* _url) 30 | : entry::AppI(_name, _description, _url) 31 | { 32 | } 33 | 34 | void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override 35 | { 36 | Args args(_argc, _argv); 37 | 38 | m_width = _width; 39 | m_height = _height; 40 | m_debug = BGFX_DEBUG_TEXT; 41 | m_reset = BGFX_RESET_VSYNC; 42 | 43 | bgfx::Init init; 44 | init.type = args.m_type; 45 | init.vendorId = args.m_pciId; 46 | init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle); 47 | init.platformData.ndt = entry::getNativeDisplayHandle(); 48 | init.resolution.width = m_width; 49 | init.resolution.height = m_height; 50 | init.resolution.reset = m_reset; 51 | bgfx::init(init); 52 | 53 | bgfx::setViewMode(g_sceneViewId, bgfx::ViewMode::Sequential); 54 | bgfx::setViewMode(g_defaultViewId, bgfx::ViewMode::Sequential); 55 | 56 | auto inter = bgfx_get_interface(BGFX_API_VERSION); 57 | const bool invz = false; 58 | EffekseerRendererBGFX::InitArgs efkArgs { 59 | 2048, g_defaultViewId, inter, 60 | EffekseerBgfxTest::ShaderLoad, 61 | EffekseerBgfxTest::TextureGet, 62 | EffekseerBgfxTest::TextureLoad, 63 | EffekseerBgfxTest::TextureUnload, 64 | EffekseerBgfxTest::TextureHandle, 65 | this, 66 | invz, 67 | }; 68 | 69 | initFullScreen(); 70 | initCube(); 71 | 72 | m_efkRenderer = EffekseerRendererBGFX::CreateRenderer(&efkArgs); 73 | m_efkManager = Effekseer::Manager::Create(8000); 74 | m_efkManager->GetSetting()->SetCoordinateSystem(Effekseer::CoordinateSystem::LH); 75 | 76 | m_efkManager->SetModelRenderer(CreateModelRenderer(m_efkRenderer, &efkArgs)); 77 | m_efkManager->SetSpriteRenderer(m_efkRenderer->CreateSpriteRenderer()); 78 | m_efkManager->SetRibbonRenderer(m_efkRenderer->CreateRibbonRenderer()); 79 | m_efkManager->SetRingRenderer(m_efkRenderer->CreateRingRenderer()); 80 | m_efkManager->SetTrackRenderer(m_efkRenderer->CreateTrackRenderer()); 81 | m_efkManager->SetTextureLoader(m_efkRenderer->CreateTextureLoader()); 82 | m_efkManager->SetModelLoader(m_efkRenderer->CreateModelLoader()); 83 | m_efkManager->SetMaterialLoader(m_efkRenderer->CreateMaterialLoader()); 84 | m_efkManager->SetCurveLoader(Effekseer::MakeRefPtr()); 85 | 86 | m_projMat.PerspectiveFovLH( 87 | bx::toRad(90.0f), m_width/float(m_height), 1.0f, 500.0f); 88 | m_efkRenderer->SetProjectionMatrix(m_projMat); 89 | m_viewMat.LookAtLH(Effekseer::Vector3D(0.0f, 0.0f, 40.0f), Effekseer::Vector3D(0.0f, 0.0f, 0.0f), Effekseer::Vector3D(0.0f, 1.0f, 0.0f)); 90 | m_efkRenderer->SetCameraMatrix(m_viewMat); 91 | 92 | //m_efkEffect = Effekseer::Effect::Create(m_efkManager, u"./resources/Simple_Model_UV.efkefc"); 93 | //m_efkEffect = Effekseer::Effect::Create(m_efkManager, u"./resources/Laser01.efk"); 94 | 95 | // for (int ii=0; ii<4; ++ii){ 96 | // auto eff = Effekseer::Effect::Create(m_efkManager, u"./resources/sword_lightning.efkefc"); 97 | // m_efkManager->Play(eff, ii*5.f, 0, 0); 98 | // } 99 | 100 | auto eff = Effekseer::Effect::Create(m_efkManager, u"./resources/Simple_Model_UV.efkefc"); 101 | m_efkHandle = m_efkManager->Play(eff, 5.f, 0.f, 0.f); 102 | 103 | // Enable debug text. 104 | bgfx::setDebug(m_debug); 105 | 106 | // Set view 0 clear state. 107 | bgfx::setViewClear(g_defaultViewId 108 | , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH 109 | , 0x303030ff 110 | , 1.0f 111 | , 0 112 | ); 113 | } 114 | 115 | virtual int shutdown() override 116 | { 117 | m_efkManager = nullptr; 118 | m_efkRenderer = nullptr; 119 | // Shutdown bgfx. 120 | bgfx::shutdown(); 121 | 122 | return 0; 123 | } 124 | 125 | bool update() override 126 | { 127 | if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) ) 128 | { 129 | if (inputGetKeyState(entry::Key::Up)) 130 | { 131 | m_efkManager->SetRotation(m_efkHandle, 0.0, 0.0, bx::kPi * 0.1f); 132 | } 133 | else if (inputGetKeyState(entry::Key::Down)) 134 | { 135 | m_efkManager->SetRotation(m_efkHandle, 0.0, 0.0, -bx::kPi * 0.1f); 136 | } 137 | else if (inputGetKeyState(entry::Key::Left)) 138 | { 139 | m_efkManager->AddLocation(m_efkHandle, Effekseer::Vector3D(-0.2f, 0.0f, 0.0f)); 140 | } 141 | else if (inputGetKeyState(entry::Key::Right)) 142 | { 143 | m_efkManager->AddLocation(m_efkHandle, Effekseer::Vector3D(0.2f, 0.0f, 0.0f)); 144 | } 145 | 146 | // Set view 0 default viewport. 147 | bgfx::setViewRect(g_defaultViewId, 0, 0, uint16_t(m_width), uint16_t(m_height) ); 148 | m_efkManager->Update(); 149 | 150 | drawCube(g_sceneViewId); 151 | drawFullScreen(g_defaultViewId); 152 | 153 | bgfx::setViewTransform(g_defaultViewId, m_viewMat.Values, m_projMat.Values); 154 | //m_efkRenderer->SetTime(s_time / 60.0f); 155 | m_efkRenderer->BeginRendering(); 156 | 157 | Effekseer::Manager::DrawParameter drawParameter; 158 | drawParameter.ZNear = 0.0f; 159 | drawParameter.ZFar = 1.0f; 160 | drawParameter.ViewProjectionMatrix = m_efkRenderer->GetCameraProjectionMatrix(); 161 | m_efkManager->Draw(drawParameter); 162 | 163 | m_efkRenderer->EndRendering(); 164 | bgfx::frame(); 165 | return true; 166 | } 167 | 168 | return false; 169 | } 170 | 171 | entry::MouseState m_mouseState; 172 | 173 | uint32_t m_width; 174 | uint32_t m_height; 175 | uint32_t m_debug; 176 | uint32_t m_reset; 177 | 178 | private: 179 | void 180 | initCube(){ 181 | struct PosColorVertex 182 | { 183 | float m_x; 184 | float m_y; 185 | float m_z; 186 | uint32_t m_abgr; 187 | }; 188 | const float len = 5.f; 189 | static const PosColorVertex s_vertices[] = 190 | { 191 | {-len, len, len, 0xff000000 }, 192 | { len, len, len, 0xff0000ff }, 193 | {-len, -len, len, 0xff00ff00 }, 194 | { len, -len, len, 0xff00ffff }, 195 | {-len, len, -len, 0xffff0000 }, 196 | { len, len, -len, 0xffff00ff }, 197 | {-len, -len, -len, 0xffffff00 }, 198 | { len, -len, -len, 0xffffffff }, 199 | }; 200 | 201 | static const uint16_t s_indices[] = 202 | { 203 | 0, 1, 2, // 0 204 | 1, 3, 2, 205 | 4, 6, 5, // 2 206 | 5, 6, 7, 207 | 0, 2, 4, // 4 208 | 4, 2, 6, 209 | 1, 5, 3, // 6 210 | 5, 7, 3, 211 | 0, 4, 1, // 8 212 | 4, 5, 1, 213 | 2, 3, 6, // 10 214 | 6, 3, 7, 215 | }; 216 | 217 | m_cubeLayout 218 | .begin() 219 | .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float) 220 | .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true) 221 | .end(); 222 | 223 | m_cubeVertexBuffer = bgfx::createVertexBuffer( 224 | bgfx::makeRef(s_vertices, sizeof(s_vertices)) 225 | ,m_cubeLayout); 226 | 227 | m_cubeIndexBuffer = bgfx::createIndexBuffer( 228 | bgfx::makeRef(s_indices, sizeof(s_indices) )); 229 | 230 | 231 | m_cubeProg = bgfx::createProgram( 232 | bgfx::createShader(loadMem(entry::getFileReader(), "cube/shaders/vs_cube.bin") ), 233 | bgfx::createShader(loadMem(entry::getFileReader(), "cube/shaders/fs_cube.bin") ), 234 | true); 235 | } 236 | 237 | void 238 | drawCube(bgfx::ViewId viewid){ 239 | bgfx::setViewFrameBuffer(viewid, m_frameBuffer); 240 | const float h = 15.f; 241 | const float worldmat[16] = { 242 | 1.f, 0.f, 0.f, 0.f, 243 | 0.f, 1.f, 0.f, 0.f, 244 | 0.f, 0.f, 1.f, 0.f, 245 | 0.f, h, 0.f, 1.f, 246 | }; 247 | bgfx::setTransform(worldmat); 248 | bgfx::setViewTransform(viewid, m_viewMat.Values, m_projMat.Values); 249 | bgfx::setVertexBuffer(0, m_cubeVertexBuffer); 250 | bgfx::setIndexBuffer(m_cubeIndexBuffer); 251 | 252 | bgfx::setState(m_renderstate); 253 | bgfx::submit(viewid, m_cubeProg, 0, BGFX_DISCARD_ALL); 254 | } 255 | 256 | void 257 | initFullScreen(){ 258 | m_sceneTex = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT); 259 | m_sceneDepth = bgfx::createTexture2D(m_width, m_height, false, 1, bgfx::TextureFormat::D24S8, BGFX_TEXTURE_RT); 260 | const bgfx::TextureHandle handles[] = {m_sceneTex, m_sceneDepth}; 261 | m_frameBuffer = bgfx::createFrameBuffer(2, handles, false); 262 | 263 | bgfx::setViewFrameBuffer(g_sceneViewId, m_frameBuffer); 264 | bgfx::setViewRect(g_sceneViewId, 0, 0, m_width, m_height); 265 | bgfx::setViewClear(g_sceneViewId 266 | , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH 267 | , 0x000000ff 268 | , 1.0f 269 | , 0 270 | ); 271 | 272 | bgfx::ShaderHandle fs = bgfx::createShader(loadMem(entry::getFileReader(), "cube/shaders/fs_fullscreen.bin")); 273 | m_fullscreenProg = bgfx::createProgram( 274 | bgfx::createShader(loadMem(entry::getFileReader(), "cube/shaders/vs_fullscreen.bin")), 275 | fs, 276 | true); 277 | 278 | bgfx::UniformHandle uniforms[16]; 279 | uint32_t numUniform = bgfx::getShaderUniforms(fs, uniforms, 16); 280 | for (uint32_t ii=0; iidata, size, bx::ErrorAssert{}); 306 | bx::close(_reader); 307 | mem->data[mem->size-1] = '\0'; 308 | return mem; 309 | } 310 | 311 | DBG("Failed to load %s.", _filePath); 312 | return NULL; 313 | } 314 | 315 | static const char* 316 | findShaderFile(const char* name, const char* type){ 317 | #define CHECK_SHADER(_SHADERNAME, _VS, _FS) if (strcmp(name, _SHADERNAME) == 0){ \ 318 | if (strcmp(type, "vs") == 0){\ 319 | return _VS;\ 320 | }\ 321 | assert(strcmp(type, "fs") == 0);\ 322 | return _FS;\ 323 | } 324 | 325 | CHECK_SHADER("sprite_unlit", "../shaders/sprite_unlit_vs.fx.bin", "../shaders/model_unlit_ps.fx.bin"); 326 | CHECK_SHADER("sprite_lit", "../shaders/sprite_lit_vs.fx.bin", "../shaders/model_lit_ps.fx.bin"); 327 | CHECK_SHADER("sprite_distortion", "../shaders/sprite_distortion_vs.fx.bin", "../shaders/model_distortion_ps.fx.bin"); 328 | CHECK_SHADER("sprite_adv_unlit", "../shaders/ad_sprite_unlit_vs.fx.bin", "../shaders/ad_model_unlit_ps.fx.bin"); 329 | CHECK_SHADER("sprite_adv_lit", "../shaders/ad_sprite_lit_vs.fx.bin", "../shaders/ad_model_lit_ps.fx.bin"); 330 | CHECK_SHADER("sprite_adv_distortion", "../shaders/ad_sprite_distortion_vs.fx.bin","../shaders/ad_model_distortion_ps.fx.bin"); 331 | 332 | CHECK_SHADER("model_unlit", "../shaders/model_unlit_vs.fx.bin", "../shaders/model_unlit_ps.fx.bin"); 333 | CHECK_SHADER("model_lit", "../shaders/model_lit_vs.fx.bin", "../shaders/model_lit_ps.fx.bin"); 334 | CHECK_SHADER("model_distortion", "../shaders/model_distortion_vs.fx.bin", "../shaders/model_distortion_ps.fx.bin"); 335 | CHECK_SHADER("model_adv_unlit", "../shaders/ad_model_unlit_vs.fx.bin", "../shaders/ad_model_unlit_ps.fx.bin"); 336 | CHECK_SHADER("model_adv_lit", "../shaders/ad_model_lit_vs.fx.bin", "../shaders/ad_model_lit_ps.fx.bin"); 337 | CHECK_SHADER("model_adv_distortion", "../shaders/ad_model_distortion_vs.fx.bin", "../shaders/ad_model_distortion_ps.fx.bin"); 338 | 339 | assert(false && "invalid shader name and type name"); 340 | return nullptr; 341 | } 342 | 343 | static bgfx_shader_handle_t ShaderLoad(const char *mat, const char *name, const char *type, void *ud){ 344 | assert(mat == nullptr); 345 | const char* shaderfile = findShaderFile(name, type); 346 | bgfx::ShaderHandle handle = bgfx::createShader(loadMem(entry::getFileReader(), shaderfile) ); 347 | bgfx::setName(handle, shaderfile); 348 | 349 | return bgfx_shader_handle_t{handle.idx}; 350 | } 351 | static bool isPngFile(const char* filename){ 352 | std::string s(filename); 353 | for (auto &c: s) c = std::tolower(c); 354 | return s.rfind(".png") != std::string::npos; 355 | } 356 | 357 | static bgfx::TextureHandle 358 | loadPng(const char* filename, uint64_t state){ 359 | const bgfx::Memory* mem = loadMem(entry::getFileReader(), filename); 360 | auto image = bimg::imageParse(entry::getAllocator(), mem->data, mem->size, bimg::TextureFormat::Enum(bgfx::TextureFormat::Count), nullptr); 361 | assert(image && "invalid png file"); 362 | bimg::ImageContainer *dstimage = nullptr; 363 | if (image->m_format == bgfx::TextureFormat::RG8){ 364 | dstimage = bimg::imageAlloc(entry::getAllocator() 365 | , bimg::TextureFormat::RGBA8 366 | , uint16_t(image->m_width) 367 | , uint16_t(image->m_height) 368 | , uint16_t(image->m_depth) 369 | , image->m_numLayers 370 | , image->m_cubeMap 371 | , false 372 | ); 373 | auto unpack = [](float* dst, const void* src){ 374 | const uint8_t* _src = (const uint8_t*)src; 375 | dst[0] = dst[1] = dst[2] = bx::fromUnorm(_src[0], 255.0f); 376 | if (_src[1] != 255 && _src[1] != 0){ 377 | int debug = 0; 378 | } 379 | dst[3] = bx::fromUnorm(_src[1], 255.0f); 380 | }; 381 | const auto srcbpp = 16; 382 | const auto dstbpp = 32; 383 | bimg::imageConvert(dstimage->m_data, dstbpp, bx::packRgba8, 384 | image->m_data, srcbpp, unpack, 385 | image->m_width, image->m_height, image->m_depth, 386 | image->m_width * (srcbpp/8), image->m_width * (dstbpp/8)); 387 | } else { 388 | dstimage = bimg::imageConvert(entry::getAllocator(), bimg::TextureFormat::RGBA8, *image, false); 389 | } 390 | 391 | imageFree(image); 392 | 393 | auto h = bgfx::createTexture2D( 394 | (uint16_t)dstimage->m_width 395 | , (uint16_t)dstimage->m_height 396 | , false 397 | , 1 398 | , bgfx::TextureFormat::RGBA8 399 | , state 400 | , bgfx::copy(dstimage->m_data, dstimage->m_size) 401 | ); 402 | imageFree(dstimage); 403 | return h; 404 | } 405 | 406 | static bgfx::TextureHandle createTexture(const char* filename, uint64_t state){ 407 | if (isPngFile(filename)){ 408 | return loadPng(filename, state); 409 | } 410 | 411 | return bgfx::createTexture(loadMem(entry::getFileReader(), filename), state); 412 | } 413 | 414 | static bgfx_texture_handle_t TextureGet(int texture_type, void *parm, void *ud){ 415 | EffekseerBgfxTest *that = (EffekseerBgfxTest *)ud; 416 | if (texture_type == TEXTURE_BACKGROUND) 417 | return {that->m_sceneTex.idx}; 418 | 419 | if (texture_type == TEXTURE_DEPTH){ 420 | EffekseerRenderer::DepthReconstructionParameter *p = (EffekseerRenderer::DepthReconstructionParameter*)parm; 421 | p->DepthBufferScale = 1.0f; 422 | p->DepthBufferOffset = 0.0f; 423 | 424 | p->ProjectionMatrix33 = that->m_projMat.Values[2][2]; 425 | p->ProjectionMatrix34 = that->m_projMat.Values[2][3]; 426 | p->ProjectionMatrix43 = that->m_projMat.Values[3][2]; 427 | p->ProjectionMatrix44 = that->m_projMat.Values[3][3]; 428 | return {that->m_sceneDepth.idx}; 429 | } 430 | assert(false && "invalid texture type"); 431 | return {BGFX_INVALID_HANDLE}; 432 | } 433 | 434 | static int TextureLoad(const char *name, int srgb, void *ud){ 435 | const uint64_t state = (srgb ? BGFX_TEXTURE_SRGB : BGFX_TEXTURE_NONE)|BGFX_SAMPLER_NONE; 436 | auto handle = createTexture(name, state); 437 | bgfx::setName(handle, name); 438 | if (handle.idx == 0xffff) 439 | return -1; 440 | return handle.idx; 441 | } 442 | 443 | static void TextureUnload(int id, void *ud){ 444 | bgfx::destroy(bgfx::TextureHandle{uint16_t(id & 0xffff)}); 445 | } 446 | static bgfx_texture_handle_t TextureHandle(int id, void *ud) { 447 | bgfx_texture_handle_t ret { uint16_t(id & 0xffff) }; 448 | return ret; 449 | } 450 | private: 451 | EffekseerRenderer::RendererRef m_efkRenderer = nullptr; 452 | Effekseer::ManagerRef m_efkManager = nullptr; 453 | Effekseer::Matrix44 m_projMat; 454 | Effekseer::Matrix44 m_viewMat; 455 | 456 | bgfx::TextureHandle m_sceneTex = BGFX_INVALID_HANDLE; 457 | bgfx::TextureHandle m_sceneDepth = BGFX_INVALID_HANDLE; 458 | bgfx::FrameBufferHandle m_frameBuffer = BGFX_INVALID_HANDLE; 459 | 460 | bgfx::VertexLayout m_cubeLayout; 461 | bgfx::VertexBufferHandle m_cubeVertexBuffer = BGFX_INVALID_HANDLE; 462 | bgfx::IndexBufferHandle m_cubeIndexBuffer = BGFX_INVALID_HANDLE; 463 | 464 | bgfx::ProgramHandle m_fullscreenProg = BGFX_INVALID_HANDLE; 465 | bgfx::ProgramHandle m_cubeProg = BGFX_INVALID_HANDLE; 466 | 467 | bgfx::UniformHandle m_fullscreenTextureUniformHandle = BGFX_INVALID_HANDLE; 468 | 469 | Effekseer::Handle m_efkHandle = 0; 470 | 471 | const uint64_t m_renderstate = 0 472 | | BGFX_STATE_WRITE_R 473 | | BGFX_STATE_WRITE_G 474 | | BGFX_STATE_WRITE_B 475 | | BGFX_STATE_WRITE_A 476 | | BGFX_STATE_WRITE_Z 477 | | BGFX_STATE_DEPTH_TEST_LESS 478 | | BGFX_STATE_CULL_CW 479 | | BGFX_STATE_MSAA; 480 | 481 | const uint64_t m_fullscreenstate = 0 482 | | BGFX_STATE_WRITE_R 483 | | BGFX_STATE_WRITE_G 484 | | BGFX_STATE_WRITE_B 485 | | BGFX_STATE_WRITE_A 486 | | BGFX_STATE_MSAA; 487 | }; 488 | 489 | } // namespace 490 | 491 | ENTRY_IMPLEMENT_MAIN( 492 | EffekseerBgfxTest 493 | , "EffekseerBgfxTest" 494 | , "Effekseer bgfx renderer example." 495 | , "https://github.com/cloudwu/efkbgfx" 496 | ); 497 | --------------------------------------------------------------------------------