Compare commits

..
Author SHA1 Message Date
alexander.biryukov c5c53f1e2b Scale by mouse scroll 2018-06-04 13:10:07 +05:00
vladislav.khorev 747bfaba7c Update code to engine fixed 2018-04-12 18:19:08 +03:00
vladislav.khorev f70741f6e6 Finishing antialiasing 2018-04-11 17:16:37 +03:00
vladislav.khorev b2a0901369 Update shader 2018-04-11 16:40:22 +03:00
vladislav.khorev 75b76fc236 New antialiasing made 2018-01-14 03:17:27 +03:00
vladislav.khorev bf04c70f50 Set SMAA antialiasing 2018-01-06 00:51:05 +03:00
7 changed files with 181 additions and 95 deletions

No files matched your search

+1
View File
@@ -73,5 +73,6 @@ iOSInjectionProject/
/windows/DoubleHitBalls-win/DoubleHitBalls-win/log.txt
/windows/DoubleHitBalls-win/DoubleHitBalls-win/progress.txt
/windows/DoubleHitBalls-win/DoubleHitBalls-win/resources
/windows/DoubleHitBalls-win/**/*.user
*.db
*.opendb
+52
View File
@@ -0,0 +1,52 @@
precision mediump float;
varying vec4 color;
varying vec3 position;
//uniform vec4 lineParams;
//uniform vec4 startPointEndPoint;
varying vec3 lineParams;
varying vec4 startPointEndPoint;
void main()
{
float a = lineParams.x;
float b = lineParams.y;
float c = lineParams.z;
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);
}
+22
View File
@@ -0,0 +1,22 @@
attribute vec3 vPosition;
attribute vec4 vColor;
attribute vec3 vLineParams;
attribute vec4 vStartPointEndPoint;
varying vec3 position;
varying vec4 color;
varying vec3 lineParams;
varying vec4 startPointEndPoint;
uniform mat4 ProjectionMatrix;
void main()
{
gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0);
position = vPosition;
color = vColor;
lineParams = vLineParams;
startPointEndPoint = vStartPointEndPoint;
}
+1 -1
View File
@@ -7,7 +7,7 @@ void main()
{
vec4 color = texture2D(Texture,texCoord).rgba;
gl_FragColor = vec4(color.rgb, color.a * Transparency);
gl_FragColor = vec4(color.rgb, 1.0);
Regular → Executable
+97 -89
View File
@@ -11,6 +11,73 @@
TMyApplication* Application;
static const float BUFFER_DISTANCE = 50.f;
TRenderPair linesToRenderBoxes(const std::vector<std::pair<Vector2f, Vector2f>>& lineArr)
{
TRenderPair pair;
for (size_t i = 0; i < lineArr.size(); i++)
{
Vector2f startPoint = lineArr[i].first;
Vector2f endPoint = lineArr[i].second;
Vector2f renderAreaStart{ std::min<float>(startPoint(0), endPoint(0)) - BUFFER_DISTANCE, std::min<float>(startPoint(1), endPoint(1)) - BUFFER_DISTANCE };
Vector2f renderAreEnd{ std::max<float>(startPoint(0), endPoint(0)) + BUFFER_DISTANCE, std::max<float>(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.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));
Vector2f lineVec = endPoint - startPoint;
Vector2f lineNormVec = { -lineVec(1), lineVec(0) };
lineNormVec.normalize();
//float distance = abs(normVec.x*(position.x - startPoint.x) + normVec.y*(position.y - startPoint.y));
//distance = a*x + b*y + c, here we calculate a, b,c and pass them to shader
float a = lineNormVec(0);
float b = lineNormVec(1);
float c = -(lineNormVec(0)*startPoint(0) + lineNormVec(1)*startPoint(1));
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
pair.second.Data.Vec3CoordArr["vLineParams"].push_back(Vector3f(a, b, c));
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
pair.second.Data.Vec4CoordArr["vStartPointEndPoint"].push_back(Vector4f(startPoint(0), startPoint(1), endPoint(0), endPoint(1)));
}
pair.second.RefreshBuffer();
pair.first = TRenderParams().withShader("AntialiasingShader");
return pair;
}
void TMyApplication::InnerInit()
{
@@ -19,7 +86,8 @@ void TMyApplication::InnerInit()
#ifdef TARGET_WIN32
#ifdef NDEBUG
ST::PathToResources = "resources/";
//ST::PathToResources = "resources/";
ST::PathToResources = "../../../assets/";
#else
ST::PathToResources = "../../../assets/";
#endif
@@ -35,63 +103,36 @@ void TMyApplication::InnerInit()
}
srand (static_cast<size_t>(time(NULL)));
ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt");
ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt");
ResourceManager->ShaderManager.AddShader("ColorShader", "color_vertex.txt", "color_fragment.txt");
ResourceManager->ShaderManager.AddShader("SSAA_4X", "SSAA_4X.vertex", "SSAA_4X.frag");
Renderer->PushShader("DefaultShader");
ResourceManager->ShaderManager.AddShader("AntialiasingShader", "ms_vertex.txt", "ms_fragment.txt");
ResourceManager->TexList.AddTexture("console_bkg.bmp");
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
std::vector<std::pair<Vector2f, Vector2f>> lineArr;
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 0, 0));
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 512, 0));
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 512, 0));
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 0, 0));
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 512, 0));
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 0, 0));
for (int i = 0; i < 10; i++)
{
lineArr.push_back({ {50.f + i * 20.f, 50.f}, { 60.f + i * 20.f, 440.f } });
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(0, 1, 0, 1));
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(0, 0, 1, 1));
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(0, 0, 1, 1));
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(0, 1, 0, 1));
pair.first.ShaderName = "ColorShader";
pair.second.RefreshBuffer();
lineArr.push_back({ { 60.f + i * 20.f, 440.f },{ 70.f + i * 20.f, 50.f } });
};
lineRenderPair = linesToRenderBoxes(lineArr);
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 0, 0));
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 512, 0));
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 512, 0));
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 512, 0));
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 0, 0));
rect.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(0, 0, 0));
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 1));
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1, 1));
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1, 1));
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1, 0));
rect.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
rect.second.RefreshBuffer();
Renderer->PushShader("AntialiasingShader");
Renderer->SetOrthoProjection();
Renderer->SetFullScreenViewport();
Inited = true;
}
void TMyApplication::InnerDeinit()
@@ -102,7 +143,14 @@ void TMyApplication::InnerDeinit()
{
*Console<<"APP DEINIT\n";
}
}
void TMyApplication::OnMouseWheel(short int delta)
{
scale += (delta > 0 ? 1 : -1) * 0.25;
if(scale < 0.25) {
scale = 0.25;
}
}
void TMyApplication::InnerOnTapDown(Vector2f p)
@@ -133,62 +181,22 @@ void TMyApplication::OnFling(Vector2f v)
void TMyApplication::InnerDraw()
{
Renderer->SwitchToFrameBuffer("LevelBuffer");
//Render the frame
Renderer->SetProjectionMatrix(512.f, 512.f);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
Renderer->PushMatrix();
Renderer->ScaleMatrix(scale);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
CheckGlError("");
TRenderParamsSetter params(lineRenderPair.first);
Renderer->DrawTriangleList(lineRenderPair.second);
{
TRenderParamsSetter params(pair.first);
Renderer->DrawTriangleList(pair.second);
}
Renderer->PopMatrix();
CheckGlError("");
Renderer->SwitchToScreen();
Renderer->SetFullScreenViewport();
const float cos30 = sqrt(3) / 2;
const float sin30 = 0.5f;
const float sampleRadiusX = 0.75 / 512;
const float sampleRadiusY = 0.75 / 512;
Matrix2f rotate30Matrix;
rotate30Matrix(0, 0) = cos30;
rotate30Matrix(0, 1) = sin30;
rotate30Matrix(1, 0) = -sin30;
rotate30Matrix(1, 1) = cos30;
Renderer->PushShader("SSAA_4X");
std::array<Vector2f, 4> sampleVector = {
Vector2f(sampleRadiusX, sampleRadiusY),
Vector2f(-sampleRadiusX, sampleRadiusY),
Vector2f(-sampleRadiusX, -sampleRadiusY),
Vector2f(sampleRadiusX, -sampleRadiusY)
};
for (size_t i = 0; i < 4; i++)
{
sampleVector[i] = rotate30Matrix * sampleVector[i];
RenderUniform2fv("samplesOffset[" + boost::lexical_cast<std::string>(i) + "]", &sampleVector[i][0]);
}
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("LevelBuffer"));
Renderer->DrawTriangleList(rect.second);
Renderer->PopShader();
CheckGlError("");
}
Regular → Executable
+4 -2
View File
@@ -32,9 +32,10 @@ protected:
bool Inited;
float scale = 1.0;
public:
TRenderPair pair;
TRenderPair rect;
TRenderPair lineRenderPair;
bool Loaded;
@@ -52,6 +53,7 @@ public:
bool IsInited();
virtual void OnMouseWheel(short int delta);
virtual void InnerOnTapDown(Vector2f p);
@@ -22,6 +22,7 @@
<ProjectGuid>{1CC98EEE-BBCB-4D79-B6D7-8511789172C5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DoubleHitBallswin</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -48,7 +49,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -150,7 +151,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;TARGET_WIN32;_WIN32_WINNT=0x0501;WIN32_LEAN_AND_MEAN;EIGEN_DONT_ALIGN_STATICALLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_63_0/;../../../../boost_1_63_0/bin.v2/libs/system/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/date_time/build/msvc-14.0/release/address-model-64/link-static/threading-multi/;../../../../boost_1_63_0/bin.v2/libs/regex/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/thread/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/chrono/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/signals/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_67_0/;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4503</DisableSpecificWarnings>
</ClCompile>
<Link>
@@ -158,7 +159,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_63_0/stage/x64/lib;../../../../boost_1_63_0/bin.v2/libs/system/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/date_time/build/msvc-14.0/release/address-model-64/link-static/threading-multi/;../../../../boost_1_63_0/bin.v2/libs/regex/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/thread/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/chrono/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/signals/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510;../x64/Release</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_67_0/stage/lib;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510;../x64/Release</AdditionalLibraryDirectories>
<AdditionalDependencies>libjpeg.lib;libpng.lib;Engine.lib;opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>