cyberarm_engine 0.24.4 → 0.24.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -8
  3. data/.rubocop.yml +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +6 -6
  6. data/Gemfile.lock +24 -0
  7. data/LICENSE.txt +21 -21
  8. data/README.md +74 -74
  9. data/Rakefile +10 -10
  10. data/assets/shaders/fragment/g_buffer.glsl +30 -30
  11. data/assets/shaders/fragment/lighting.glsl +115 -69
  12. data/assets/shaders/include/light_struct.glsl +11 -11
  13. data/assets/shaders/include/material_struct.glsl +16 -16
  14. data/assets/shaders/vertex/g_buffer.glsl +28 -28
  15. data/assets/shaders/vertex/lighting.glsl +24 -24
  16. data/bin/console +14 -14
  17. data/bin/setup +8 -8
  18. data/cyberarm_engine.gemspec +36 -36
  19. data/lib/cyberarm_engine/animator.rb +219 -219
  20. data/lib/cyberarm_engine/background.rb +180 -179
  21. data/lib/cyberarm_engine/background_image.rb +93 -93
  22. data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
  23. data/lib/cyberarm_engine/bounding_box.rb +150 -150
  24. data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
  25. data/lib/cyberarm_engine/cache/download_manager.rb +123 -123
  26. data/lib/cyberarm_engine/cache.rb +4 -4
  27. data/lib/cyberarm_engine/common.rb +128 -128
  28. data/lib/cyberarm_engine/config_file.rb +46 -46
  29. data/lib/cyberarm_engine/console/command.rb +157 -157
  30. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
  31. data/lib/cyberarm_engine/console/subcommand.rb +99 -99
  32. data/lib/cyberarm_engine/console.rb +248 -248
  33. data/lib/cyberarm_engine/game_object.rb +244 -244
  34. data/lib/cyberarm_engine/game_state.rb +124 -124
  35. data/lib/cyberarm_engine/gosu_ext/draw_arc.rb +97 -97
  36. data/lib/cyberarm_engine/gosu_ext/draw_circle.rb +30 -30
  37. data/lib/cyberarm_engine/gosu_ext/draw_path.rb +17 -17
  38. data/lib/cyberarm_engine/model/material.rb +21 -21
  39. data/lib/cyberarm_engine/model/{model_object.rb → mesh.rb} +131 -131
  40. data/lib/cyberarm_engine/model/parser.rb +74 -74
  41. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
  42. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
  43. data/lib/cyberarm_engine/model.rb +216 -213
  44. data/lib/cyberarm_engine/model_cache.rb +31 -31
  45. data/lib/cyberarm_engine/notification.rb +82 -82
  46. data/lib/cyberarm_engine/notification_manager.rb +241 -241
  47. data/lib/cyberarm_engine/opengl/light.rb +52 -50
  48. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
  49. data/lib/cyberarm_engine/opengl/perspective_camera.rb +41 -38
  50. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
  51. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +167 -165
  52. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +307 -304
  53. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +33 -33
  54. data/lib/cyberarm_engine/opengl/shader.rb +408 -406
  55. data/lib/cyberarm_engine/opengl/texture.rb +69 -69
  56. data/lib/cyberarm_engine/opengl.rb +53 -40
  57. data/lib/cyberarm_engine/ray.rb +56 -56
  58. data/lib/cyberarm_engine/stats.rb +200 -200
  59. data/lib/cyberarm_engine/text.rb +260 -260
  60. data/lib/cyberarm_engine/timer.rb +23 -23
  61. data/lib/cyberarm_engine/transform.rb +296 -296
  62. data/lib/cyberarm_engine/trees/aabb_node.rb +126 -0
  63. data/lib/cyberarm_engine/trees/aabb_tree.rb +55 -0
  64. data/lib/cyberarm_engine/trees/aabb_tree_debug.rb +29 -0
  65. data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
  66. data/lib/cyberarm_engine/ui/dsl.rb +142 -142
  67. data/lib/cyberarm_engine/ui/element.rb +662 -662
  68. data/lib/cyberarm_engine/ui/elements/button.rb +100 -100
  69. data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
  70. data/lib/cyberarm_engine/ui/elements/container.rb +404 -404
  71. data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
  72. data/lib/cyberarm_engine/ui/elements/edit_line.rb +297 -297
  73. data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
  74. data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
  75. data/lib/cyberarm_engine/ui/elements/list_box.rb +79 -79
  76. data/lib/cyberarm_engine/ui/elements/menu.rb +27 -27
  77. data/lib/cyberarm_engine/ui/elements/menu_item.rb +6 -6
  78. data/lib/cyberarm_engine/ui/elements/progress.rb +93 -93
  79. data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
  80. data/lib/cyberarm_engine/ui/elements/slider.rb +107 -107
  81. data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
  82. data/lib/cyberarm_engine/ui/elements/text_block.rb +216 -216
  83. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +67 -67
  84. data/lib/cyberarm_engine/ui/event.rb +54 -54
  85. data/lib/cyberarm_engine/ui/gui_state.rb +321 -321
  86. data/lib/cyberarm_engine/ui/style.rb +50 -50
  87. data/lib/cyberarm_engine/ui/theme.rb +225 -225
  88. data/lib/cyberarm_engine/vector.rb +312 -312
  89. data/lib/cyberarm_engine/version.rb +4 -4
  90. data/lib/cyberarm_engine/window.rb +195 -195
  91. data/lib/cyberarm_engine.rb +70 -78
  92. data/mrbgem.rake +29 -29
  93. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d1ca43bcfb5385b9c2666d4917ac44683fcb22c44fa18b918643fab9ec16ef9
