| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- include = [
- "core/shaders/common.shader"
- "core/shaders/lighting.shader"
- ]
- render_states = {
- debug_line = {
- inherit = "default"
- states = {
- blend_enable = true
- blend_src = "src_alpha"
- blend_dst = "inv_src_alpha"
- primitive_type = "pt_lines"
- "!defined(DEPTH_ENABLED)" = {
- depth_enable = false
- }
- }
- }
- gui = {
- inherit = "opacity"
- }
- blit = {
- inherit = "opacity"
- states = {
- "!defined(BLEND_ENABLED)" = {
- blend_enable = false;
- }
- }
- }
- sprite = {
- inherit = "default"
- states = {
- depth_func = "always"
- blend_enable = true
- blend_src = "src_alpha"
- blend_dst = "inv_src_alpha"
- blend_equation = "add"
- }
- }
- mesh = {
- inherit = "default"
- }
- skydome = {
- inherit = "default"
- }
- noop = {
- inherit = "default"
- states = {
- rgb_write_enable = false
- alpha_write_enable = false
- depth_write_enable = false
- depth_enable = false
- blend_enable = false
- }
- }
- }
- bgfx_shaders = {
- debug_line = {
- includes = [ "common" ]
- varying = """
- vec4 v_color0 : COLOR0 = vec4(0.0, 0.0, 0.0, 0.0);
- vec3 a_position : POSITION;
- vec4 a_color0 : COLOR0;
- """
- vs_input_output = """
- $input a_position, a_color0
- $output v_color0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
- v_color0 = a_color0;
- }
- """
- fs_input_output = """
- $input v_color0
- """
- fs_code = """
- void main()
- {
- gl_FragColor = v_color0;
- }
- """
- }
- gui = {
- includes = [ "common" ]
- samplers = {
- u_albedo_map = { sampler_state = "clamp_anisotropic" }
- }
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec4 v_color0 : COLOR0 = vec4(0.0, 0.0, 0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- vec4 a_color0 : COLOR0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0, a_color0
- $output v_texcoord0, v_color0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
- #if defined(DIFFUSE_MAP)
- v_texcoord0 = a_texcoord0;
- #endif // DIFFUSE_MAP
- v_color0 = a_color0;
- }
- """
- fs_input_output = """
- $input v_texcoord0, v_color0
- """
- fs_code = """
- #if defined(DIFFUSE_MAP)
- SAMPLER2D(u_albedo_map, 0);
- #endif // DIFFUSE_MAP
- void main()
- {
- #if defined(DIFFUSE_MAP)
- gl_FragColor = toGammaAccurate(texture2D(u_albedo_map, v_texcoord0) * toLinearAccurate(v_color0));
- #else
- gl_FragColor = v_color0;
- #endif // DIFFUSE_MAP
- }
- """
- }
- sprite = {
- includes = [ "common" ]
- samplers = {
- u_albedo_map = { sampler_state = "clamp_point" }
- }
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0
- $output v_texcoord0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_texcoord0
- """
- fs_code = """
- SAMPLER2D(u_albedo_map, 0);
- uniform vec4 u_color;
- void main()
- {
- gl_FragColor = toGammaAccurate(texture2D(u_albedo_map, v_texcoord0) * toLinearAccurate(u_color));
- }
- """
- }
- mesh = {
- includes = [ "common" "lighting" ]
- samplers = {
- u_albedo_map = { sampler_state = "mirror_anisotropic" }
- u_normal_map = { sampler_state = "mirror_anisotropic" }
- u_metallic_map = { sampler_state = "mirror_anisotropic" }
- u_roughness_map = { sampler_state = "mirror_anisotropic" }
- u_ao_map = { sampler_state = "mirror_anisotropic" }
- u_emission_map = { sampler_state = "mirror_anisotropic" }
- }
- varying = """
- vec3 v_normal : NORMAL = vec3(0.0, 0.0, 0.0);
- vec3 v_tangent : TANGENT = vec3(0.0, 0.0, 0.0);
- vec3 v_bitangent : BITANGENT = vec3(0.0, 0.0, 0.0);
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 v_position : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
- vec3 v_camera : TEXCOORD2 = vec3(0.0, 0.0, 0.0);
- vec4 v_shadow0 : TEXCOORD3 = vec4(0.0, 0.0, 0.0, 0.0);
- vec4 v_shadow1 : TEXCOORD4 = vec4(0.0, 0.0, 0.0, 0.0);
- vec4 v_shadow2 : TEXCOORD5 = vec4(0.0, 0.0, 0.0, 0.0);
- vec4 v_shadow3 : TEXCOORD6 = vec4(0.0, 0.0, 0.0, 0.0);
- vec4 v_shadow_local : TEXCOORD7 = vec4(0.0, 0.0, 0.0, 0.0);
- vec3 v_camera_pos : TEXCOORD8 = vec3(0.0, 0.0, 0.0);
- vec3 a_position : POSITION;
- vec3 a_normal : NORMAL;
- vec3 a_tangent : TANGENT;
- vec3 a_bitangent : BITANGENT;
- vec4 a_indices : BLENDINDICES;
- vec4 a_weight : BLENDWEIGHT;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- #if defined(SKINNING)
- $input a_position, a_normal, a_tangent, a_bitangent, a_texcoord0, a_indices, a_weight
- #else
- $input a_position, a_normal, a_tangent, a_bitangent, a_texcoord0
- #endif
- $output v_normal, v_tangent, v_bitangent, v_texcoord0, v_position, v_camera, v_camera_pos, v_shadow0, v_shadow1, v_shadow2, v_shadow3, v_shadow_local
- """
- vs_code = """
- uniform vec4 u_use_normal_map;
- uniform vec4 u_uv_scale;
- uniform vec4 u_uv_offset;
- void main()
- {
- #if defined(SKINNING)
- mat4 model;
- model = a_weight.x * u_model[int(a_indices.x)];
- model += a_weight.y * u_model[int(a_indices.y)];
- model += a_weight.z * u_model[int(a_indices.z)];
- model += a_weight.w * u_model[int(a_indices.w)];
- gl_Position = mul(mul(u_modelViewProj, model), vec4(a_position, 1.0));
- model = mul(u_model[0], model);
- #else
- gl_Position = mul(mul(u_viewProj, u_model[0]), vec4(a_position, 1.0));
- mat4 model = u_model[0];
- #endif
- vec3 normal = decodeNormalUint(a_normal);
- vec3 tangent = decodeNormalUint(a_tangent);
- vec3 bitangent = decodeNormalUint(a_bitangent);
- mat3 normal_matrix = cofactor(model);
- v_position = mul(model, vec4(a_position, 1.0)).xyz;
- v_normal = normalize(mul(normal_matrix, normal)).xyz;
- v_tangent = normalize(mul(normal_matrix, tangent)).xyz;
- v_bitangent = normalize(mul(normal_matrix, bitangent)).xyz;
- mat3 tbn;
- if (u_use_normal_map.r == 1.0)
- tbn = mtxFromCols(v_tangent, v_bitangent, v_normal);
- else
- tbn = mtxFromCols(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0));
- v_camera_pos = mul(u_invView, vec4(0.0, 0.0, 0.0, 1.0)).xyz;
- v_camera = mul(v_camera_pos - v_position, tbn);
- v_position = mul(v_position, tbn);
- v_texcoord0 = (a_texcoord0 - vec2_splat(0.5))*u_uv_scale.xy + vec2_splat(0.5) + u_uv_offset.xy;
- #if !defined(NO_LIGHT)
- vec3 pos_offset = a_position + normal * 0.01;
- v_shadow0 = mul(mul(u_cascaded_lights[0], model), vec4(pos_offset, 1.0));
- v_shadow1 = mul(mul(u_cascaded_lights[1], model), vec4(pos_offset, 1.0));
- v_shadow2 = mul(mul(u_cascaded_lights[2], model), vec4(pos_offset, 1.0));
- v_shadow3 = mul(mul(u_cascaded_lights[3], model), vec4(pos_offset, 1.0));
- v_shadow_local = mul(model, vec4(pos_offset, 1.0));
- #endif
- }
- """
- fs_input_output = """
- $input v_normal, v_tangent, v_bitangent, v_texcoord0, v_position, v_camera, v_camera_pos, v_shadow0, v_shadow1, v_shadow2, v_shadow3, v_shadow_local
- """
- code = """
- """
- fs_code = """
- SAMPLER2D(u_albedo_map, 0);
- SAMPLER2D(u_normal_map, 1);
- SAMPLER2D(u_metallic_map, 2);
- SAMPLER2D(u_roughness_map, 3);
- SAMPLER2D(u_ao_map, 4);
- SAMPLER2D(u_emission_map, 5);
- uniform vec4 u_albedo;
- uniform vec4 u_metallic;
- uniform vec4 u_roughness;
- uniform vec4 u_emission_color;
- uniform vec4 u_emission_intensity;
- uniform vec4 u_use_albedo_map;
- uniform vec4 u_use_normal_map;
- uniform vec4 u_use_metallic_map;
- uniform vec4 u_use_roughness_map;
- uniform vec4 u_use_ao_map;
- uniform vec4 u_use_emission_map;
- void main()
- {
- vec3 albedo = u_use_albedo_map.r == 1.0 ? texture2D(u_albedo_map, v_texcoord0).rgb : u_albedo.rgb;
- #if defined(NO_LIGHT)
- vec3 radiance = albedo;
- #else
- vec3 normal;
- if (u_use_normal_map.r == 1.0) {
- normal.xy = texture2DBc5(u_normal_map, v_texcoord0) * 2.0 - 1.0;
- normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
- } else {
- normal = v_normal;
- }
- float metallic = u_use_metallic_map.r == 1.0 ? texture2D(u_metallic_map, v_texcoord0).r : u_metallic.r;
- float roughness = u_use_roughness_map.r == 1.0 ? texture2D(u_roughness_map, v_texcoord0).r: u_roughness.r;
- float ao = u_use_ao_map.r == 1.0 ? texture2D(u_ao_map, v_texcoord0).r : 1.0;
- vec3 emission = u_emission_intensity.r * (u_use_emission_map.r == 1.0 ? texture2D(u_emission_map, v_texcoord0).rgb : u_emission_color.rgb);
- mat3 tbn;
- if (u_use_normal_map.r == 1.0)
- tbn = mtxFromCols(v_tangent, v_bitangent, v_normal);
- else
- tbn = mtxFromCols(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0));
- vec3 n = normalize(normal); // Fragment normal.
- vec3 v = normalize(v_camera); // Versor from fragment to camera pos.
- vec3 f0 = mix(vec3_splat(0.04), albedo, metallic);
- vec3 radiance = calc_lighting(tbn, n, v, v_position, v_camera, v_camera_pos, v_shadow0, v_shadow1, v_shadow2, v_shadow3, v_shadow_local, albedo, metallic, roughness, ao, emission, f0);
- #endif // !defined(NO_LIGHT)
- gl_FragColor = vec4(radiance, 1.0);
- }
- """
- }
- skydome = {
- includes = [ "common" ]
- samplers = {
- u_skydome_map = { sampler_state = "clamp_anisotropic" }
- }
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0
- $output v_texcoord0
- """
- vs_code = """
- uniform mat4 u_persp; // Perspective proj.
- void main()
- {
- vec4 world_pos = mul(mul(u_persp, u_modelView), vec4(a_position, 1.0));
- world_pos.z = world_pos.w; // Project to far plane.
- gl_Position = world_pos;
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_texcoord0
- """
- fs_code = """
- SAMPLER2D(u_skydome_map, 0);
- uniform vec4 u_skydome_intensity;
- void main()
- {
- gl_FragColor = texture2D(u_skydome_map, v_texcoord0) * u_skydome_intensity.x;
- }
- """
- }
- blit = {
- includes = [ "common" ]
- varying = """
- vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_texcoord0
- $output v_texcoord0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0) );
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_texcoord0
- """
- fs_code = """
- SAMPLER2D(s_color_map, 0);
- void main()
- {
- gl_FragColor = texture2D(s_color_map, v_texcoord0);
- }
- """
- }
- fallback = {
- includes = [ "common" ]
- varying = """
- vec3 a_position : POSITION;
- """
- vs_input_output = """
- $input a_position
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
- }
- """
- fs_input_output = """
- """
- fs_code = """
- void main()
- {
- gl_FragColor = toGammaAccurate(vec4(1.0, 0.0, 1.0, 1.0));
- }
- """
- }
- noop = {
- includes = [ "common" ]
- varying = """
- """
- vs_input_output = """
- """
- vs_code = """
- void main()
- {
- gl_Position = vec4_splat(0.0);
- }
- """
- fs_input_output = """
- """
- fs_code = """
- void main()
- {
- discard;
- }
- """
- }
- }
- shaders = {
- debug_line = {
- bgfx_shader = "debug_line"
- render_state = "debug_line"
- }
- gui = {
- bgfx_shader = "gui"
- render_state = "gui"
- }
- sprite = {
- bgfx_shader = "sprite"
- render_state = "sprite"
- }
- mesh = {
- bgfx_shader = "mesh"
- render_state = "mesh"
- }
- skydome = {
- bgfx_shader = "skydome"
- render_state = "skydome"
- }
- blit = {
- bgfx_shader = "blit"
- render_state = "blit"
- }
- fallback = {
- bgfx_shader = "fallback"
- render_state = "mesh"
- }
- noop = {
- bgfx_shader = "noop"
- render_state = "noop"
- }
- }
- static_compile = [
- { shader = "debug_line" defines = [] }
- { shader = "debug_line" defines = ["DEPTH_ENABLED"] }
- { shader = "gui" defines = [] }
- { shader = "gui" defines = ["DIFFUSE_MAP"]}
- { shader = "gui" defines = ["DEPTH_ENABLED"]}
- { shader = "gui" defines = ["DIFFUSE_MAP" "DEPTH_ENABLED"]}
- { shader = "sprite" defines = [] }
- { shader = "mesh" defines = [] }
- { shader = "mesh" defines = ["DIFFUSE_MAP"] }
- { shader = "mesh" defines = ["SKINNING"] }
- { shader = "mesh" defines = ["NO_LIGHT"] }
- { shader = "mesh" defines = ["DIFFUSE_MAP" "SKINNING"] }
- { shader = "mesh" defines = ["DIFFUSE_MAP" "NO_LIGHT"] }
- { shader = "skydome" defines = [] }
- { shader = "blit" defines = [] }
- { shader = "blit" defines = ["BLEND_ENABLED"] }
- { shader = "fallback" defines = [] }
- { shader = "noop" defines = [] }
- ]
|