Commit 11711d68 authored by Dario Seyb's avatar Dario Seyb

almost working motion vectors

parent d2efb9da
......@@ -9,9 +9,16 @@ uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
uniform mat4 uPrevModelMatrix;
uniform mat4 uPrevViewProjectionMatrix;
out vec4 oColor;
out vec4 oEmissive;
out vec4 oNormal;
out vec2 oMotion;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
......@@ -29,7 +36,14 @@ void main()
if(sample > color.a) discard;
vec4 thisPosition = uViewProjectionMatrix * vec4(vPosition, 1);
vec4 prevPosition = uPrevViewProjectionMatrix * vec4(vPosition, 1);
vec2 prevFragCoord = prevPosition.xy/prevPosition.w;
vec2 thisFragCoord = thisPosition.xy/thisPosition.w;
oMotion = (thisFragCoord-prevFragCoord)*0.5;
oColor = color;
oEmissive = emissive();
oNormal = vec4(normalize(normal()) * 0.5 + 0.5, 0.0);
oNormal = vec4(normalize(normal()) * 0.5 + 0.5, 1.0);
}
......@@ -3,9 +3,6 @@
uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
uniform mat4 uPrevModelMatrix;
uniform mat4 uPrevViewProjectionMatrix;
in vec3 aNormal;
in vec3 aPosition;
in vec2 aTexCoord;
......@@ -13,7 +10,6 @@ in vec2 aTexCoord;
out vec3 vNormal;
out vec2 vTexCoord;
out vec3 vPosition;
out vec2 vMotion;
vec3 normal();
vec2 texCoord();
......@@ -23,14 +19,11 @@ void main()
{
vNormal = inverse(transpose(mat3(uModelMatrix))) * normal();
vTexCoord = texCoord();
vec4 worldPosition = uModelMatrix * vec4(position(), 1.0);
vPosition = worldPosition.xyz;
gl_Position = uViewProjectionMatrix * worldPosition;
vec4 prevPosition = uPrevViewProjectionMatrix * uPrevModelMatrix * vec4(aPosition, 1.0);
vec4 modelPos = vec4(position(), 1.0);
vec2 prevFragCoord = prevPosition.xy/(prevPosition.w * vec2(1280, 720));
vec2 thisFragCoord = gl_Position.xy/(gl_Position.w * vec2(1280, 720));
vec4 worldPosition = uModelMatrix * modelPos;
vPosition = worldPosition.xyz;
vMotion = vThisFragCoord-vPrevFragCoord;
gl_Position = uViewProjectionMatrix * worldPosition;
}
......@@ -90,6 +90,8 @@ void main()
if(specularFactor < 0) specularFactor = 0;
vec3 specularColor = pow(specularFactor, 210) * uLightColor.rgb;
float attenuation = 1.0/(lightDistance * lightDistance);
oColor = vec4((diffuseColor + specularColor) * color.rgb * uLightColor.a/(lightDistance * lightDistance) * shadowFactor(worldPosition) + emissive.rgb, 1);
oColor = vec4((diffuseColor + specularColor) * color.rgb * uLightColor.a * shadowFactor(worldPosition) * attenuation + emissive.rgb, 1);
}
#pragma import "CommonDeferredFrag.glsl"
<<<<<<< HEAD
in vec3 vNormal;
in vec2 vTexCoord;
in vec3 vPosition;
in vec2 vThisFragCoord;
in vec2 vPrevFragCoord;
in vec2 vMotion;
uniform sampler2D uTexture;
uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
out vec4 oColor;
out vec4 oEmissive;
out vec4 oNormal;
out vec2 oMotion;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main()
{
vec4 color = texture(uTexture, vTexCoord).rgba * uTintColor;
float sample = rand(gl_FragCoord.xy * vPosition.xy * vPosition.z * uTime);
if(sample > color.a) discard;
oMotion = vMotion;
oColor = color;
oEmissive = uEmissiveColor * color;
oNormal = vec4(normalize(vNormal) * 0.5 + 0.5, 0);
=======
vec4 color() {
return texture(uTexture, vTexCoord).rgba * uTintColor;
}
vec4 emissive() {
return uEmissiveColor;
>>>>>>> master
}
vec3 normal() {
return vNormal;
}
#version 330
in vec3 vNormal;
in vec2 vTexCoord;
in vec3 vPosition;
uniform sampler2D uTexture;
uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
out vec4 oColor;
out vec4 oEmissive;
out vec4 oNormal;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main()
{
vec4 color = texture(uTexture, vTexCoord).rgba * uTintColor;
float sample = rand(gl_FragCoord.xy * vPosition.xy * vPosition.z * uTime);
if(sample > color.a) discard;
oColor = color;
oEmissive = uEmissiveColor * color;
oNormal = vec4(normalize(vNormal) * 0.5 + 0.5, 0.0);
}
#version 330
in vec3 vNormal;
in vec2 vTexCoord;
in vec3 vPosition;
in vec2 vThisFragCoord;
in vec2 vPrevFragCoord;
in vec2 vMotion;
uniform sampler2D uTexture;
uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
out vec4 oColor;
out vec4 oEmissive;
out vec4 oNormal;
out vec2 oMotion;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main()
{
vec4 color = texture(uTexture, vTexCoord).rgba * uTintColor;
float sample = rand(gl_FragCoord.xy * vPosition.xy * vPosition.z * uTime);
if(sample > color.a) discard;
oMotion = vMotion;
oColor = color;
oEmissive = uEmissiveColor * color;
oNormal = vec4(normalize(vNormal) * 0.5 + 0.5, 0);
}
#pragma import "CommonDeferredFrag.glsl"
vec4 color() {
return texture(uTexture, vTexCoord).rgba * uTintColor;
}
vec4 emissive() {
return uEmissiveColor;
}
vec3 normal() {
return vNormal;
}
\ No newline at end of file
#pragma import "CommonDeferredFrag.glsl"
<<<<<<< HEAD
in vec3 vNormal;
in vec2 vTexCoord;
in vec3 vPosition;
in vec2 vThisFragCoord;
in vec2 vPrevFragCoord;
in vec2 vMotion;
uniform sampler2D uTexture;
uniform vec4 uEmissiveColor;
uniform vec4 uTintColor;
uniform float uTime;
out vec4 oColor;
out vec4 oEmissive;
out vec4 oNormal;
out vec2 oMotion;
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main()
{
vec4 color = texture(uTexture, vTexCoord).rgba * uTintColor;
float sample = rand(gl_FragCoord.xy * vPosition.xy * vPosition.z * uTime);
if(sample > color.a) discard;
oMotion = vMotion;
oColor = color;
oEmissive = uEmissiveColor * color;
oNormal = vec4(normalize(vNormal) * 0.5 + 0.5, 0);
=======
vec4 color() {
return texture(uTexture, vTexCoord).rgba * uTintColor;
}
vec4 emissive() {
return uEmissiveColor;
>>>>>>> master
}
vec3 normal() {
return vNormal;
}
#pragma import "CommonDeferredVert.glsl"
<<<<<<< HEAD
uniform mat4 uPrevModelMatrix;
uniform mat4 uPrevViewProjectionMatrix;
uniform mat4 uModelMatrix;
uniform mat4 uViewProjectionMatrix;
in vec3 aNormal;
in vec3 aPosition;
in vec2 aTexCoord;
out vec3 vNormal;
out vec2 vTexCoord;
out vec3 vPosition;
out vec2 vThisFragCoord;
out vec2 vPrevFragCoord;
out vec2 vMotion;
void main()
{
vNormal = inverse(transpose(mat3(uModelMatrix))) * aNormal;
vTexCoord = aTexCoord;
vec4 worldPosition = uModelMatrix * vec4(aPosition, 1.0);
vPosition = worldPosition.xyz;
vec4 prevPosition = uPrevViewProjectionMatrix * uPrevModelMatrix * vec4(aPosition, 1.0);
gl_Position = uViewProjectionMatrix * worldPosition;
vPrevFragCoord = prevPosition.xy/(prevPosition.w * vec2(1280, 720));
vThisFragCoord = gl_Position.xy/(gl_Position.w * vec2(1280, 720));
vMotion = vThisFragCoord-vPrevFragCoord;
=======
vec3 normal() {
return aNormal;
}
vec2 texCoord() {
return aTexCoord;
>>>>>>> master
}
vec3 position() {
return aPosition;
}
......@@ -18,51 +18,49 @@
class PlayerSystem : public System {
private:
EventSystem* m_events;
SceneGraphSystem *m_scene;
RendererSystem* m_renderer;
AudioSystem* m_audio;
UISystem* m_ui;
EventSystem* m_events;
SceneGraphSystem *m_scene;
RendererSystem* m_renderer;
AudioSystem* m_audio;
UISystem* m_ui;
Entity player;
Transform::Handle cameraTransform;
Entity player;
Transform::Handle cameraTransform;
bool m_keyState[SDL_NUM_SCANCODES];
bool spaceDown = false;
bool shiftDown = false;
float speed = 10;
float speed = 10;
std::string parentName = "Sun";
std::string parentName = "Sun";
void handleKeyboard(KeyboardEvent e);
void handleMouse(MouseEvent e);
void handleKeyboard(KeyboardEvent e);
void handleMouse(MouseEvent e);
void update(float dt);
void update(float dt);
public:
CONSTRUCT_SYSTEM(PlayerSystem) {}
CONSTRUCT_SYSTEM(PlayerSystem) {}
bool startup() override;
void shutdown() override;
bool startup() override;
void shutdown() override;
void setPosition(glm::vec3 p) {
cameraTransform->position = p;
}
void setPosition(glm::vec3 p) {
cameraTransform->position = p;
}
glm::vec3 getPosition() {
return cameraTransform->position;
}
glm::vec3 getPosition() {
return cameraTransform->position;
}
std::string getParentName() {
return parentName;
}
std::string getParentName() {
return parentName;
}
void setRotation(glm::mat4 r) {
cameraTransform->rotation = r;
}
void setRotation(glm::mat4 r) {
cameraTransform->rotation = r;
}
void attachToTransform(Transform::Handle p) {
cameraTransform->parent = p;
}
void attachToTransform(Transform::Handle p) {
cameraTransform->parent = p;
}
};
\ No newline at end of file
......@@ -53,6 +53,7 @@ bool RendererSystem::startup() {
for (auto& tex : m_gBufferTextures) {
tex->setMinFilter(GL_NEAREST);
tex->setMagFilter(GL_NEAREST);
tex->setWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER);
}
m_gBufferObject = SharedFrameBufferObject(new FrameBufferObject());
......@@ -112,8 +113,11 @@ bool RendererSystem::startup() {
}
ImGui::End();
ImGui::Begin("Motion", 0, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Image((void*)m_gBufferTextures[3]->getObjectName(), glm::vec2{ 1280, 720 } * 0.2f);
ImGui::Begin("GBuffer", 0, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Image((void*)m_gBufferTextures[0]->getObjectName(), glm::vec2{ 1280, 720 } *0.2f, { 0, 1 }, { 1, 0 });
ImGui::Image((void*)m_gBufferTextures[1]->getObjectName(), glm::vec2{ 1280, 720 } *0.2f, { 0, 1 }, { 1, 0 });
ImGui::Image((void*)m_gBufferTextures[2]->getObjectName(), glm::vec2{ 1280, 720 } *0.2f, { 0, 1 }, { 1, 0 });
ImGui::Image((void*)m_gBufferTextures[3]->getObjectName(), glm::vec2{ 1280, 720 } *0.2f, { 0, 1 }, { 1, 0 });
ImGui::End();
/*ImGui::Begin("ShadowMap", 0, ImGuiWindowFlags_AlwaysAutoResize);
......
......@@ -47,11 +47,6 @@ void PlayerSystem::handleKeyboard(KeyboardEvent e) {
SDL_SetRelativeMouseMode(SDL_FALSE);
}
break;
case SDL_SCANCODE_SPACE:
spaceDown = e.originalEvent.key.type == SDL_KEYDOWN;
break;
case SDL_SCANCODE_LSHIFT:
shiftDown = e.originalEvent.key.type == SDL_KEYDOWN;;
default:
break;
}
......@@ -90,13 +85,12 @@ void PlayerSystem::update(float dt) {
float speedMod = 1.0f;
// Move the camera based on WASD keyboard input
if (!ImGui::GetIO().WantCaptureKeyboard) {
if (wDown) moveDir -= glm::vec3(0, 0, 1);
if (m_keyState[SDL_SCANCODE_W]) moveDir -= glm::vec3(0, 0, 1);
if (m_keyState[SDL_SCANCODE_S]) moveDir += glm::vec3(0, 0, 1);
if (m_keyState[SDL_SCANCODE_A]) moveDir -= glm::vec3(1, 0, 0);
if (m_keyState[SDL_SCANCODE_D]) moveDir += glm::vec3(1, 0, 0);
if (spaceDown) moveDir += glm::vec3(0, 1, 0);
if (shiftDown) speedMod = 100;
if (m_keyState[SDL_SCANCODE_SPACE]) moveDir += glm::vec3(0, 1, 0);
if (m_keyState[SDL_SCANCODE_LSHIFT]) speedMod = 100;
if (m_keyState[SDL_SCANCODE_LEFT]) rotDir += glm::vec2(1, 0);
......
......@@ -70,22 +70,34 @@ int main(int argc, char *argv[]) {
// load a test scene
auto vaoCube = VertexArrayObjectCreator("cube.obj").create();
auto vaoSun = VertexArrayObjectCreator("uvsphere.obj").create();
auto vaoTestScene = VertexArrayObjectCreator("test_scene.obj").create();
// load a texture:
auto checkboardTexture = Texture2DFileManager::the()->get(Texture2DCreator("checkerboard.png"));
auto testTransparencyTexture = Texture2DFileManager::the()->get(Texture2DCreator("transparency_test.png"));
// look up all shader files starting with 'PBR' and build a ShaderProgram from it:
auto pbrShader = ShaderProgramCreator("PBR").attributeLocations(vaoTeapot->getAttributeLocations()).create();
auto pbrShader = ShaderProgramCreator("PBR")
.attributeLocations(vaoTeapot->getAttributeLocations())
.fragmentDataLocations(renderer.getGBufferLocations()).create();
// Create geometry objects that point to the previously initialized vaos
Geometry geom1 = { vaoSun };
Geometry geom2 = { vaoTeapot };
// Create a material that uses the loaded shader program
Material sunMaterial = { glm::vec4{1, 1, 1, 1}, glm::vec4{ 1, 1, 1, 1 }, checkboardTexture, pbrShader };
Material sunMaterial = { glm::vec4{1, 1, 1, 1}, glm::vec4{ 0, 0, 0, 1 }, checkboardTexture, pbrShader };
Material transparentMat = { glm::vec4{ 1, 1, 1, 1 }, glm::vec4{ 0, 0, 0, 1 }, testTransparencyTexture, pbrShader };
// Let's create a placeholder sun
auto scene = sceneGraph.create();
// Add a transform component to it so we are able to position it in space
auto sceneTransform = scene.assign<Transform>();
// Add a Drawable component to it so the renderer has something to draw
scene.assign<Drawable>(Geometry{ vaoTestScene }, sunMaterial);
sceneTransform->scale = glm::vec3(orbitals.solarRadius * orbitals.scaleFactor * 0.1, orbitals.solarRadius * orbitals.scaleFactor* 0.1, orbitals.solarRadius * orbitals.scaleFactor* 0.1);
sceneTransform->position = glm::vec3(0, -600, 0);
// Let's create a placeholder sun
auto sun = sceneGraph.create();
// Add a transform component to it so we are able to position it in space
......@@ -93,7 +105,7 @@ int main(int argc, char *argv[]) {
// Add a Drawable component to it so the renderer has something to draw
sun.assign<Drawable>(geom1, sunMaterial);
sunTransform->scale = glm::vec3(orbitals.solarRadius * orbitals.scaleFactor * 0.1, orbitals.solarRadius * orbitals.scaleFactor* 0.1, orbitals.solarRadius * orbitals.scaleFactor* 0.1);
sun.assign<Light>(glm::vec4(1, 1, 1, 500), glm::vec3(1, 0, 0), false);
sun.assign<Light>(glm::vec4(1, 1, 1, 6000), glm::vec3(1, 0, 0), false);
// create a planet!
// Mass in solar masses, Radius in solar radii, Eccentricity, Semimajor axis, Inclination, Ascending Node, Arg. of Periapsis, time at perihelion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment