added toreiller skybox
This commit is contained in:
parent
b8c4335290
commit
c5b057e585
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
BIN
img/sky_back.PNG
Normal file
BIN
img/sky_back.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
img/sky_front.PNG
Normal file
BIN
img/sky_front.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
@ -49,5 +49,11 @@
|
||||
<file>shaders/pixel.vert.glsl</file>
|
||||
<file>shaders/world.frag.glsl</file>
|
||||
<file>shaders/world.vert.glsl</file>
|
||||
<file>shaders/skybox.frag.glsl</file>
|
||||
<file>shaders/skybox.vert.glsl</file>
|
||||
</qresource>
|
||||
<qresource prefix="images">
|
||||
<file>img/sky_front.png</file>
|
||||
<file>img/sky_back.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
32
shaders/skybox.frag.glsl
Normal file
32
shaders/skybox.frag.glsl
Normal file
@ -0,0 +1,32 @@
|
||||
#version 330 core
|
||||
|
||||
uniform sampler2D frontMap;
|
||||
uniform sampler2D backMap;
|
||||
|
||||
uniform vec3 camera;
|
||||
uniform vec2 worldSize;
|
||||
uniform vec2 screenSize;
|
||||
uniform float flatSphere;
|
||||
uniform float surfaceRatio;
|
||||
|
||||
in vec2 texCoord;
|
||||
in vec3 normal;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
// looping the world in the shape of a toreiller (infinite flat surface)
|
||||
vec2 worldCoord = texCoord*worldSize + camera.xy*worldSize + (texCoord-vec2(0.25, 0.5))*surfaceRatio*worldSize;
|
||||
vec2 texCoordWorld = worldCoord / worldSize;
|
||||
ivec2 nbRevolutions = ivec2(floor(texCoordWorld));
|
||||
vec3 texColor;
|
||||
texCoordWorld = mod(texCoordWorld, 1);
|
||||
if(abs(mod(nbRevolutions.y+nbRevolutions.x, 2)) > 0.5)
|
||||
texColor = texture(backMap, texCoordWorld).xyz;
|
||||
else
|
||||
texColor = texture(frontMap, texCoordWorld).xyz;
|
||||
|
||||
// computing lighting
|
||||
outColor = vec4(texColor, 1.0);
|
||||
}
|
21
shaders/skybox.vert.glsl
Normal file
21
shaders/skybox.vert.glsl
Normal file
@ -0,0 +1,21 @@
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0)in vec3 inPosition;
|
||||
layout(location = 2)in vec2 inTexCoord;
|
||||
layout(location = 1)in vec3 inNormal;
|
||||
|
||||
uniform float flatSphere;
|
||||
uniform vec2 screenSize;
|
||||
uniform mat4 mvp;
|
||||
uniform vec3 camera;
|
||||
|
||||
out vec2 texCoord;
|
||||
out vec3 normal;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
texCoord = vec2(inTexCoord.x, inTexCoord.y);
|
||||
normal = inNormal.xyz;
|
||||
vec4 projPos = mvp * vec4(-inPosition, 1.0);
|
||||
gl_Position = projPos;
|
||||
}
|
@ -32,7 +32,7 @@ void main()
|
||||
nbRevolutions.x = int(floor(worldCoord.x / worldSize.x));
|
||||
}
|
||||
worldCoord = worldCoord - nbRevolutions*worldSize;
|
||||
vec3 texColor = texelFetch(colorMap, ivec2(worldCoord)).xyz;
|
||||
vec3 texColor = texelFetch(colorMap, ivec2(worldCoord.x, worldSize.y-worldCoord.y)).xyz;
|
||||
|
||||
// computing lighting
|
||||
vec3 lighting = phongLighting(texColor, vec3(0.5), 50, vec3(1), normalize(normal), lightDir, normalize(lightDir+vec3(0, 0, -1)));
|
||||
|
@ -19,6 +19,7 @@ void main(void)
|
||||
texCoord = mix(texCoord, flatTexCoord, vec2(flatSphere));
|
||||
normal = inNormal.xyz;
|
||||
vec4 flatPos = vec4(inTexCoord.x*2 -1, inTexCoord.y*2 -1, 0.0, 1.0);
|
||||
vec4 projPos = mvp * vec4(inPosition*camera.z, 1.0);
|
||||
vec3 position = vec3(inPosition.xy, inPosition.z - 1);
|
||||
vec4 projPos = mvp * vec4(position*camera.z, 1.0);
|
||||
gl_Position = mix(projPos, flatPos, vec4(flatSphere));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ void MainWindow::openSimuDialog()
|
||||
void MainWindow::changeSimSpeed(int newSpeed)
|
||||
{
|
||||
m_simSpeedChanged = true;
|
||||
m_simSpeed = newSpeed;
|
||||
m_simSpeed = ui->simSpeedSlider->maximum()-newSpeed;
|
||||
}
|
||||
|
||||
void MainWindow::updateSimu()
|
||||
|
@ -96,7 +96,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Flat / Sphere</string>
|
||||
<string>Spherical / Flat</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -105,14 +105,17 @@
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>2</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>2</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -188,10 +191,10 @@
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>500</number>
|
||||
<number>2000</number>
|
||||
</property>
|
||||
<property name="sliderPosition">
|
||||
<number>500</number>
|
||||
<number>2000</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -230,8 +233,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>98</width>
|
||||
<height>56</height>
|
||||
<width>260</width>
|
||||
<height>346</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
|
@ -8,7 +8,7 @@ glm::vec3 MapScene::getColor(const Pixel &px) const
|
||||
{
|
||||
switch(px.type)
|
||||
{
|
||||
case BEDROCK : return HEX_TO_VEC3(0x101020);
|
||||
case WATER : return HEX_TO_VEC3(0x2033B0);
|
||||
case GRASS : return HEX_TO_VEC3(0x719678);
|
||||
case MARK : return HEX_TO_VEC3(0x5D7B62);
|
||||
case ROCK : return HEX_TO_VEC3(0x8C8C8C);
|
||||
|
@ -11,7 +11,7 @@
|
||||
struct MapScene : public Map, public BasicScene
|
||||
{
|
||||
public:
|
||||
MapScene(int n, int w, int h=0) : Map(n, w, h), m_teamColors(new TeamColor[n]),m_vao(0),m_vbo(0) {}
|
||||
MapScene(int n=0, int w=300, int h=0) : Map(n, w, h), m_teamColors(new TeamColor[n]),m_vao(0),m_vbo(0) {}
|
||||
|
||||
~MapScene();
|
||||
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
float clockAngle = atan2(relUV.y, relUV.x);
|
||||
float depthAngle = glm::length(relUV)*3.1416f*MAGIC_RATIO;
|
||||
float r = sin(depthAngle);
|
||||
return glm::vec3(r*cos(clockAngle), r*sin(clockAngle), cos(depthAngle)-1);
|
||||
return glm::vec3(r*cos(clockAngle), r*sin(clockAngle), cos(depthAngle));
|
||||
}
|
||||
};
|
||||
|
||||
@ -61,6 +61,11 @@ PixelPipeline::PixelPipeline(MapScene *map) :
|
||||
vertSource = QtUtils::fileToString(":shaders/shaders/world.vert.glsl").toStdString();
|
||||
fragSource = QtUtils::fileToString(":shaders/shaders/world.frag.glsl").toStdString();
|
||||
m_renderShader = new Shader(vertSource, fragSource);
|
||||
vertSource = QtUtils::fileToString(":shaders/shaders/skybox.vert.glsl").toStdString();
|
||||
fragSource = QtUtils::fileToString(":shaders/shaders/skybox.frag.glsl").toStdString();
|
||||
m_skyboxShader = new Shader(vertSource, fragSource);
|
||||
m_skyTexFront = new Texture(QtUtils::loadImage(":images/img/sky_front.png"));
|
||||
m_skyTexBack = new Texture(QtUtils::loadImage(":images/img/sky_back.png"));
|
||||
updateChanges();
|
||||
}
|
||||
|
||||
@ -92,6 +97,25 @@ void PixelPipeline::renderGL(Scene *scene)
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glDisable(GL_BLEND);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glClearDepth(1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
m_skyboxShader->bind();
|
||||
m_skyboxShader->bindVec3(m_skyboxShader->getLocation("camera"), m_camera);
|
||||
m_renderShader->bindVec2(m_skyboxShader->getLocation("worldSize"), glm::vec2(m_mapWidth, m_mapHeight));
|
||||
m_skyboxShader->bindVec2(m_skyboxShader->getLocation("screenSize"), glm::vec2(m_width, m_height));
|
||||
m_skyboxShader->bindFloat(m_skyboxShader->getLocation("surfaceRatio"), m_surfaceRatio);
|
||||
m_skyboxShader->bindFloat(m_skyboxShader->getLocation("flatSphere"), m_flatSphere);
|
||||
m_skyTexFront->bind(0);
|
||||
m_skyTexBack->bind(1);
|
||||
m_skyboxShader->bindInteger(m_skyboxShader->getLocation("frontMap"), 0);
|
||||
m_skyboxShader->bindInteger(m_skyboxShader->getLocation("backMap"), 1);
|
||||
|
||||
m_skyboxShader->bindMat4(m_skyboxShader->getLocation("mvp"), m_proj);
|
||||
m_toreiller->draw(m_skyboxShader);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
m_renderShader->bind();
|
||||
m_renderShader->bindVec3(m_renderShader->getLocation("camera"), m_camera);
|
||||
m_renderShader->bindVec2(m_renderShader->getLocation("worldSize"), glm::vec2(m_mapWidth, m_mapHeight));
|
||||
@ -100,11 +124,9 @@ void PixelPipeline::renderGL(Scene *scene)
|
||||
m_renderShader->bindFloat(m_renderShader->getLocation("flatSphere"), m_flatSphere);
|
||||
m_mapTex->bind(0);
|
||||
m_renderShader->bindInteger(m_renderShader->getLocation("colorMap"), 0);
|
||||
|
||||
glClearDepth(1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
m_renderShader->bindMat4(m_renderShader->getLocation("mvp"), m_mvp);
|
||||
|
||||
glm::mat4 mvp = m_proj * m_view;
|
||||
m_renderShader->bindMat4(m_renderShader->getLocation("mvp"), mvp);
|
||||
m_toreiller->draw(m_renderShader);
|
||||
}
|
||||
|
||||
@ -112,7 +134,8 @@ void PixelPipeline::resizeGL(int w, int h)
|
||||
{
|
||||
m_width = w;
|
||||
m_height = h;
|
||||
m_mvp = glm::translate(glm::perspectiveFov(70.f, float(w), float(h), 0.1f, 10.f), glm::vec3(0, 0, -3));
|
||||
m_proj = glm::perspectiveFov(70.f, float(w), float(h), 0.1f, 10.f);
|
||||
m_view = glm::translate(glm::mat4(), glm::vec3(0, 0, -3));
|
||||
}
|
||||
|
||||
void PixelPipeline::cameraZoom(int nbScrolls)
|
||||
|
@ -17,6 +17,9 @@ private:
|
||||
FrameBuffer *m_mapFBO;
|
||||
Texture *m_mapTex;
|
||||
Shader *m_texMapShader;
|
||||
Texture *m_skyTexFront;
|
||||
Texture *m_skyTexBack;
|
||||
Shader *m_skyboxShader;
|
||||
MapScene *m_map;
|
||||
int m_mapWidth;
|
||||
int m_mapHeight;
|
||||
@ -29,7 +32,8 @@ private:
|
||||
glm::vec3 m_camera;
|
||||
|
||||
Mesh *m_toreiller;
|
||||
glm::mat4 m_mvp;
|
||||
glm::mat4 m_proj;
|
||||
glm::mat4 m_view;
|
||||
|
||||
public:
|
||||
PixelPipeline(MapScene *map);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define PIXELTYPE_H
|
||||
|
||||
enum PixelType {
|
||||
BEDROCK, GRASS, TREE, BERRIES, ROCK, IRON_ORE, // nature
|
||||
WATER, GRASS, TREE, BERRIES, ROCK, IRON_ORE, // nature
|
||||
FOOD, WOOD, STONE, IRON, SWORD, // resources
|
||||
DUDE, DEAD_DUDE, // humans
|
||||
SPAWN, WALL, ROAD, MARK, LIBRARY, // buildings
|
||||
|
Loading…
x
Reference in New Issue
Block a user