Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf04c70f50 |
No files matched your search
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 772 KiB |
|
Before Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 2.5 MiB |
|
Before Width: | Height: | Size: 180 KiB |
|
Before Width: | Height: | Size: 1.7 MiB |
|
Before Width: | Height: | Size: 1.7 MiB |
|
Before Width: | Height: | Size: 4.4 MiB |
|
Before Width: | Height: | Size: 819 KiB |
@@ -1,68 +0,0 @@
|
||||
precision mediump float;
|
||||
uniform sampler2D Texture;
|
||||
uniform sampler2D NormalMap;
|
||||
uniform sampler2D HeightMap;
|
||||
|
||||
precision highp float;
|
||||
|
||||
varying vec2 frag_uv;
|
||||
varying vec3 ts_light_pos;
|
||||
varying vec3 ts_view_pos;
|
||||
varying vec3 ts_frag_pos;
|
||||
|
||||
const float num_layers = 8.0;
|
||||
|
||||
const float depth_scale = 0.002;
|
||||
|
||||
|
||||
|
||||
vec2 parallax_uv(vec2 uv, vec3 view_dir)
|
||||
{
|
||||
|
||||
float layer_depth = 1.0 / num_layers;
|
||||
float cur_layer_depth = 0.0;
|
||||
vec2 delta_uv = view_dir.xy * depth_scale / (view_dir.z * num_layers);
|
||||
vec2 cur_uv = uv;
|
||||
|
||||
float depth_from_tex = texture2D(HeightMap, cur_uv).r;
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
cur_layer_depth += layer_depth;
|
||||
cur_uv -= delta_uv;
|
||||
depth_from_tex = texture2D(HeightMap, cur_uv).r;
|
||||
if (depth_from_tex < cur_layer_depth) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Parallax occlusion mapping
|
||||
vec2 prev_uv = cur_uv + delta_uv;
|
||||
float next = depth_from_tex - cur_layer_depth;
|
||||
float prev = texture2D(HeightMap, prev_uv).r - cur_layer_depth
|
||||
+ layer_depth;
|
||||
float weight = next / (next - prev);
|
||||
return mix(cur_uv, prev_uv, weight);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 light_dir = normalize(ts_light_pos - ts_frag_pos);
|
||||
vec3 view_dir = normalize(ts_view_pos - ts_frag_pos);
|
||||
|
||||
// Only perturb the texture coordinates if a parallax technique is selected
|
||||
vec2 uv = parallax_uv(frag_uv, view_dir);
|
||||
//vec2 uv = frag_uv;
|
||||
|
||||
vec3 albedo = texture2D(Texture, uv).rgb;
|
||||
|
||||
vec3 ambient = 0.3 * albedo;
|
||||
|
||||
// Normal mapping
|
||||
vec3 norm = normalize(texture2D(NormalMap, uv).rgb * 2.0 - 1.0);
|
||||
float diffuse = max(dot(light_dir, norm), 0.0);
|
||||
gl_FragColor = vec4(diffuse * albedo + ambient, 1.0);
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec2 vTexCoord;
|
||||
|
||||
uniform vec3 eye;
|
||||
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat3 NormalMatrix;
|
||||
uniform mat4 ProjectionMatrix1;
|
||||
uniform mat3 ModelViewMatrix3x3;
|
||||
|
||||
varying vec2 frag_uv;
|
||||
varying vec3 ts_light_pos; // Tangent space values
|
||||
varying vec3 ts_view_pos; //
|
||||
varying vec3 ts_frag_pos; //
|
||||
|
||||
|
||||
mat3 transpose(in mat3 inMatrix)
|
||||
{
|
||||
vec3 i0 = inMatrix[0];
|
||||
vec3 i1 = inMatrix[1];
|
||||
vec3 i2 = inMatrix[2];
|
||||
|
||||
mat3 outMatrix = mat3(
|
||||
vec3(i0.x, i1.x, i2.x),
|
||||
vec3(i0.y, i1.y, i2.y),
|
||||
vec3(i0.z, i1.z, i2.z)
|
||||
);
|
||||
|
||||
return outMatrix;
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 vert_norm = vec3(0, 1, 0);
|
||||
vec3 vert_tang = vec3(1, 0, 0);
|
||||
vec3 vert_bitang = vec3(0, 0, 1);
|
||||
|
||||
mat4 mvp = ProjectionMatrix1 * ModelViewMatrix;
|
||||
|
||||
gl_Position = mvp * vec4(vPosition.xyz, 1.0);
|
||||
|
||||
ts_frag_pos = vec3(ModelViewMatrix * vec4(vPosition.xyz, 1.0));
|
||||
|
||||
vec3 t = normalize((NormalMatrix) * vert_tang);
|
||||
vec3 b = normalize((NormalMatrix) * vert_bitang);
|
||||
vec3 n = normalize((NormalMatrix) * vert_norm);
|
||||
mat3 tbn = transpose(mat3(t, b, n));
|
||||
|
||||
|
||||
ts_light_pos = tbn * vec3(1,2,0);
|
||||
|
||||
//ts_view_pos = tbn * eye;
|
||||
ts_view_pos = tbn * vec3(0,0,0);
|
||||
ts_frag_pos = tbn * ts_frag_pos;
|
||||
|
||||
|
||||
frag_uv = vTexCoord;
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
precision mediump float;
|
||||
uniform sampler2D Texture;
|
||||
uniform float Transparency;
|
||||
|
||||
|
||||
varying vec3 position;
|
||||
varying vec3 normal;
|
||||
varying vec2 texCoord;
|
||||
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 cameraPos;
|
||||
uniform vec3 ambientLight;
|
||||
uniform vec3 diffuseLight;
|
||||
uniform vec3 specularLight;
|
||||
uniform float specularPower;
|
||||
|
||||
void phongModel( vec3 norm, out vec3 ambAndDiff, out vec3 spec )
|
||||
{
|
||||
vec3 lightDirection = normalize(vec3(lightPos));
|
||||
vec3 cameraDirection = normalize(vec3(cameraPos) - position);
|
||||
vec3 lightReflection = reflect( -lightDirection, norm );
|
||||
|
||||
float sDotN = max( dot(lightDirection,norm), 0.0 );
|
||||
|
||||
vec3 diffuse = diffuseLight * sDotN;
|
||||
ambAndDiff = ambientLight + diffuse;
|
||||
|
||||
spec = vec3(0.0);
|
||||
if(sDotN > 0.0)
|
||||
{
|
||||
spec = specularLight * pow(max( dot(lightReflection, cameraDirection), 0.0 ), specularPower);
|
||||
// spec is NAN, if dot == 0 && specularPower <= 0
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ambAndDiff, spec;
|
||||
vec3 norm = normalize(normal);
|
||||
|
||||
phongModel(norm, ambAndDiff, spec);
|
||||
|
||||
vec4 textureColor = texture2D(Texture, texCoord).rgba;
|
||||
|
||||
textureColor.r = textureColor.r * ambAndDiff.r + spec.r;
|
||||
textureColor.g = textureColor.g * ambAndDiff.g + spec.g;
|
||||
textureColor.b = textureColor.b * ambAndDiff.b + spec.b;
|
||||
|
||||
gl_FragColor = textureColor;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
attribute vec3 vPosition;
|
||||
attribute vec3 vNormal;
|
||||
attribute vec2 vTexCoord;
|
||||
varying vec3 position;
|
||||
varying vec3 normal;
|
||||
varying vec2 texCoord;
|
||||
|
||||
|
||||
uniform mat4 ProjectionMatrix1;
|
||||
uniform mat4 ModelViewMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
mat4 mvp = ProjectionMatrix1 * ModelViewMatrix;
|
||||
|
||||
vec4 tnorm = ModelViewMatrix * vec4(vNormal,0.0);
|
||||
normal = normalize(vec3(tnorm));
|
||||
|
||||
position = vec3( ModelViewMatrix * vec4(vPosition,1.0) );
|
||||
gl_Position = mvp * vec4(vPosition,1.0);
|
||||
|
||||
|
||||
texCoord = vTexCoord;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,40 +12,14 @@
|
||||
TMyApplication* Application;
|
||||
|
||||
|
||||
#define AREATEX_WIDTH 160
|
||||
#define AREATEX_HEIGHT 560
|
||||
#define SEARCHTEX_WIDTH 66
|
||||
#define SEARCHTEX_HEIGHT 33
|
||||
|
||||
Matrix3f quatToMatrix(Vector4f q) {
|
||||
|
||||
Matrix3f result;
|
||||
|
||||
double sqw = q(3)*q(3);
|
||||
double sqx = q(0)*q(0);
|
||||
double sqy = q(1)*q(1);
|
||||
double sqz = q(2)*q(2);
|
||||
|
||||
// invs (inverse square length) is only required if quaternion is not already normalised
|
||||
double invs = 1 / (sqx + sqy + sqz + sqw);
|
||||
|
||||
result(0,0) = (sqx - sqy - sqz + sqw)*invs; // since sqw + sqx + sqy + sqz =1/invs*invs
|
||||
result(1,1) = (-sqx + sqy - sqz + sqw)*invs;
|
||||
result(2,2) = (-sqx - sqy + sqz + sqw)*invs;
|
||||
|
||||
double tmp1 = q(0)*q(1);
|
||||
double tmp2 = q(2)*q(3);
|
||||
result(1, 0) = 2.0 * (tmp1 + tmp2)*invs;
|
||||
result(0, 1) = 2.0 * (tmp1 - tmp2)*invs;
|
||||
|
||||
tmp1 = q(0)*q(2);
|
||||
tmp2 = q(1)*q(3);
|
||||
result(2,0) = 2.0 * (tmp1 - tmp2)*invs;
|
||||
result(0,2) = 2.0 * (tmp1 + tmp2)*invs;
|
||||
tmp1 = q(1)*q(2);
|
||||
tmp2 = q(0)*q(3);
|
||||
result(2, 1) = 2.0 * (tmp1 + tmp2)*invs;
|
||||
result(1, 2) = 2.0 * (tmp1 - tmp2)*invs;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GLuint area_tex;
|
||||
GLuint search_tex;
|
||||
|
||||
|
||||
void TMyApplication::InnerInit()
|
||||
@@ -74,169 +48,49 @@ void TMyApplication::InnerInit()
|
||||
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");
|
||||
ResourceManager->ShaderManager.AddShader("ParallaxShader", "parallax_vertex.txt", "parallax_fragment.txt");
|
||||
ResourceManager->ShaderManager.AddShader("PhongShader", "phong_vertex.txt", "phong_fragment.txt");
|
||||
|
||||
|
||||
ResourceManager->ShaderManager.AddShader("SmaaEdge", "smaa/edge_vertex.txt", "smaa/edge_fragment.txt");
|
||||
ResourceManager->ShaderManager.AddShader("SmaaBlend", "smaa/blend_vertex.txt", "smaa/blend_fragment.txt");
|
||||
ResourceManager->ShaderManager.AddShader("SmaaNeighborhood", "smaa/neighborhood_vertex.txt", "smaa/neighborhood_fragment.txt");
|
||||
|
||||
Renderer->PushShader("DefaultShader");
|
||||
|
||||
|
||||
ResourceManager->TexList.AddTexture("console_bkg.bmp");
|
||||
|
||||
ResourceManager->TexList.AddTexture("background.jpg");
|
||||
ResourceManager->TexList.AddTexture("HeightMap.png");
|
||||
ResourceManager->TexList.AddTexture("NormalMap.png");
|
||||
ResourceManager->TexList.AddTexture("linesAll.png");
|
||||
|
||||
|
||||
Vector2f const bottomLeft(-500, -500);
|
||||
float const W = 1000;
|
||||
float const H = 1000;
|
||||
|
||||
Vector2f const backgroundBottomLeft(-1000, -1000);
|
||||
float const backgroundW = 2000;
|
||||
float const backgroundH = 2000;
|
||||
ResourceManager->FrameManager.AddFrameRenderBuffer("AlbedoBuffer", 512, 512);
|
||||
ResourceManager->FrameManager.AddFrameRenderBuffer("EdgeBuffer", 512, 512);
|
||||
ResourceManager->FrameManager.AddFrameRenderBuffer("BlendBuffer", 512, 512);
|
||||
|
||||
{
|
||||
//resolution of background image
|
||||
float const imageW = 512;
|
||||
float const imageH = 512;
|
||||
|
||||
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0], 0, backgroundBottomLeft[1]));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0], 0, backgroundBottomLeft[1] + backgroundH));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0] + backgroundW, 0, backgroundBottomLeft[1] + backgroundH));
|
||||
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0] + backgroundW, 0, backgroundBottomLeft[0] + backgroundH));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0] + backgroundW, 0, backgroundBottomLeft[0]));
|
||||
background.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].emplace_back(Vector3f(backgroundBottomLeft[0], 0, backgroundBottomLeft[0]));
|
||||
|
||||
float const tw = W / imageW;
|
||||
float const th = H / imageH;
|
||||
|
||||
background.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Vector2f(0, th));
|
||||
background.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Vector2f(0, 0));
|
||||
background.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Vector2f(tw, 0));
|
||||
|
||||
background.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Vector2f(tw, 0));
|
||||
background.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Vector2f(tw, th));
|
||||
background.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].emplace_back(Vector2f(0, th));
|
||||
|
||||
|
||||
background.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].emplace_back(Vector4f(1, 1, 1, 1));
|
||||
background.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].emplace_back(Vector4f(1, 1, 1, 1));
|
||||
background.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].emplace_back(Vector4f(1, 1, 1, 1));
|
||||
|
||||
background.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].emplace_back(Vector4f(1, 1, 1, 1));
|
||||
background.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].emplace_back(Vector4f(1, 1, 1, 1));
|
||||
background.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].emplace_back(Vector4f(1, 1, 1, 1));
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
//resolution of linesAll.png
|
||||
float const texW = 900;
|
||||
float const texH = 900;
|
||||
|
||||
float const step = 12;
|
||||
float const thick = 10;
|
||||
|
||||
auto f = [this, texW, texH, thick, W, H] (const Vector3f &p1, const Vector3f &p2, float t) {
|
||||
auto pv = p2 - p1;
|
||||
Vector3f ortho(pv[2], 0, pv[0]);
|
||||
ortho.normalize();
|
||||
auto p3 = p2 + ortho * thick;
|
||||
auto p4 = p1 + ortho * thick;
|
||||
|
||||
float extraHeight = std::min(20.f, -(t - 1)*t*100.f);
|
||||
|
||||
|
||||
|
||||
const size_t segmentCount = 20;
|
||||
|
||||
for (int i = 0; i < segmentCount; i++)
|
||||
{
|
||||
auto pStart = p1 + pv * i/ segmentCount;
|
||||
auto pEnd = p1 + pv * (i+1)/ segmentCount;
|
||||
|
||||
auto pStartShifted = pStart + ortho * thick;
|
||||
auto pEndShifted = pEnd + ortho * thick;
|
||||
|
||||
float innerHeightStart = std::min(20.f, -(i / 20.f) * (i / 20.f - 1.f)*100.f);
|
||||
float innerHeightEnd = std::min(20.f, -((i+1) / 20.f) * ((i+1) / 20.f - 1.f)*100.f);
|
||||
|
||||
Vector3f extraShiftStart = { 0, std::min(innerHeightStart, extraHeight), 0 };
|
||||
Vector3f extraShiftEnd = { 0, std::min(innerHeightEnd, extraHeight), 0 };
|
||||
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pStart + extraShiftStart);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pEnd + extraShiftEnd);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pEndShifted + extraShiftEnd);
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pEndShifted + extraShiftEnd);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pStartShifted + extraShiftStart);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(pStart + extraShiftStart);
|
||||
|
||||
auto texThick = thick / texW;
|
||||
auto m = (pStart[0] + pEnd[0]) / 2 / texW;
|
||||
auto yStart = (H / texH)*(i / 20.f);
|
||||
auto yEnd = (H / texH)*((i+1) / 20.f);
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, yStart));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, yEnd));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, yEnd));
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, yEnd));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, yStart));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, yStart));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
Vector3f const stepDirection(1, 0, 0);
|
||||
Vector3f p1(bottomLeft[0], 0, -bottomLeft[1]);
|
||||
|
||||
while (p1[0] < bottomLeft[0] + W) {
|
||||
|
||||
float t = (p1(0) - bottomLeft(0)) / W;
|
||||
|
||||
auto p2 = p1 - Vector3f(0, 0, W);
|
||||
f(p1, p2, t);
|
||||
|
||||
auto p3 = p1 + step * stepDirection;
|
||||
f(p3, p2, t);
|
||||
|
||||
p1 = p3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//background.first.ShaderName ="ParallaxShader";
|
||||
//DefaultShader
|
||||
background.first.ShaderName = "DefaultShader";
|
||||
|
||||
fabricRender.first.ShaderName = "ParallaxShader";
|
||||
//fabricRender.first.ShaderName = "PhongShader";
|
||||
//Choose colored or black and white -- Vladislav Khorev vladislav.khorev@fishrungames.com
|
||||
#if 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(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));
|
||||
#else
|
||||
|
||||
/*
|
||||
* Line below should be in tes-engine/include/ShaderManager/ShaderManager.h
|
||||
*/
|
||||
std::string const CONST_STRING_HEIGHTMAP_UNIFORM = "HeightMap";
|
||||
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 1, 1, 1));
|
||||
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 1, 1, 1));
|
||||
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(1, 1, 1, 1));
|
||||
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(0, 0, 0, 1));
|
||||
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(0, 0, 0, 1));
|
||||
pair.second.Data.Vec4CoordArr[CONST_STRING_COLOR_ATTRIB].push_back(Vector4f(0, 0, 0, 1));
|
||||
|
||||
background.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "background.jpg";
|
||||
#endif
|
||||
pair.first.ShaderName = "ColorShader";
|
||||
|
||||
fabricRender.first.SamplerMap[CONST_STRING_NORMALMAP_UNIFORM] = "NormalMap.png";
|
||||
fabricRender.first.SamplerMap[CONST_STRING_HEIGHTMAP_UNIFORM] = "HeightMap.png";
|
||||
fabricRender.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "linesAll.png";
|
||||
|
||||
background.second.RefreshBuffer();
|
||||
fabricRender.second.RefreshBuffer();
|
||||
pair.second.RefreshBuffer();
|
||||
|
||||
|
||||
|
||||
@@ -261,10 +115,64 @@ void TMyApplication::InnerInit()
|
||||
Renderer->SetOrthoProjection();
|
||||
|
||||
Renderer->SetFullScreenViewport();
|
||||
|
||||
|
||||
|
||||
glDisable(GL_BLEND); //Don't forget to disable blending or whole thing will not work!!! -- Vladislav Khorev vladislav.khorev@fishrungames.com
|
||||
|
||||
Inited = true;
|
||||
|
||||
|
||||
|
||||
|
||||
//This is stuff from original https://github.com/scrawl/smaa-opengl
|
||||
//We must have these textures to be used for pattern matching or something -- Vladislav Khorev vladislav.khorev@fishrungames.com
|
||||
|
||||
unsigned char* buffer = 0;
|
||||
FILE* f = 0;
|
||||
|
||||
buffer = new unsigned char[1024 * 1024];
|
||||
f = fopen((ST::PathToResources + "smaa/smaa_area.raw").c_str(), "rb"); //rb stands for "read binary file"
|
||||
|
||||
if (!f)
|
||||
{
|
||||
std::cerr << "Couldn't open smaa_area.raw.\n";
|
||||
}
|
||||
|
||||
fread(buffer, AREATEX_WIDTH * AREATEX_HEIGHT * 2, 1, f);
|
||||
fclose(f);
|
||||
|
||||
f = 0;
|
||||
|
||||
glGenTextures(1, &area_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, area_tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, (GLsizei)AREATEX_WIDTH, (GLsizei)AREATEX_HEIGHT, 0, GL_RG, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
f = fopen((ST::PathToResources + "smaa/smaa_search.raw").c_str(), "rb");
|
||||
|
||||
if (!f)
|
||||
{
|
||||
std::cerr << "Couldn't open smaa_search.raw.\n";
|
||||
}
|
||||
|
||||
fread(buffer, SEARCHTEX_WIDTH * SEARCHTEX_HEIGHT, 1, f);
|
||||
fclose(f);
|
||||
|
||||
f = 0;
|
||||
|
||||
glGenTextures(1, &search_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, search_tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, (GLsizei)SEARCHTEX_WIDTH, (GLsizei)SEARCHTEX_HEIGHT, 0, GL_RED, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::InnerDeinit()
|
||||
@@ -276,6 +184,9 @@ void TMyApplication::InnerDeinit()
|
||||
*Console<<"APP DEINIT\n";
|
||||
}
|
||||
|
||||
glDeleteTextures(1, &search_tex);
|
||||
glDeleteTextures(1, &area_tex);
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::InnerOnTapDown(Vector2f p)
|
||||
@@ -295,121 +206,133 @@ void TMyApplication::InnerOnTapUpAfterMove(Vector2f p)
|
||||
|
||||
void TMyApplication::InnerOnMove(Vector2f p, Vector2f shift)
|
||||
{
|
||||
phi += shift(1)*0.02f;
|
||||
|
||||
if (phi < pi/12)
|
||||
{
|
||||
phi = pi / 12;
|
||||
}
|
||||
|
||||
if (phi > pi / 2)
|
||||
{
|
||||
phi = pi / 2;
|
||||
}
|
||||
|
||||
alpha -= shift(0)*0.02f;
|
||||
}
|
||||
|
||||
void TMyApplication::OnFling(Vector2f v)
|
||||
{
|
||||
}
|
||||
|
||||
void TMyApplication::OnMouseWheel(short int delta)
|
||||
{
|
||||
distance += delta;
|
||||
|
||||
if (distance > 2500)
|
||||
{
|
||||
distance = 2500;
|
||||
}
|
||||
|
||||
if (distance < 100)
|
||||
{
|
||||
distance = 100;
|
||||
}
|
||||
}
|
||||
|
||||
void TMyApplication::InnerDraw()
|
||||
{
|
||||
|
||||
DrawScene();
|
||||
}
|
||||
|
||||
void TMyApplication::DrawScene()
|
||||
{
|
||||
//Render the frame
|
||||
Renderer->SwitchToFrameBuffer("AlbedoBuffer");
|
||||
Renderer->SetProjectionMatrix(512.f, 512.f);
|
||||
|
||||
Renderer->SetPerspectiveProjection(pi / 6, 10.f, 10000.f);
|
||||
|
||||
Renderer->SetFullScreenViewport();
|
||||
|
||||
Renderer->PushMatrix();
|
||||
|
||||
Renderer->TranslateMatrix(Vector3f(0, 0, -distance));
|
||||
|
||||
Vector4f quat1 = Vector4f(sin(phi / 2), 0, 0, cos(phi / 2));
|
||||
Vector4f quat2 = Vector4f(0, sin(alpha / 2), 0, cos(alpha / 2));
|
||||
|
||||
|
||||
Renderer->RotateMatrix(quat1);
|
||||
|
||||
Renderer->RotateMatrix(quat2);
|
||||
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
CheckGlError("");
|
||||
|
||||
auto mat1 = quatToMatrix(quat1);
|
||||
|
||||
auto mat2 = quatToMatrix(quat2);
|
||||
|
||||
Vector3f lightPos = { 0.f, -1.f, -1.f };
|
||||
|
||||
Vector3f eye = mat2 * mat1 * Vector3f(0.0f, 0.f, -distance);
|
||||
|
||||
{
|
||||
TRenderParamsSetter params(background.first);
|
||||
|
||||
RenderUniform3fv("eye", eye.data());
|
||||
RenderUniform3fv("lightPos", lightPos.data());
|
||||
|
||||
Matrix3f normMatrix = Renderer->GetModelviewMatrix().inverse().transpose().block<3, 3>(0, 0);
|
||||
|
||||
RenderUniformMatrix3fv("NormalMatrix", false, normMatrix.data());
|
||||
RenderUniformMatrix4fv("ModelViewMatrix", false, Renderer->GetModelviewMatrix().data());
|
||||
RenderUniformMatrix3fv("ModelViewMatrix3x3", false, Renderer->GetModelviewMatrix().block<3, 3>(0, 0).data());
|
||||
|
||||
Renderer->DrawTriangleList(background.second);
|
||||
//Render here all objects that you want to have -- Vladislav Khorev vladislav.khorev@fishrungames.com
|
||||
TRenderParamsSetter params(pair.first);
|
||||
Renderer->DrawTriangleList(pair.second);
|
||||
}
|
||||
{
|
||||
TRenderParamsSetter params(fabricRender.first);
|
||||
|
||||
//RenderUniform3fv("cameraPos", eye.data());
|
||||
RenderUniform3fv("eye", eye.data());
|
||||
RenderUniform3fv("lightPos", lightPos.data());
|
||||
|
||||
//RenderUniform3fv("ambientLight", Vector3f(0.0f, 0.0f, 0.0f).data());
|
||||
//RenderUniform3fv("specularLight", Vector3f(0.0f, 0.0f, 0.0f).data());
|
||||
//RenderUniform3fv("ambientLight", Vector3f(0.0f, 0.0f, 0.0f).data());
|
||||
//RenderUniform1f("specularPower", 20.f);
|
||||
|
||||
Matrix3f normMatrix = Renderer->GetModelviewMatrix().inverse().transpose().block<3, 3>(0, 0);
|
||||
|
||||
RenderUniformMatrix3fv("NormalMatrix", false, normMatrix.data());
|
||||
RenderUniformMatrix4fv("ModelViewMatrix", false, Renderer->GetModelviewMatrix().data());
|
||||
RenderUniformMatrix3fv("ModelViewMatrix3x3", false, Renderer->GetModelviewMatrix().block<3, 3>(0, 0).data());
|
||||
|
||||
Renderer->DrawTriangleList(fabricRender.second);
|
||||
}
|
||||
|
||||
|
||||
Renderer->PopMatrix();
|
||||
|
||||
CheckGlError("");
|
||||
|
||||
|
||||
//-------------------------
|
||||
//First pass - edge detection
|
||||
|
||||
Renderer->PushShader("SmaaEdge");
|
||||
|
||||
|
||||
Renderer->SwitchToFrameBuffer("EdgeBuffer");
|
||||
Renderer->SetProjectionMatrix(512.f, 512.f);
|
||||
|
||||
RenderUniform1i("albedo_tex", 0);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("AlbedoBuffer"));
|
||||
|
||||
|
||||
Renderer->DrawTriangleList(rect.second);
|
||||
|
||||
Renderer->PopShader();
|
||||
|
||||
CheckGlError("");
|
||||
|
||||
|
||||
//-------------------------
|
||||
//Second pass - blend plus pattern matching
|
||||
|
||||
Renderer->PushShader("SmaaBlend");
|
||||
|
||||
Renderer->SwitchToFrameBuffer("BlendBuffer");
|
||||
Renderer->SetProjectionMatrix(512.f, 512.f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
RenderUniform1i("edge_tex", 0);
|
||||
RenderUniform1i("area_tex", 1);
|
||||
RenderUniform1i("search_tex", 2);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("EdgeBuffer"));
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, area_tex);
|
||||
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, search_tex);
|
||||
|
||||
Renderer->DrawTriangleList(rect.second);
|
||||
|
||||
Renderer->PopShader();
|
||||
|
||||
CheckGlError("");
|
||||
|
||||
#if 1
|
||||
//-------------------------
|
||||
//Last pass - neightborhood
|
||||
|
||||
Renderer->PushShader("SmaaNeighborhood");
|
||||
|
||||
Renderer->SwitchToScreen();
|
||||
Renderer->SetFullScreenViewport();
|
||||
Renderer->SetProjectionMatrix(512.f, 512.f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
RenderUniform1i("albedo_tex", 0);
|
||||
RenderUniform1i("blend_tex", 1);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("BlendBuffer"));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("AlbedoBuffer"));
|
||||
Renderer->DrawTriangleList(rect.second);
|
||||
|
||||
Renderer->PopShader();
|
||||
|
||||
CheckGlError("");
|
||||
#else
|
||||
|
||||
|
||||
//... or just render intermediate buffers to see what is going on
|
||||
Renderer->PushShader("DefaultShader");
|
||||
Renderer->SwitchToScreen();
|
||||
Renderer->SetFullScreenViewport();
|
||||
Renderer->SetProjectionMatrix(512.f, 512.f);
|
||||
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
//Choose any to render for debug:
|
||||
//glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("AlbedoBuffer"));
|
||||
//glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("EdgeBuffer"));
|
||||
glBindTexture(GL_TEXTURE_2D, ResourceManager->FrameManager.GetFrameTexture("BlendBuffer"));
|
||||
|
||||
Renderer->DrawTriangleList(rect.second);
|
||||
|
||||
Renderer->PopShader();
|
||||
|
||||
CheckGlError("");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ protected:
|
||||
bool Inited;
|
||||
|
||||
public:
|
||||
TRenderPair fabricRender;
|
||||
TRenderPair background;
|
||||
TRenderPair pair;
|
||||
TRenderPair rect;
|
||||
|
||||
bool Loaded;
|
||||
@@ -47,9 +46,6 @@ public:
|
||||
|
||||
virtual void InnerDraw();
|
||||
|
||||
|
||||
void DrawScene();
|
||||
|
||||
virtual void InnerUpdate(size_t dt);
|
||||
|
||||
bool IsLoaded();
|
||||
@@ -67,14 +63,6 @@ public:
|
||||
|
||||
virtual void OnFling(Vector2f v);
|
||||
|
||||
virtual void OnMouseWheel(short int delta);
|
||||
|
||||
|
||||
float distance = 2000;
|
||||
|
||||
float alpha = 0;
|
||||
|
||||
float phi = pi / 6;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Файлы исходного кода">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Заголовочные файлы">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы ресурсов">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Файлы исходного кода</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\game\main_code.cpp">
|
||||
<Filter>Файлы исходного кода</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="main.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\game\main_code.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||