4
- data.tar.gz: 62d712e673772e19f74c14d1b6a54318776848d51ac0fbf82e3b4dc581ea58bf
3
+ metadata.gz: 7c44575f9a8fbd0035a9c3c29f5300b346fdc9cb739342c1b6208cb8add1a676
4
+ data.tar.gz: '090cd515e5af9c480afb1314cddf56721a5dda85f3c7c8a7fe4c97b8faeb19f1'
5
5
  SHA512:
6
- metadata.gz: '09c5d9c2d88444021f625e35bef5d4eeb06bc5791f76e80d5560b2b347212f01c6be6bee26a782ca4aea1bfdeca535b4b8020cbce08e028980faec9a55b3ce89'
7
- data.tar.gz: 8e2185d8f47e3af2f0fc42106718bd64d722066a38fdfc3cf0777c3dbd4be7239443ac3f0552e26399c9791cf8297ca0ebd0066f6c1181c01553e6b01f3d74be
6
+ metadata.gz: 35613cc87423553e0976471dfa63559623c528d57826441eceb32bfdb58f3e7e0abeb1505895a8c9b5e2b7f1fa8814c482579a293d9816f944100c8bf01ebd46
7
+ data.tar.gz: 247a5aa8f53dab456b6847f1c7918e2f4ac9a42748b3cdd64c6e99ca132dbd8ae4db5c5fcd522584266ccb1c46fbad3793d8b2ad51ceeeb4499574444a764823
data/.gitignore CHANGED
@@ -1,8 +1,8 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml CHANGED
@@ -1,8 +1,8 @@
1
- Style/StringLiterals:
2
- EnforcedStyle: double_quotes
3
-
4
- Metrics/MethodLength:
5
- Max: 40
6
-
7
- Style/EmptyMethod:
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+
4
+ Metrics/MethodLength:
5
+ Max: 40
6
+
7
+ Style/EmptyMethod:
8
8
  EnforcedStyle: expanded
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.0
5
- before_install: gem install bundler -v 1.16.1
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in cyberarm_engine.gemspec
6
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cyberarm_engine.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cyberarm_engine (0.24.4)
5
+ gosu (~> 1.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ gosu (1.4.6)
11
+ minitest (5.25.5)
12
+ rake (13.2.1)
13
+
14
+ PLATFORMS
15
+ x64-mingw-ucrt
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 2.2)
19
+ cyberarm_engine!
20
+ minitest (~> 5.0)
21
+ rake (~> 13.0)
22
+
23
+ BUNDLED WITH
24
+ 2.5.3
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 Cyberarm
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all 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,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Cyberarm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,74 +1,74 @@
1
- ![CyberarmEngine](https://raw.githubusercontent.com/cyberarm/cyberarm_engine/master/assets/textures/logo.png)
2
-
3
- Yet Another Game Engine On Top Of Gosu
4
-
5
- ## Features
6
- * [Shoes-like](http://shoesrb.com) GUI support
7
- * OpenGL Shader support (requires [opengl-bindings](https://github.com/vaiorabbit/ruby-opengl) gem)
8
- * Includes classes for handling Vectors, Rays, Bounding Boxes, and Transforms
9
- * GameState system
10
- * Monolithic GameObjects
11
-
12
- ## Installation
13
-
14
- Add this line to your application's Gemfile:
15
-
16
- ```ruby
17
- gem 'cyberarm_engine'
18
- ```
19
-
20
- And then execute:
21
-
22
- $ bundle
23
-
24
- Or install it yourself as:
25
-
26
- $ gem install cyberarm_engine
27
-
28
- ## Usage
29
-
30
- ```ruby
31
- require "cyberarm_engine"
32
-
33
- class Hello < CyberarmEngine::GuiState
34
- def setup
35
- background Gosu::Color::GRAY
36
-
37
- stack do
38
- label "Hello World!"
39
-
40
- button "close" do
41
- window.close
42
- end
43
- end
44
- end
45
- end
46
-
47
- class Window < CyberarmEngine::Window
48
- def setup
49
- self.show_cursor = true
50
-
51
- push_state(Hello)
52
- end
53
- end
54
-
55
- Window.new(width: 800, height: 600, fullscreen: false, resizable: true).show
56
- ```
57
-
58
- ## Development
59
-
60
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
-
62
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
-
64
- ## Contributing
65
-
66
- Bug reports and pull requests are welcome on GitHub at https://github.com/cyberarm/cyberarm_engine.
67
-
68
- ## License
69
-
70
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
71
-
72
- ## Code of Conduct
73
-
74
- Everyone interacting in the CyberarmEngine project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the ruby moto of "Matz is nice so we are nice."
1
+ ![CyberarmEngine](https://raw.githubusercontent.com/cyberarm/cyberarm_engine/master/assets/textures/logo.png)
2
+
3
+ Yet Another Game Engine On Top Of Gosu
4
+
5
+ ## Features
6
+ * [Shoes-like](http://shoesrb.com) GUI support
7
+ * OpenGL Shader support (requires [opengl-bindings](https://github.com/vaiorabbit/ruby-opengl) gem)
8
+ * Includes classes for handling Vectors, Rays, Bounding Boxes, and Transforms
9
+ * GameState system
10
+ * Monolithic GameObjects
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'cyberarm_engine'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install cyberarm_engine
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require "cyberarm_engine"
32
+
33
+ class Hello < CyberarmEngine::GuiState
34
+ def setup
35
+ background Gosu::Color::GRAY
36
+
37
+ stack do
38
+ label "Hello World!"
39
+
40
+ button "close" do
41
+ window.close
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ class Window < CyberarmEngine::Window
48
+ def setup
49
+ self.show_cursor = true
50
+
51
+ push_state(Hello)
52
+ end
53
+ end
54
+
55
+ Window.new(width: 800, height: 600, fullscreen: false, resizable: true).show
56
+ ```
57
+
58
+ ## Development
59
+
60
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cyberarm/cyberarm_engine.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
71
+
72
+ ## Code of Conduct
73
+
74
+ Everyone interacting in the CyberarmEngine project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the ruby moto of "Matz is nice so we are nice."
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task default: :test
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
@@ -1,30 +1,30 @@
1
- # version 330 core
2
-
3
- layout(location = 0) out vec3 fragPosition;
4
- layout (location = 1) out vec4 fragColor;
5
- layout (location = 2) out vec3 fragNormal;
6
- layout (location = 3) out vec3 fragUV;
7
-
8
- in vec3 out_position, out_color, out_normal, out_uv, out_frag_pos, out_camera_pos;
9
- out vec4 outputFragColor;
10
- flat in int out_has_texture;
11
-
12
- uniform sampler2D diffuse_texture;
13
-
14
- void main() {
15
- vec3 result;
16
-
17
- if (out_has_texture == 0) {
18
- result = out_color;
19
- } else {
20
- result = texture(diffuse_texture, out_uv.xy).xyz + 0.25;
21
- }
22
-
23
- fragPosition = out_position;
24
- fragColor = vec4(result, 1.0);
25
- fragNormal = out_normal;
26
- fragUV = out_uv;
27
-
28
- float gamma = 2.2;
29
- outputFragColor.rgb = pow(fragColor.rgb, vec3(1.0 / gamma));
30
- }
1
+ # version 330 core
2
+
3
+ layout(location = 0) out vec3 fragPosition;
4
+ layout (location = 1) out vec4 fragColor;
5
+ layout (location = 2) out vec3 fragNormal;
6
+ layout (location = 3) out vec3 fragUV;
7
+
8
+ in vec3 out_position, out_color, out_normal, out_uv, out_frag_pos, out_camera_pos;
9
+ out vec4 outputFragColor;
10
+ flat in int out_has_texture;
11
+
12
+ uniform sampler2D diffuse_texture;
13
+
14
+ void main() {
15
+ vec3 result;
16
+
17
+ if (out_has_texture == 0) {
18
+ result = out_color;
19
+ } else {
20
+ result = texture(diffuse_texture, out_uv.xy).xyz + 0.25;
21
+ }
22
+
23
+ fragPosition = out_position;
24
+ fragColor = vec4(result, 1.0);
25
+ fragNormal = out_normal;
26
+ fragUV = out_uv;
27
+
28
+ float gamma = 2.2;
29
+ outputFragColor.rgb = pow(fragColor.rgb, vec3(1.0 / gamma));
30
+ }
@@ -1,69 +1,115 @@
1
- #version 330 core
2
- out vec4 frag_color;
3
-
4
- @include "light_struct"
5
- const int DIRECTIONAL = 0;
6
- const int POINT = 1;
7
- const int SPOT = 2;
8
-
9
- flat in Light out_lights[7];
10
- in vec2 out_tex_coords;
11
- flat in int out_light_count;
12
-
13
- uniform sampler2D diffuse, position, texcoord, normal, depth;
14
-
15
- vec4 directionalLight(Light light) {
16
- vec3 norm = normalize(texture(normal, out_tex_coords).rgb);
17
- vec3 diffuse_color = texture(diffuse, out_tex_coords).rgb;
18
- vec3 frag_pos = texture(position, out_tex_coords).rgb;
19
-
20
- vec3 lightDir = normalize(light.position - frag_pos);
21
- float diff = max(dot(norm, lightDir), 0);
22
-
23
- vec3 _ambient = light.ambient;
24
- vec3 _diffuse = light.diffuse * diff;
25
- vec3 _specular = light.specular;
26
-
27
- return vec4(_diffuse + _ambient + _specular, 1.0);
28
- }
29
-
30
- vec4 pointLight(Light light) {
31
- return vec4(0.25, 0.25, 0.25, 1);
32
- }
33
-
34
- vec4 spotLight(Light light) {
35
- return vec4(0.5, 0.5, 0.5, 1);
36
- }
37
-
38
- vec4 calculateLighting(Light light) {
39
- vec4 result;
40
-
41
- // switch(light.type) {
42
- // case DIRECTIONAL: {
43
- // result = directionalLight(light);
44
- // }
45
- // case SPOT: {
46
- // result = spotLight(light);
47
- // }
48
- // default: {
49
- // result = pointLight(light);
50
- // }
51
- // }
52
-
53
- if (light.type == DIRECTIONAL) {
54
- result = directionalLight(light);
55
- } else {
56
- result = pointLight(light);
57
- }
58
-
59
- return result;
60
- }
61
-
62
- void main() {
63
- frag_color = vec4(0.0);
64
-
65
- for(int i = 0; i < out_light_count; i++)
66
- {
67
- frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
68
- }
69
- }
1
+ #version 330 core
2
+ @include "light_struct"
3
+
4
+ out vec4 frag_color;
5
+
6
+ const int DIRECTIONAL = 0;
7
+ const int POINT = 1;
8
+ const int SPOT = 2;
9
+
10
+ in vec2 out_tex_coords;
11
+ flat in int out_light_count;
12
+ flat in Light out_lights[7];
13
+
14
+ uniform sampler2D diffuse, position, texcoord, normal, depth;
15
+
16
+ vec4 directionalLight(Light light) {
17
+ vec3 norm = normalize(texture(normal, out_tex_coords).rgb);
18
+ vec3 diffuse_color = texture(diffuse, out_tex_coords).rgb;
19
+ vec3 frag_pos = texture(position, out_tex_coords).rgb;
20
+
21
+ vec3 lightDir = normalize(light.position - frag_pos);
22
+ float diff = max(dot(norm, lightDir), 0);
23
+
24
+ vec3 _ambient = light.ambient;
25
+ vec3 _diffuse = light.diffuse * diff;
26
+ vec3 _specular = light.specular;
27
+
28
+ return vec4(_diffuse + _ambient + _specular, 1.0);
29
+ }
30
+
31
+ void main() {
32
+ Light light;
33
+ light.type = DIRECTIONAL;
34
+
35
+ light.position = vec3(100, 100, 100);
36
+
37
+ light.diffuse = vec3(0.5, 0.5, 0.5);
38
+ light.ambient = vec3(0.8, 0.8, 0.8);
39
+ light.specular = vec3(0.2, 0.2, 0.2);
40
+
41
+ light.intensity = 1.0;
42
+
43
+ frag_color = texture(diffuse, out_tex_coords) * directionalLight(light);
44
+ }
45
+
46
+ // #version 330 core
47
+ // @include "light_struct"
48
+
49
+ // out vec4 frag_color;
50
+
51
+ // const int DIRECTIONAL = 0;
52
+ // const int POINT = 1;
53
+ // const int SPOT = 2;
54
+
55
+ // in vec2 out_tex_coords;
56
+ // flat in int out_light_count;
57
+ // flat in Light out_lights[7];
58
+
59
+ // uniform sampler2D diffuse, position, texcoord, normal, depth;
60
+
61
+ // vec4 directionalLight(Light light) {
62
+ // vec3 norm = normalize(texture(normal, out_tex_coords).rgb);
63
+ // vec3 diffuse_color = texture(diffuse, out_tex_coords).rgb;
64
+ // vec3 frag_pos = texture(position, out_tex_coords).rgb;
65
+
66
+ // vec3 lightDir = normalize(light.position - frag_pos);
67
+ // float diff = max(dot(norm, lightDir), 0);
68
+
69
+ // vec3 _ambient = light.ambient;
70
+ // vec3 _diffuse = light.diffuse * diff;
71
+ // vec3 _specular = light.specular;
72
+
73
+ // return vec4(_diffuse + _ambient + _specular, 1.0);
74
+ // }
75
+
76
+ // vec4 pointLight(Light light) {
77
+ // return vec4(0.25, 0.25, 0.25, 1);
78
+ // }
79
+
80
+ // vec4 spotLight(Light light) {
81
+ // return vec4(0.5, 0.5, 0.5, 1);
82
+ // }
83
+
84
+ // vec4 calculateLighting(Light light) {
85
+ // vec4 result;
86
+
87
+ // // switch(light.type) {
88
+ // // case DIRECTIONAL: {
89
+ // // result = directionalLight(light);
90
+ // // }
91
+ // // case SPOT: {
92
+ // // result = spotLight(light);
93
+ // // }
94
+ // // default: {
95
+ // // result = pointLight(light);
96
+ // // }
97
+ // // }
98
+
99
+ // if (light.type == DIRECTIONAL) {
100
+ // result = directionalLight(light);
101
+ // } else {
102
+ // result = pointLight(light);
103
+ // }
104
+
105
+ // return result;
106
+ // }
107
+
108
+ // void main() {
109
+ // frag_color = vec4(0.0);
110
+
111
+ // for(int i = 0; i < out_light_count; i++)
112
+ // {
113
+ // frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
114
+ // }
115
+ // }
@@ -1,11 +1,11 @@
1
- struct Light {
2
- int type;
3
- vec3 direction;
4
- vec3 position;
5
-
6
- vec3 diffuse;
7
- vec3 ambient;
8
- vec3 specular;
9
-
10
- float intensity;
11
- };
1
+ struct Light {
2
+ int type;
3
+ vec3 direction;
4
+ vec3 position;
5
+
6
+ vec3 diffuse;
7
+ vec3 ambient;
8
+ vec3 specular;
9
+
10
+ float intensity;
11
+ };
@@ -1,16 +1,16 @@
1
- struct Material {
2
- vec3 color;
3
- vec3 roughness;
4
- vec3 metalic;
5
- vec3 specular;
6
-
7
- bool use_color_texture;
8
- bool use_roughness_texture;
9
- bool use_metalic_texture;
10
- bool use_specular_texture;
11
-
12
- sampler2D color_tex;
13
- sampler2D roughness_tex;
14
- sampler2D metalic_tex;
15
- sampler2D specular_tex;
16
- };
1
+ struct Material {
2
+ vec3 color;
3
+ vec3 roughness;
4
+ vec3 metalic;
5
+ vec3 specular;
6
+
7
+ bool use_color_texture;
8
+ bool use_roughness_texture;
9
+ bool use_metalic_texture;
10
+ bool use_specular_texture;
11
+
12
+ sampler2D color_tex;
13
+ sampler2D roughness_tex;
14
+ sampler2D metalic_tex;
15
+ sampler2D specular_tex;
16
+ };