From 24fd919de3dc811c9b8a833ff10bd8c0e8b5ec65 Mon Sep 17 00:00:00 2001 From: Alexander Biryukov Date: Thu, 31 May 2018 19:47:36 +0500 Subject: [PATCH] Coloring --- assets/lines.json | 843 +-------------------------------- assets/simple_shading.fragment | 3 +- assets/simple_shading.vertex | 3 + game/main_code.cpp | 24 +- 4 files changed, 24 insertions(+), 849 deletions(-) diff --git a/assets/lines.json b/assets/lines.json index d5948e6..6fafc05 100755 --- a/assets/lines.json +++ b/assets/lines.json @@ -1,844 +1,7 @@ { "lines": [ - { - "start": [ - -500, - -500 - ], - "end": [ - 500, - -500 - ] - }, - { - "start": [ - -500, - -488 - ], - "end": [ - 500, - -488 - ] - }, - { - "start": [ - -500, - -476 - ], - "end": [ - 500, - -476 - ] - }, - { - "start": [ - -500, - -464 - ], - "end": [ - 500, - -464 - ] - }, - { - "start": [ - -500, - -452 - ], - "end": [ - 500, - -452 - ] - }, - { - "start": [ - -500, - -440 - ], - "end": [ - 500, - -440 - ] - }, - { - "start": [ - -500, - -428 - ], - "end": [ - 500, - -428 - ] - }, - { - "start": [ - -500, - -416 - ], - "end": [ - 500, - -416 - ] - }, - { - "start": [ - -500, - -404 - ], - "end": [ - 500, - -404 - ] - }, - { - "start": [ - -500, - -392 - ], - "end": [ - 500, - -392 - ] - }, - { - "start": [ - -500, - -380 - ], - "end": [ - 500, - -380 - ] - }, - { - "start": [ - -500, - -368 - ], - "end": [ - 500, - -368 - ] - }, - { - "start": [ - -500, - -356 - ], - "end": [ - 500, - -356 - ] - }, - { - "start": [ - -500, - -344 - ], - "end": [ - 500, - -344 - ] - }, - { - "start": [ - -500, - -332 - ], - "end": [ - 500, - -332 - ] - }, - { - "start": [ - -500, - -320 - ], - "end": [ - 500, - -320 - ] - }, - { - "start": [ - -500, - -308 - ], - "end": [ - 500, - -308 - ] - }, - { - "start": [ - -500, - -296 - ], - "end": [ - 500, - -296 - ] - }, - { - "start": [ - -500, - -284 - ], - "end": [ - 500, - -284 - ] - }, - { - "start": [ - -500, - -272 - ], - "end": [ - 500, - -272 - ] - }, - { - "start": [ - -500, - -260 - ], - "end": [ - 500, - -260 - ] - }, - { - "start": [ - -500, - -248 - ], - "end": [ - 500, - -248 - ] - }, - { - "start": [ - -500, - -236 - ], - "end": [ - 500, - -236 - ] - }, - { - "start": [ - -500, - -224 - ], - "end": [ - 500, - -224 - ] - }, - { - "start": [ - -500, - -212 - ], - "end": [ - 500, - -212 - ] - }, - { - "start": [ - -500, - -200 - ], - "end": [ - 500, - -200 - ] - }, - { - "start": [ - -500, - -188 - ], - "end": [ - 500, - -188 - ] - }, - { - "start": [ - -500, - -176 - ], - "end": [ - 500, - -176 - ] - }, - { - "start": [ - -500, - -164 - ], - "end": [ - 500, - -164 - ] - }, - { - "start": [ - -500, - -152 - ], - "end": [ - 500, - -152 - ] - }, - { - "start": [ - -500, - -140 - ], - "end": [ - 500, - -140 - ] - }, - { - "start": [ - -500, - -128 - ], - "end": [ - 500, - -128 - ] - }, - { - "start": [ - -500, - -116 - ], - "end": [ - 500, - -116 - ] - }, - { - "start": [ - -500, - -104 - ], - "end": [ - 500, - -104 - ] - }, - { - "start": [ - -500, - -92 - ], - "end": [ - 500, - -92 - ] - }, - { - "start": [ - -500, - -80 - ], - "end": [ - 500, - -80 - ] - }, - { - "start": [ - -500, - -68 - ], - "end": [ - 500, - -68 - ] - }, - { - "start": [ - -500, - -56 - ], - "end": [ - 500, - -56 - ] - }, - { - "start": [ - -500, - -44 - ], - "end": [ - 500, - -44 - ] - }, - { - "start": [ - -500, - -32 - ], - "end": [ - 500, - -32 - ] - }, - { - "start": [ - -500, - -20 - ], - "end": [ - 500, - -20 - ] - }, - { - "start": [ - -500, - -8 - ], - "end": [ - 500, - -8 - ] - }, - { - "start": [ - -500, - 4 - ], - "end": [ - 500, - 4 - ] - }, - { - "start": [ - -500, - 16 - ], - "end": [ - 500, - 16 - ] - }, - { - "start": [ - -500, - 28 - ], - "end": [ - 500, - 28 - ] - }, - { - "start": [ - -500, - 40 - ], - "end": [ - 500, - 40 - ] - }, - { - "start": [ - -500, - 52 - ], - "end": [ - 500, - 52 - ] - }, - { - "start": [ - -500, - 64 - ], - "end": [ - 500, - 64 - ] - }, - { - "start": [ - -500, - 76 - ], - "end": [ - 500, - 76 - ] - }, - { - "start": [ - -500, - 88 - ], - "end": [ - 500, - 88 - ] - }, - { - "start": [ - -500, - 100 - ], - "end": [ - 500, - 100 - ] - }, - { - "start": [ - -500, - 112 - ], - "end": [ - 500, - 112 - ] - }, - { - "start": [ - -500, - 124 - ], - "end": [ - 500, - 124 - ] - }, - { - "start": [ - -500, - 136 - ], - "end": [ - 500, - 136 - ] - }, - { - "start": [ - -500, - 148 - ], - "end": [ - 500, - 148 - ] - }, - { - "start": [ - -500, - 160 - ], - "end": [ - 500, - 160 - ] - }, - { - "start": [ - -500, - 172 - ], - "end": [ - 500, - 172 - ] - }, - { - "start": [ - -500, - 184 - ], - "end": [ - 500, - 184 - ] - }, - { - "start": [ - -500, - 196 - ], - "end": [ - 500, - 196 - ] - }, - { - "start": [ - -500, - 208 - ], - "end": [ - 500, - 208 - ] - }, - { - "start": [ - -500, - 220 - ], - "end": [ - 500, - 220 - ] - }, - { - "start": [ - -500, - 232 - ], - "end": [ - 500, - 232 - ] - }, - { - "start": [ - -500, - 244 - ], - "end": [ - 500, - 244 - ] - }, - { - "start": [ - -500, - 256 - ], - "end": [ - 500, - 256 - ] - }, - { - "start": [ - -500, - 268 - ], - "end": [ - 500, - 268 - ] - }, - { - "start": [ - -500, - 280 - ], - "end": [ - 500, - 280 - ] - }, - { - "start": [ - -500, - 292 - ], - "end": [ - 500, - 292 - ] - }, - { - "start": [ - -500, - 304 - ], - "end": [ - 500, - 304 - ] - }, - { - "start": [ - -500, - 316 - ], - "end": [ - 500, - 316 - ] - }, - { - "start": [ - -500, - 328 - ], - "end": [ - 500, - 328 - ] - }, - { - "start": [ - -500, - 340 - ], - "end": [ - 500, - 340 - ] - }, - { - "start": [ - -500, - 352 - ], - "end": [ - 500, - 352 - ] - }, - { - "start": [ - -500, - 364 - ], - "end": [ - 500, - 364 - ] - }, - { - "start": [ - -500, - 376 - ], - "end": [ - 500, - 376 - ] - }, - { - "start": [ - -500, - 388 - ], - "end": [ - 500, - 388 - ] - }, - { - "start": [ - -500, - 400 - ], - "end": [ - 500, - 400 - ] - }, - { - "start": [ - -500, - 412 - ], - "end": [ - 500, - 412 - ] - }, - { - "start": [ - -500, - 424 - ], - "end": [ - 500, - 424 - ] - }, - { - "start": [ - -500, - 436 - ], - "end": [ - 500, - 436 - ] - }, - { - "start": [ - -500, - 448 - ], - "end": [ - 500, - 448 - ] - }, - { - "start": [ - -500, - 460 - ], - "end": [ - 500, - 460 - ] - }, - { - "start": [ - -500, - 472 - ], - "end": [ - 500, - 472 - ] - }, - { - "start": [ - -500, - 484 - ], - "end": [ - 500, - 484 - ] - }, - { - "start": [ - -500, - 496 - ], - "end": [ - 500, - 496 - ] - } + {"start": [-500, -500], "end": [500, -500], "color": [0.3, 0.3, 0.0]}, + {"start": [500, -500], "end": [500, 500], "color": [0.0, 0.3, 0.15]}, + {"start": [500, 500], "end": [-500, -500], "color": [0.25, 0, 0.4]} ] } \ No newline at end of file diff --git a/assets/simple_shading.fragment b/assets/simple_shading.fragment index 731b433..5c70e01 100755 --- a/assets/simple_shading.fragment +++ b/assets/simple_shading.fragment @@ -6,11 +6,12 @@ uniform vec4 LightDirection; varying vec2 texCoord; varying vec3 fragNormal; +varying vec3 fragColor; void main() { vec4 color = texture2D(Texture, texCoord).rgba; float intensity = dot(normalize(LightDirection.xyz), -normalize(fragNormal)); - gl_FragColor = vec4(color.rgb * intensity*0.5 + vec3(0.5, 0.5, 0.5), color.a * Transparency); + gl_FragColor = vec4(color.rgb * fragColor.rgb * intensity + vec3(0.5, 0.5, 0.5), color.a * Transparency); //gl_FragColor = vec4((fragNormal.rgb + vec3(1.0, 1.0, 1.0))*0.5, 1.0); } diff --git a/assets/simple_shading.vertex b/assets/simple_shading.vertex index c070b5b..dce1d96 100755 --- a/assets/simple_shading.vertex +++ b/assets/simple_shading.vertex @@ -1,14 +1,17 @@ attribute vec3 vPosition; attribute vec3 Normal; attribute vec2 vTexCoord; +attribute vec3 vColor; uniform mat4 ProjectionMatrix; varying vec2 texCoord; varying vec3 fragNormal; +varying vec3 fragColor; void main() { gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0); texCoord = vTexCoord; fragNormal = Normal; + fragColor = vColor; } diff --git a/game/main_code.cpp b/game/main_code.cpp index 2b5fbfe..a30c19e 100755 --- a/game/main_code.cpp +++ b/game/main_code.cpp @@ -169,14 +169,12 @@ void TMyApplication::InnerInit() size_t const threadsCount = 3; size_t const edgesCount = 6; float const angle = pi / 6; - size_t const iterationsCount = 60; Vector3f up(0, 1, 0); up.normalize(); size_t const step = 5; - auto g = [this, findPlaneBasis, R, r, threadsCount, edgesCount, up, angle, step] (Vector3f start, Vector3f end) { - size_t iterationsCount = (end - start).norm() / step; + auto g = [this, findPlaneBasis, R, r, threadsCount, edgesCount, up, angle, step] (Vector3f start, Vector3f end, const Vector3f &color) { Vector3f direction = (end - start).normalized(); - start = start + (r + R) * direction; end = end - (r + R) * direction; + size_t iterationsCount = (end - start).norm() / step; auto e = findPlaneBasis(up); std::vector threadCenters; @@ -264,7 +262,6 @@ void TMyApplication::InnerInit() fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk1); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk); - fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk1); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk1); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk); @@ -272,7 +269,6 @@ void TMyApplication::InnerInit() fabricRender.second.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB].push_back((vk - threadCenter)); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB].push_back((vk1 - threadCenter)); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB].push_back((nvk - newThreadCenter)); - fabricRender.second.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB].push_back((vk1 - threadCenter)); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB].push_back((nvk1 - newThreadCenter)); fabricRender.second.Data.Vec3CoordArr[CONST_STRING_NORMAL_ATTRIB].push_back((nvk - newThreadCenter)); @@ -280,10 +276,17 @@ void TMyApplication::InnerInit() fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.1, 0.1)); fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.2, 0.1)); fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.1, 0.2)); - fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.2, 0.1)); fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.2, 0.2)); fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.1, 0.2)); + + fabricRender.second.Data.Vec3CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(color); + fabricRender.second.Data.Vec3CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(color); + fabricRender.second.Data.Vec3CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(color); + fabricRender.second.Data.Vec3CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(color); + fabricRender.second.Data.Vec3CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(color); + fabricRender.second.Data.Vec3CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(color); + } } @@ -299,6 +302,7 @@ void TMyApplication::InnerInit() for(auto line: root.get_child("lines")) { std::vector start; std::vector end; + std::vector color; for(auto value: line.second.get_child("start")) { start.push_back(value.second.get_value()); @@ -308,7 +312,11 @@ void TMyApplication::InnerInit() end.push_back(value.second.get_value()); } - g(Vector3f(start[0], 0, start[1]), Vector3f(end[0], 0, end[1])); + for (auto value : line.second.get_child("color")) { + color.push_back(value.second.get_value()); + } + + g(Vector3f(start[0], 0, start[1]), Vector3f(end[0], 0, end[1]), Vector3f(color[0], color[1], color[2])); } }