Compare commits
4
Commits
parallax-test
...
fabric
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f2572eaa5 | ||
|
|
86f0ad59bb | ||
|
|
13f3e3ee9b | ||
|
|
95207620f6 |
No files matched your search
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 696 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.5 MiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 180 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
+131
-72
@@ -78,84 +78,128 @@ void TMyApplication::InnerInit()
|
||||
Renderer->PushShader("DefaultShader");
|
||||
|
||||
ResourceManager->TexList.AddTexture("console_bkg.bmp");
|
||||
ResourceManager->TexList.AddTexture("owl-green.jpg");
|
||||
ResourceManager->TexList.AddTexture("owl-green-height.png");
|
||||
ResourceManager->TexList.AddTexture("owl-green-normal.png");
|
||||
|
||||
ResourceManager->TexList.AddTexture("5f.jpg");
|
||||
ResourceManager->TexList.AddTexture("6f.jpg");
|
||||
ResourceManager->TexList.AddTexture("7f.jpg");
|
||||
ResourceManager->TexList.AddTexture("background.jpg");
|
||||
ResourceManager->TexList.AddTexture("HeightMap.png");
|
||||
ResourceManager->TexList.AddTexture("NormalMap.png");
|
||||
ResourceManager->TexList.AddTexture("linesAll.png");
|
||||
|
||||
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
|
||||
|
||||
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;
|
||||
|
||||
{
|
||||
//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 = backgroundW / imageW;
|
||||
float const th = backgroundH / 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));
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
//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) {
|
||||
auto pv = p2 - p1;
|
||||
Vector3f ortho(pv[2], 0, pv[0]);
|
||||
ortho.normalize();
|
||||
auto p3 = p2 + ortho * thick;
|
||||
auto p4 = p1 + ortho * thick;
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p2);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
|
||||
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p4);
|
||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
|
||||
|
||||
auto texThick = thick / texW;
|
||||
auto m = (p1[0] + p2[0]) / 2 / texW;
|
||||
auto y = H / texH;
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, y));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
|
||||
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, 0));
|
||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
|
||||
|
||||
};
|
||||
|
||||
Vector3f const stepDirection(1, 0, 0);
|
||||
Vector3f p1(bottomLeft[0], 0, -bottomLeft[1]);
|
||||
|
||||
while (p1[0] < bottomLeft[0] + W) {
|
||||
|
||||
auto p2 = p1 - Vector3f(0, 0, W);
|
||||
f(p1, p2);
|
||||
|
||||
auto p3 = p1 + step * stepDirection;
|
||||
f(p3, p2);
|
||||
|
||||
p1 = p3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
background.first.ShaderName ="DefaultShader";
|
||||
fabricRender.first.ShaderName = "ParallaxShader";
|
||||
|
||||
/*
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(-511, -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(512, 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(512, 512, 0));
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, -512, 0));
|
||||
* Line below should be in tes-engine/include/ShaderManager/ShaderManager.h
|
||||
*/
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(-511, 0, -512));
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(-512, 0, 512));
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 0, 512));
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(-512, 0, -512));
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 0, 512));
|
||||
pair.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(Vector3f(512, 0, -512));
|
||||
std::string const CONST_STRING_HEIGHTMAP_UNIFORM = "HeightMap";
|
||||
|
||||
pair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
|
||||
pair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 1));
|
||||
pair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1,1));
|
||||
pair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
|
||||
pair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(1,1));
|
||||
pair.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(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(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 = "ParallaxShader";
|
||||
|
||||
pair.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "owl-green.jpg";
|
||||
pair.first.SamplerMap["HeightMap"] = "owl-green-height.png";
|
||||
pair.first.SamplerMap["NormalMap"] = "owl-green-normal.png";
|
||||
//pair.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "6f.jpg";
|
||||
//pair.first.SamplerMap["HeightMap"] = "5f.jpg";
|
||||
//pair.first.SamplerMap["NormalMap"] = "7f.jpg";
|
||||
|
||||
pair.second.RefreshBuffer();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
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();*/
|
||||
background.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "background.jpg";
|
||||
|
||||
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();
|
||||
|
||||
Inited = true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TMyApplication::InnerDeinit()
|
||||
@@ -240,9 +284,10 @@ void TMyApplication::InnerDraw()
|
||||
Renderer->RotateMatrix(quat2);
|
||||
|
||||
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
CheckGlError("");
|
||||
|
||||
auto mat1 = quatToMatrix(quat1);
|
||||
@@ -251,11 +296,10 @@ void TMyApplication::InnerDraw()
|
||||
|
||||
Vector3f lightPos = {0.f, 1.f, 1.f};
|
||||
|
||||
Vector3f eye = mat2 * (mat1 * Vector3f(0.0f, 0.f, -distance));
|
||||
|
||||
Vector3f eye = mat2 * mat1 * Vector3f(0.0f, 0.f, -distance);
|
||||
|
||||
{
|
||||
TRenderParamsSetter params(pair.first);
|
||||
TRenderParamsSetter params(background.first);
|
||||
|
||||
RenderUniform3fv("eye", eye.data());
|
||||
RenderUniform3fv("lightPos", lightPos.data());
|
||||
@@ -266,8 +310,23 @@ void TMyApplication::InnerDraw()
|
||||
RenderUniformMatrix4fv("ModelViewMatrix", false, Renderer->GetModelviewMatrix().data());
|
||||
RenderUniformMatrix3fv("ModelViewMatrix3x3", false, Renderer->GetModelviewMatrix().block<3, 3>(0, 0).data());
|
||||
|
||||
Renderer->DrawTriangleList(pair.second);
|
||||
Renderer->DrawTriangleList(background.second);
|
||||
}
|
||||
{
|
||||
TRenderParamsSetter params(fabricRender.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(fabricRender.second);
|
||||
}
|
||||
|
||||
|
||||
Renderer->PopMatrix();
|
||||
|
||||
|
||||
+2
-2
@@ -33,8 +33,8 @@ protected:
|
||||
bool Inited;
|
||||
|
||||
public:
|
||||
TRenderPair pair;
|
||||
TRenderPair rect;
|
||||
TRenderPair fabricRender;
|
||||
TRenderPair background;
|
||||
|
||||
bool Loaded;
|
||||
|
||||
|
||||
Reference in new issue
Block a user