| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- include = ["core/shaders/common.shader"]
- render_states = {
- debug_line = {
- blend_enable = true
- blend_src = "src_alpha"
- blend_dst = "inv_src_alpha"
- primitive_type = "pt_lines"
- }
- debug_line_noz = {
- inherit = "debug_line"
- depth_enable = false
- }
- gui = {
- depth_write_enable = false
- depth_enable = false
- blend_enable = true
- blend_src = "src_alpha"
- blend_dst = "inv_src_alpha"
- }
- gui_noblend = {
- inherit = "gui"
- blend_enable = false
- }
- sprite = {
- depth_func = "always"
- blend_enable = true
- blend_src = "src_alpha"
- blend_dst = "inv_src_alpha"
- blend_equation = "add"
- }
- mesh = {
- }
- selection = {
- alpha_write_enable = false
- }
- noop = {
- 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 = toLinearAccurate(a_color0);
- }
- """
- fs_input_output = """
- $input v_color0
- """
- fs_code = """
- void main()
- {
- gl_FragColor = v_color0;
- }
- """
- }
- gui = {
- includes = "common"
- samplers = {
- u_albedo = { 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));
- #ifdef DIFFUSE_MAP
- v_texcoord0 = a_texcoord0;
- #endif // DIFFUSE_MAP
- v_color0 = toLinearAccurate(a_color0);
- }
- """
- fs_input_output = """
- $input v_texcoord0, v_color0
- """
- fs_code = """
- #ifdef DIFFUSE_MAP
- SAMPLER2D(u_albedo, 0);
- #endif // DIFFUSE_MAP
- void main()
- {
- #ifdef DIFFUSE_MAP
- gl_FragColor = texture2D(u_albedo, v_texcoord0) * v_color0;
- #else
- gl_FragColor = v_color0;
- #endif // DIFFUSE_MAP
- }
- """
- }
- sprite = {
- includes = "common"
- samplers = {
- u_albedo = { 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 = """
- uniform vec4 u_color;
- SAMPLER2D(u_albedo, 0);
- void main()
- {
- gl_FragColor = texture2D(u_albedo, v_texcoord0) * toLinearAccurate(u_color);
- }
- """
- }
- mesh = {
- includes = "common"
- samplers = {
- u_albedo = { sampler_state = "mirror_anisotropic" }
- }
- varying = """
- vec3 v_normal : NORMAL = vec3(0.0, 0.0, 0.0);
- vec4 v_view : TEXCOORD0 = vec4(0.0, 0.0, 0.0, 0.0);
- vec2 v_texcoord0 : TEXCOORD1 = vec2(0.0, 0.0);
- vec3 a_position : POSITION;
- vec3 a_normal : NORMAL;
- vec2 a_texcoord0 : TEXCOORD0;
- """
- vs_input_output = """
- $input a_position, a_normal, a_texcoord0
- $output v_normal, v_view, v_texcoord0
- """
- vs_code = """
- void main()
- {
- gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
- v_view = mul(u_modelView, vec4(a_position, 1.0));
- v_normal = normalize(mul(u_modelView, vec4(a_normal, 0.0)).xyz);
- v_texcoord0 = a_texcoord0;
- }
- """
- fs_input_output = """
- $input v_normal, v_view, v_texcoord0
- """
- fs_code = """
- #if !defined(NO_LIGHT)
- uniform vec4 u_light_position; // In world-space
- uniform vec4 u_light_direction; // In view-space
- uniform vec4 u_light_color;
- uniform vec4 u_light_range;
- uniform vec4 u_light_intensity;
- uniform vec4 u_ambient;
- uniform vec4 u_diffuse;
- uniform vec4 u_specular;
- #endif
- #ifdef DIFFUSE_MAP
- SAMPLER2D(u_albedo, 0);
- #endif // DIFFUSE_MAP
- void main()
- {
- #if !defined(NO_LIGHT)
- // normalize both input vectors
- vec3 n = normalize(v_normal);
- vec3 e = normalize(v_view.xyz);
- vec3 l = u_light_direction.xyz;
- float nl = max(0.0, dot(n, l));
- vec3 light_diffuse = nl * toLinearAccurate(u_light_color.rgb) * u_light_intensity.x;
- vec3 color = max(u_diffuse.rgb * light_diffuse, u_ambient.rgb);
- #else
- vec3 color = vec3(1.0f, 1.0f, 1.0f);
- #endif // !defined(NO_LIGHT)
- #ifdef DIFFUSE_MAP
- gl_FragColor.rgb = color * texture2D(u_albedo, v_texcoord0).rgb;
- #else
- gl_FragColor.rgb = color;
- #endif // DIFFUSE_MAP
- gl_FragColor.a = 1.0;
- }
- """
- }
- selection = {
- 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 = """
- uniform vec4 u_unit_id;
- void main()
- {
- gl_FragColor.r = u_unit_id.x;
- }
- """
- }
- outline = {
- 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 = """
- #if !BX_PLATFORM_EMSCRIPTEN
- USAMPLER2D(s_selection, 0);
- SAMPLER2D(s_selection_depth, 1);
- SAMPLER2D(s_main_depth, 2);
- uniform vec4 u_outline_color;
- void main()
- {
- vec2 tex_size = vec2(textureSize(s_selection, 0)) - vec2(1, 1);
- uint id[8];
- id[0] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2(-1, -1)), 0).r;
- id[1] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2( 0, -1)), 0).r;
- id[2] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2( 1, -1)), 0).r;
- id[3] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2( 1, 0)), 0).r;
- id[4] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2( 1, 1)), 0).r;
- id[5] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2( 0, 1)), 0).r;
- id[6] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2(-1, 1)), 0).r;
- id[7] = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size + vec2(-1, 0)), 0).r;
- uint ref_id = texelFetch(s_selection, ivec2(v_texcoord0 * tex_size), 0).r;
- float alpha = 0.0;
- for (int ii = 0; ii < 8; ++ii)
- {
- if (ref_id != id[ii])
- alpha += 1.0/8.0;
- }
- if (alpha == 0.0)
- {
- gl_FragColor = vec4(0, 0, 0, 0);
- return;
- }
- alpha = max(0.5, alpha);
- // Scan the depth around the center and choose the value closest
- // to the viewer. This is to avoid getting s_depth = 1.0.
- float s_depth = 1.0;
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2(-1, -1)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2( 0, -1)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2( 1, -1)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2( 1, 0)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2( 1, 1)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2( 0, 1)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2(-1, 1)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2(-1, 0)), 0).r);
- s_depth = min(s_depth, texelFetch(s_selection_depth, ivec2(v_texcoord0 * tex_size + vec2( 0, 0)), 0).r);
- float m_depth = texelFetch(s_main_depth, ivec2(v_texcoord0 * tex_size), 0).r;
- // Dim alpha if selected object is behind another object.
- if (s_depth > m_depth)
- alpha *= 0.35;
- gl_FragColor = vec4(u_outline_color.xyz, alpha);
- }
- #else
- void main()
- {
- gl_FragColor = vec4_splat(0.0);
- }
- #endif
- """
- }
- 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, 0);
- void main()
- {
- gl_FragColor = toGammaAccurate(texture2D(s_color, 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 = 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"
- }
- debug_line_noz = {
- bgfx_shader = "debug_line"
- render_state = "debug_line_noz"
- }
- gui = {
- bgfx_shader = "gui"
- render_state = "gui"
- }
- sprite = {
- bgfx_shader = "sprite"
- render_state = "sprite"
- }
- mesh = {
- bgfx_shader = "mesh"
- render_state = "mesh"
- }
- selection = {
- bgfx_shader = "selection"
- render_state = "selection"
- }
- outline = {
- bgfx_shader = "outline"
- render_state = "gui"
- }
- blit = {
- bgfx_shader = "blit"
- render_state = "gui_noblend"
- }
- fallback = {
- bgfx_shader = "fallback"
- render_state = "mesh"
- }
- noop = {
- bgfx_shader = "noop"
- render_state = "noop"
- }
- }
- static_compile = [
- { shader = "debug_line" defines = [] }
- { shader = "debug_line_noz" defines = [] }
- { shader = "gui" defines = [] }
- { shader = "gui" defines = ["DIFFUSE_MAP"]}
- { shader = "sprite" defines = [] }
- { shader = "mesh" defines = [] }
- { shader = "mesh" defines = ["DIFFUSE_MAP"] }
- { shader = "mesh" defines = ["DIFFUSE_MAP" "NO_LIGHT"] }
- { shader = "selection" defines = [] }
- { shader = "outline" defines = [] }
- { shader = "blit" defines = [] }
- { shader = "fallback" defines = [] }
- { shader = "noop" defines = [] }
- ]
|