diff --git a/assets/ms_fragment.txt b/assets/ms_fragment.txt index e6e494c..1ff2249 100755 --- a/assets/ms_fragment.txt +++ b/assets/ms_fragment.txt @@ -3,14 +3,46 @@ varying vec4 color; varying vec3 position; uniform vec4 lineParams; +uniform vec4 startPointEndPoint; void main() { float a = lineParams.x; float b = lineParams.y; float c = lineParams.z; - - float distance = abs(a*position.x + b*position.y + c); - gl_FragColor = vec4(color.rgb, color.a*clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0)); + float Xa = startPointEndPoint.r; + float Ya = startPointEndPoint.g; + + float Xb = startPointEndPoint.b; + float Yb = startPointEndPoint.a; + + + + float distance; + + + float distanceToA = (Xa - position.x)*(Xb - Xa) + (Ya - position.y)*(Yb - Ya); + + float distanceToB = (Xb - position.x)*(Xb - Xa) + (Yb - position.y)*(Yb - Ya); + + + + if (distanceToA * distanceToB > 0) + { + float len = sqrt((Xb - Xa)*(Xb - Xa) + (Yb - Ya)*(Yb - Ya)); + distance = max(abs(distanceToA/len), abs(distanceToB/len)); + } + else + { + distance = abs(a*position.x + b*position.y + c); + } + + + float t = clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0); + + + gl_FragColor = vec4(color.rgb, color.a*t); + + //gl_FragColor = vec4(color.rgb*clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0), 1.0); } \ No newline at end of file diff --git a/assets/ms_fragment_x16.txt b/assets/ms_fragment_x16.txt index 81cad5c..e7d3efe 100755 --- a/assets/ms_fragment_x16.txt +++ b/assets/ms_fragment_x16.txt @@ -42,5 +42,6 @@ void main() distance = min(distance, abs(lineParams15.x*position.x + lineParams15.y*position.y + lineParams15.z)); - gl_FragColor = vec4(color.rgb, color.a*clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0)); + //gl_FragColor = vec4(color.rgb, color.a*clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0)); + gl_FragColor = vec4(color.rgb*clamp(1.2 / (distance + 1.0) - 0.5, 0.0, 1.0), 1.0); } \ No newline at end of file diff --git a/game/main_code.cpp b/game/main_code.cpp index 636becc..fe3242a 100644 --- a/game/main_code.cpp +++ b/game/main_code.cpp @@ -11,7 +11,11 @@ TMyApplication* Application; -#define USE_SHADER_X16 +//static const float BUFFER_DISTANCE = 30.f; +static const float BUFFER_DISTANCE = 50.f; + + +//#define USE_SHADER_X16 #ifdef USE_SHADER_X16 @@ -19,6 +23,8 @@ TMyApplication* Application; std::vector linesToRenderBoxesX16(const std::vector>& lineArr) { + + std::vector lineRenderPairArr; size_t boxCount = lineArr.size() / 16; @@ -53,12 +59,12 @@ std::vector linesToRenderBoxesX16(const std::vector linesToRenderBoxes(const std::vector(startPoint(0), endPoint(0)) - BUFFER_DISTANCE, std::min(startPoint(1), endPoint(1)) - BUFFER_DISTANCE }; + Vector2f renderAreEnd{ std::max(startPoint(0), endPoint(0)) + BUFFER_DISTANCE, std::max(startPoint(1), endPoint(1)) + BUFFER_DISTANCE }; + + pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreaStart(0), renderAreaStart(1), 0)); + pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreaStart(0), renderAreEnd(1), 0)); + pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreEnd(0), renderAreEnd(1), 0)); + pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreaStart(0), renderAreaStart(1), 0)); + pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreEnd(0), renderAreEnd(1), 0)); + pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(renderAreEnd(0), renderAreaStart(1), 0)); + + + /* pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), startPoint(1), 0)); pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), endPoint(1), 0)); pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), endPoint(1), 0)); pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(startPoint(0), startPoint(1), 0)); pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), endPoint(1), 0)); pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(endPoint(0), startPoint(1), 0)); + */ + pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); + pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); + pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); + pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); + pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); + pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 0, 0, 1)); @@ -138,10 +163,14 @@ std::vector linesToRenderBoxes(const std::vector