Merge branch 'master' of https://git.epicsparrow.com/epicsparrow/PixelWars
This commit is contained in:
commit
9fa3e924a4
@ -6,13 +6,28 @@ uniform vec3 camera;
|
|||||||
uniform vec2 worldSize;
|
uniform vec2 worldSize;
|
||||||
uniform vec2 screenSize;
|
uniform vec2 screenSize;
|
||||||
|
|
||||||
|
in vec2 texCoord;
|
||||||
|
in vec3 normal;
|
||||||
|
|
||||||
out vec4 outColor;
|
out vec4 outColor;
|
||||||
|
|
||||||
|
vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 normal, in vec3 lightDir, in vec3 halfVec){
|
||||||
|
float diffuseComponent = max(dot(normal, lightDir), 0);
|
||||||
|
float specularComponent = max(dot(halfVec, normal), 0);
|
||||||
|
return color*diffuseComponent*(kd+ks*pow(specularComponent, ns));
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 halfScreen = screenSize/2;
|
vec2 worldCoord = texCoord*worldSize + camera.xy;
|
||||||
vec2 screenPos = gl_FragCoord.xy + camera.xy;
|
ivec2 nbRevolutions = ivec2(floor(worldCoord / worldSize));
|
||||||
vec2 texCoord = (screenPos-halfScreen)/200;
|
if(abs(mod(nbRevolutions.y, 2)) > 0.5)
|
||||||
vec3 texColor = texelFetch(colorMap, ivec2(screenPos*camera.z)).xyz;
|
{
|
||||||
outColor = vec4(texColor, 1.0);
|
worldCoord.x += worldSize.x/2;
|
||||||
|
nbRevolutions.x = int(floor(worldCoord.x / worldSize.x));
|
||||||
|
}
|
||||||
|
worldCoord = worldCoord - nbRevolutions*worldSize;
|
||||||
|
vec3 texColor = texelFetch(colorMap, ivec2(worldCoord)).xyz;
|
||||||
|
float pseudoLighting = 0.4+dot(normal, normalize(vec3(-0.5))); // TODO : use phong lighting
|
||||||
|
outColor = vec4(texColor*pseudoLighting, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,18 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout(location = 0)in vec2 inPosition;
|
layout(location = 0)in vec3 inPosition;
|
||||||
|
layout(location = 2)in vec2 inTexCoord;
|
||||||
|
layout(location = 1)in vec3 inNormal;
|
||||||
|
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform vec3 camera;
|
||||||
|
|
||||||
|
out vec2 texCoord;
|
||||||
|
out vec3 normal;
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
gl_Position = vec4(inPosition, 0.0, 1.0);
|
texCoord = inTexCoord.xy;
|
||||||
|
normal = inNormal.xyz;
|
||||||
|
gl_Position = mvp * vec4(inPosition*camera.z, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <qtutils.h>
|
#include <qtutils.h>
|
||||||
#include "mapscene.h"
|
#include "mapscene.h"
|
||||||
|
#include <parametricmesh.h>
|
||||||
|
#include <glm/ext.hpp>
|
||||||
|
|
||||||
#define SCROLL_SPEED 0.998f
|
#define SCROLL_SPEED 0.998f
|
||||||
|
|
||||||
@ -40,6 +42,20 @@ inline glm::vec3 getColor(const Pixel &p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ToreillerGenerator : public MeshGenerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual glm::vec3 evalUV(float u, float v)
|
||||||
|
{
|
||||||
|
const float MAGIC_RATIO = 1;
|
||||||
|
|
||||||
|
glm::vec2 relUV = glm::vec2(u-0.5f, v-0.5f);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// MESH (2D points)
|
// MESH (2D points)
|
||||||
|
|
||||||
@ -118,18 +134,12 @@ PixelPipeline::PixelPipeline(MapScene *map) :
|
|||||||
m_mapFBO->initColorAttachments();
|
m_mapFBO->initColorAttachments();
|
||||||
|
|
||||||
// set up vao
|
// set up vao
|
||||||
const float vertices[] = {
|
|
||||||
-1.0f, -1.0f,
|
ToreillerGenerator gen;
|
||||||
3.0f, -1.0f,
|
m_toreiller = gen.generateParametricMesh(NULL, 40, 40, 1.0f);
|
||||||
-1.0f, 3.0f
|
m_toreiller->computeNormals();
|
||||||
};
|
m_toreiller->mergeVertices();
|
||||||
glGenVertexArrays(1, &m_vao);
|
m_toreiller->initGL();
|
||||||
glBindVertexArray(m_vao);
|
|
||||||
glGenBuffers(1, &m_vbo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, 3 * 2 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
|
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, NULL);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
std::string vertSource = QtUtils::fileToString(":shaders/shaders/pixel.vert.glsl").toStdString();
|
std::string vertSource = QtUtils::fileToString(":shaders/shaders/pixel.vert.glsl").toStdString();
|
||||||
std::string fragSource = QtUtils::fileToString(":shaders/shaders/pixel.frag.glsl").toStdString();
|
std::string fragSource = QtUtils::fileToString(":shaders/shaders/pixel.frag.glsl").toStdString();
|
||||||
@ -173,11 +183,10 @@ void PixelPipeline::updateChanges()
|
|||||||
void PixelPipeline::renderGL(Scene *scene)
|
void PixelPipeline::renderGL(Scene *scene)
|
||||||
{
|
{
|
||||||
m_targetFBO->bindFBO();
|
m_targetFBO->bindFBO();
|
||||||
glClearColor(0, 0, 0, 1);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
glViewport(0, 0, m_width, m_height);
|
glViewport(0, 0, m_width, m_height);
|
||||||
|
glClearColor(0, 0, 0, 1);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
m_renderShader->bind();
|
m_renderShader->bind();
|
||||||
m_renderShader->bindVec3(m_renderShader->getLocation("camera"), m_camera);
|
m_renderShader->bindVec3(m_renderShader->getLocation("camera"), m_camera);
|
||||||
m_renderShader->bindVec2(m_renderShader->getLocation("worldSize"), glm::vec2(m_mapWidth, m_mapHeight));
|
m_renderShader->bindVec2(m_renderShader->getLocation("worldSize"), glm::vec2(m_mapWidth, m_mapHeight));
|
||||||
@ -185,16 +194,18 @@ void PixelPipeline::renderGL(Scene *scene)
|
|||||||
m_mapTex->bind(0);
|
m_mapTex->bind(0);
|
||||||
m_renderShader->bindInteger(m_renderShader->getLocation("colorMap"), 0);
|
m_renderShader->bindInteger(m_renderShader->getLocation("colorMap"), 0);
|
||||||
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glClearDepth(1);
|
||||||
glBindVertexArray(m_vao);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glBindVertexArray(0);
|
m_renderShader->bindMat4(m_renderShader->getLocation("mvp"), m_mvp);
|
||||||
|
m_toreiller->draw(m_renderShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelPipeline::resizeGL(int w, int h)
|
void PixelPipeline::resizeGL(int w, int h)
|
||||||
{
|
{
|
||||||
m_width = w;
|
m_width = w;
|
||||||
m_height = h;
|
m_height = h;
|
||||||
|
m_mvp = glm::translate(glm::perspectiveFov(70.f, float(w), float(h), 0.1f, 10.f), glm::vec3(0, 0, -3));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelPipeline::cameraZoom(int nbScrolls)
|
void PixelPipeline::cameraZoom(int nbScrolls)
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
#define PIXELPIPELINE_H
|
#define PIXELPIPELINE_H
|
||||||
|
|
||||||
#include <pipeline.h>
|
#include <pipeline.h>
|
||||||
|
#include <glm/mat4x4.hpp>
|
||||||
|
|
||||||
class FrameBuffer;
|
class FrameBuffer;
|
||||||
class Texture;
|
class Texture;
|
||||||
class Shader;
|
class Shader;
|
||||||
class PixelMesh;
|
class PixelMesh;
|
||||||
class MapScene;
|
class MapScene;
|
||||||
|
class Mesh;
|
||||||
|
|
||||||
class PixelPipeline : public Pipeline
|
class PixelPipeline : public Pipeline
|
||||||
{
|
{
|
||||||
@ -24,7 +26,9 @@ private:
|
|||||||
int m_height;
|
int m_height;
|
||||||
glm::vec3 m_camera;
|
glm::vec3 m_camera;
|
||||||
|
|
||||||
unsigned int m_vao, m_vbo;
|
Mesh *m_toreiller;
|
||||||
|
glm::mat4 m_mvp;
|
||||||
|
//unsigned int m_vao, m_vbo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PixelPipeline(MapScene *map);
|
PixelPipeline(MapScene *map);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user