Commit 8b804ad1 authored by Dario Seyb's avatar Dario Seyb

added console and tweening

parent bd3e3ded
# Blender v2.71 (sub 0) OBJ File: 'cockpit_applied.blend'
# www.blender.org
v -0.342575 -0.852134 -1.943174
v -0.342575 -0.852134 -2.273623
v 0.342575 -0.852134 -2.273623
v 0.342575 -0.852134 -1.943174
v -0.342575 -0.476618 -1.943174
v -0.342575 -0.266119 -2.273623
v 0.342575 -0.266119 -2.273623
v 0.342575 -0.476618 -1.943174
vt -0.075306 0.294069
vt -0.405399 0.594247
vt -0.440086 0.590158
vt -0.075306 1.045536
vt -0.420490 0.654020
vt -0.669233 0.954111
vt -0.454515 0.644319
vt -0.616154 0.226492
vt 0.999900 1.000978
vt -0.000042 1.000978
vt -0.000042 0.000101
vt 0.999900 0.000100
vn -1.000000 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 1.000000 0.000000 0.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 0.843400 0.537300
s off
f 6/1/1 2/2/1 1/3/1
f 7/4/2 3/5/2 2/2/2
f 7/4/3 8/6/3 4/7/3
f 5/8/4 1/3/4 4/7/4
f 2/2/5 3/5/5 4/7/5
f 7/9/6 6/10/6 5/11/6
f 5/8/1 6/1/1 1/3/1
f 6/1/2 7/4/2 2/2/2
f 3/5/3 7/4/3 4/7/3
f 8/6/4 5/8/4 4/7/4
f 1/3/5 2/2/5 4/7/5
f 8/12/6 7/9/6 5/11/6
#define LAST_SHADER GEOMETRY
#pragma import "CommonDeferredFrag.glsl"
#pragma import "Utils.glsl"
#pragma import "terrain/mountainTexture.glsl"
in vec3 gUpVector_normalized;
in vec3 gPosInModelspace;
vec3 approxNormal;
float amplify(float d, float scale, float offset){
d = scale * d + offset;
d = clamp(d, 0, 1);
d = 1 - exp2(-2*d*d);
return d;
}
vec4 color() {
//approxNormal = approximateTerrainNormal(normalize(gPosInModelspace));
approxNormal = inNormal;
vec4 color = texture_getColor(gPosInModelspace, gUpVector_normalized, approxNormal);
inPosition += inNormal * height;
/*float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z);
float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z);
color = amplify(d1, 80, -0.5) * amplify(d2, 120, -0.5) * color;*/
color.w = 1.0;
return color;
}
vec4 emissive() {
return uEmissiveColor;
}
vec3 normal() {
return approxNormal;
}
vec4 specularSmoothness() {
return vec4(0.2, 0.2, 0.2, 0.2);
}
#version 410 core
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in vec3 tPosition[3];
in vec3 tPatchDistance[3];
in vec3 tNormal[3];
in vec2 tTexCoord[3];
//in float tHeight[3];
in vec3 tUpVector_normalized[3];
in vec3 tPosInModelspace[3];
out vec3 gNormal;
out vec3 gPosition;
out vec2 gTexCoord;
//out float gHeight;
//out float gSurfaceAngle;
out vec3 gUpVector_normalized;
out vec3 gPosInModelspace;
out vec3 gPatchDistance;
out vec3 gTriDistance;
void main()
{
vec3 A = tPosition[2] - tPosition[0];
vec3 B = tPosition[1] - tPosition[0];
gNormal = -normalize(cross(A, B));
gPatchDistance = tPatchDistance[0];
gNormal = tNormal[0];
gTexCoord = tTexCoord[0];
gPosition = tPosition[0];
//gHeight = tHeight[0];
//gSurfaceAngle = acos(dot(gNormal, tUpVector[0]));
gUpVector_normalized = tUpVector_normalized[0];
gPosInModelspace = tPosInModelspace[0];
gTriDistance = vec3(1, 0, 0);
gl_Position = gl_in[0].gl_Position; EmitVertex();
gNormal = tNormal[1];
gTexCoord = tTexCoord[1];
gPosition = tPosition[1];
//gHeight = tHeight[1];
//gSurfaceAngle = acos(dot(gNormal, tUpVector[1]));
gUpVector_normalized = tUpVector_normalized[1];
gPosInModelspace = tPosInModelspace[1];
gPatchDistance = tPatchDistance[1];
gTriDistance = vec3(0, 1, 0);
gl_Position = gl_in[1].gl_Position; EmitVertex();
gNormal = tNormal[2];
gTexCoord = tTexCoord[2];
gPosition = tPosition[2];
//gHeight = tHeight[2];
//gSurfaceAngle = acos(dot(gNormal, tUpVector[2]));
gUpVector_normalized = tUpVector_normalized[2];
gPosInModelspace = tPosInModelspace[2];
gPatchDistance = tPatchDistance[2];
gTriDistance = vec3(0, 0, 1);
gl_Position = gl_in[2].gl_Position; EmitVertex();
EndPrimitive();
}
#version 410 core
layout(vertices = 3) out;
in vec3 vNormal[];
in vec3 vPosition[];
in vec2 vTexCoord[];
out vec3 tcNormal[];
out vec2 tcTexCoord[];
out vec3 tcPosition[];
uniform mat4 uModelMatrix;
uniform vec3 cameraPosition;
#define ID gl_InvocationID
float getTessLevel(float d0, float d1){
float avg = (d0 + d1) / 2.0;
if(avg >= 100){
return 1;
}
if(avg >= 80){
return 2;
}
if(avg >= 60){
return 4;
}
if(avg >= 40){
return 8;
}
if(avg >= 20){
return 16;
}
if(avg >= 10){
return 32;
}
if(avg >= 0){
return 64;
}
else return 1;
}
void main(){
tcNormal[ID] = vNormal[ID];
tcTexCoord[ID] = vTexCoord[ID];
tcPosition[ID] = vPosition[ID];
if (ID == 0) {
float d0 = distance(cameraPosition, (uModelMatrix * vec4(tcPosition[0], 1)).xyz );
float d1 = distance(cameraPosition, (uModelMatrix * vec4(tcPosition[1], 1)).xyz );
float d2 = distance(cameraPosition, (uModelMatrix * vec4(tcPosition[2], 1)).xyz );
gl_TessLevelOuter[0] = getTessLevel(d1, d2);
gl_TessLevelOuter[1] = getTessLevel(d2, d0);
gl_TessLevelOuter[2] = getTessLevel(d0, d1);
gl_TessLevelInner[0] = 0.5 * gl_TessLevelOuter[2];
/*
float avgDist = (d0 + d1 + d2)/3.0;
vec3 midPoint;
float fDistance;
midPoint = (tcPosition[2] + tcPosition[0] / 2.0);
fDistance = distance(midPoint, cameraPosition) * 1;
gl_TessLevelOuter[0] = getTessLevel(fDistance, fDistance);
midPoint = (tcPosition[2] + tcPosition[0] / 2.0);
fDistance = distance(midPoint, cameraPosition) * 1;
gl_TessLevelOuter[1] = getTessLevel(fDistance, fDistance);
midPoint = (tcPosition[2] + tcPosition[0] / 2.0);
fDistance = distance(midPoint, cameraPosition) * 1;
gl_TessLevelOuter[2] = getTessLevel(fDistance, fDistance);
gl_TessLevelInner[0] = (gl_TessLevelOuter[0] + gl_TessLevelOuter[1] +gl_TessLevelOuter[2]) /3;
*/
}
}
#version 410 core
//#pragma import "noise/noise3d.glsl"
//#pragma import "terrain/sphereUV.glsl"
#pragma import "terrain/mountainTexture.glsl"
layout(triangles, equal_spacing, ccw) in;
in vec2 tcTexCoord[];
in vec3 tcNormal[];
in vec3 tcPosition[];
out vec3 tNormal;
out vec2 tTexCoord;
out vec3 tPosition;
//out float tHeight;
out vec3 tUpVector_normalized;
out vec3 tPosInModelspace;
out vec3 tPatchDistance;
uniform mat4 uViewProjectionMatrix;
uniform mat4 uModelMatrix;
uniform vec3 cameraPostion;
//vec3 mod289(vec3 x)
//{
// return x - floor(x * (1.0 / 289.0)) * 289.0;
//}
//vec4 mod289(vec4 x)
//{
// return x - floor(x * (1.0 / 289.0)) * 289.0;
//}
//vec4 permute(vec4 x)
//{
// return mod289(((x*34.0)+1.0)*x);
//}
//vec4 taylorInvSqrt(vec4 r)
//{
// return 1.79284291400159 - 0.85373472095314 * r;
//}
//vec3 fade(vec3 t) {
// return t*t*t*(t*(t*6.0-15.0)+10.0);
//}
//// Classic Perlin noise
//float cnoise(vec3 P)
//{
// vec3 Pi0 = floor(P); // Integer part for indexing
// vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1
// Pi0 = mod289(Pi0);
// Pi1 = mod289(Pi1);
// vec3 Pf0 = fract(P); // Fractional part for interpolation
// vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
// vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
// vec4 iy = vec4(Pi0.yy, Pi1.yy);
// vec4 iz0 = Pi0.zzzz;
// vec4 iz1 = Pi1.zzzz;
// vec4 ixy = permute(permute(ix) + iy);
// vec4 ixy0 = permute(ixy + iz0);
// vec4 ixy1 = permute(ixy + iz1);
// vec4 gx0 = ixy0 * (1.0 / 7.0);
// vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
// gx0 = fract(gx0);
// vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
// vec4 sz0 = step(gz0, vec4(0.0));
// gx0 -= sz0 * (step(0.0, gx0) - 0.5);
// gy0 -= sz0 * (step(0.0, gy0) - 0.5);
// vec4 gx1 = ixy1 * (1.0 / 7.0);
// vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
// gx1 = fract(gx1);
// vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
// vec4 sz1 = step(gz1, vec4(0.0));
// gx1 -= sz1 * (step(0.0, gx1) - 0.5);
// gy1 -= sz1 * (step(0.0, gy1) - 0.5);
// vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
// vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
// vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
// vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
// vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
// vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
// vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
// vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
// vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
// g000 *= norm0.x;
// g010 *= norm0.y;
// g100 *= norm0.z;
// g110 *= norm0.w;
// vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
// g001 *= norm1.x;
// g011 *= norm1.y;
// g101 *= norm1.z;
// g111 *= norm1.w;
// float n000 = dot(g000, Pf0);
// float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
// float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
// float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
// float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
// float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
// float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
// float n111 = dot(g111, Pf1);
// vec3 fade_xyz = fade(Pf0);
// vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
// vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
// float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
// return 2.2 * n_xyz;
//}
//// Classic Perlin noise, periodic variant
//float pnoise(vec3 P, vec3 rep)
//{
// vec3 Pi0 = mod(floor(P), rep); // Integer part, modulo period
// vec3 Pi1 = mod(Pi0 + vec3(1.0), rep); // Integer part + 1, mod period
// Pi0 = mod289(Pi0);
// Pi1 = mod289(Pi1);
// vec3 Pf0 = fract(P); // Fractional part for interpolation
// vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
// vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
// vec4 iy = vec4(Pi0.yy, Pi1.yy);
// vec4 iz0 = Pi0.zzzz;
// vec4 iz1 = Pi1.zzzz;
// vec4 ixy = permute(permute(ix) + iy);
// vec4 ixy0 = permute(ixy + iz0);
// vec4 ixy1 = permute(ixy + iz1);
// vec4 gx0 = ixy0 * (1.0 / 7.0);
// vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
// gx0 = fract(gx0);
// vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
// vec4 sz0 = step(gz0, vec4(0.0));
// gx0 -= sz0 * (step(0.0, gx0) - 0.5);
// gy0 -= sz0 * (step(0.0, gy0) - 0.5);
// vec4 gx1 = ixy1 * (1.0 / 7.0);
// vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
// gx1 = fract(gx1);
// vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
// vec4 sz1 = step(gz1, vec4(0.0));
// gx1 -= sz1 * (step(0.0, gx1) - 0.5);
// gy1 -= sz1 * (step(0.0, gy1) - 0.5);
// vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
// vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
// vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
// vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
// vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
// vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
// vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
// vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
// vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
// g000 *= norm0.x;
// g010 *= norm0.y;
// g100 *= norm0.z;
// g110 *= norm0.w;
// vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
// g001 *= norm1.x;
// g011 *= norm1.y;
// g101 *= norm1.z;
// g111 *= norm1.w;
// float n000 = dot(g000, Pf0);
// float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
// float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
// float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
// float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
// float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
// float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
// float n111 = dot(g111, Pf1);
// vec3 fade_xyz = fade(Pf0);
// vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
// vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
// float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
// return 2.2 * n_xyz;
//}
vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2){
return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2;
}
vec3 interpolate3D(vec3 v0, vec3 v1, vec3 v2){
return vec3(gl_TessCoord.x ) * v0 + vec3(gl_TessCoord.y) * v1 + vec3(gl_TessCoord.z) * v2;
}
void main(){
tNormal = interpolate3D(tcNormal[0], tcNormal[1], tcNormal[2]);
tTexCoord = interpolate2D(tcTexCoord[0], tcTexCoord[1], tcTexCoord[2]);
tNormal = normalize(tNormal);
tUpVector_normalized = tNormal;
tPatchDistance = gl_TessCoord;
tPosition = interpolate3D(tcPosition[0], tcPosition[1], tcPosition[2]);
tPosInModelspace = tPosition;
tPosition = normalize(tPosition);
//vec4 camWorld = uModelMatrix * vec4(tPosition, 1.0);
//tTexCoord = vec2(calculateU(tPosition), calculateV(tPosition));
//float noiseValue = sumUpOctaves_3d( tPosition , 8, 80.);
tPosition = mountain_getDisplacedPosition_modelspace(tPosition, tNormal);
//tHeight = noiseValue;
//tPosition += tNormal * re1() ;
//tNormal = inverse(transpose(mat3(uModelMatrix))) * normalize(tNormal);
tPosition = (uModelMatrix * vec4(tPosition, 1)).xyz;
gl_Position = uViewProjectionMatrix * vec4(tPosition, 1);
}
#version 410 core
in vec3 gNormal;
in vec3 gPosition;
in vec2 gTexCoord;
out vec3 vNormal;
out vec3 vPosition;
out vec2 vTexCoord;
void main(){
vNormal = gNormal;
vPosition = gPosition;
vTexCoord = gTexCoord;
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ void main()
gNormal = -normalize(cross(A, B));
gPatchDistance = tPatchDistance[0];
gNormal = tNormal[0];
gTexCoord = tTexCoord[0];
gPosition = tPosition[0];
......@@ -40,11 +40,11 @@ void main()
//gSurfaceAngle = acos(dot(gNormal, tUpVector[0]));
gUpVector_normalized = tUpVector_normalized[0];
gPosInModelspace = tPosInModelspace[0];
gNormal = tNormal[0];
gTriDistance = vec3(1, 0, 0);
gl_Position = gl_in[0].gl_Position; EmitVertex();
gNormal = tNormal[1];
gTexCoord = tTexCoord[1];
gPosition = tPosition[1];
......@@ -52,12 +52,12 @@ void main()
//gSurfaceAngle = acos(dot(gNormal, tUpVector[1]));
gUpVector_normalized = tUpVector_normalized[1];
gPosInModelspace = tPosInModelspace[1];
gNormal = tNormal[1];
gPatchDistance = tPatchDistance[1];
gTriDistance = vec3(0, 1, 0);
gl_Position = gl_in[1].gl_Position; EmitVertex();
gNormal = tNormal[2];
gTexCoord = tTexCoord[2];
gPosition = tPosition[2];
......@@ -65,7 +65,8 @@ void main()
//gSurfaceAngle = acos(dot(gNormal, tUpVector[2]));
gUpVector_normalized = tUpVector_normalized[2];
gPosInModelspace = tPosInModelspace[2];
gNormal = tNormal[2];
gPatchDistance = tPatchDistance[2];
gTriDistance = vec3(0, 0, 1);
gl_Position = gl_in[2].gl_Position; EmitVertex();
......
......@@ -5,15 +5,22 @@
#undef far
#undef up
enum class ProjectionMode {
Perspective,
Orthographic
};
struct Camera : Component<Camera> {
explicit Camera() : fov(75), near(0.1f), far(100), worldUp(glm::dvec3(0, 1, 0)), isMain(false), renderPassIndex(std::numeric_limits<uint32_t>::max()) {}
explicit Camera(float fov, float near, float far, glm::dvec3 up = glm::dvec3(0, 1, 0), bool isMain = false, uint32_t passIndex = std::numeric_limits<uint32_t>::max())
: fov(fov), near(near), far(far), worldUp(up), isMain(isMain), renderPassIndex(passIndex) { }
float fov;
float near;
float far;
glm::dvec3 worldUp;
bool isMain;
uint32_t renderPassIndex;
ProjectionMode mode = ProjectionMode::Perspective;
};
......@@ -9,9 +9,9 @@ using namespace ACGL::OpenGL;
struct Material {
glm::vec4 tintColor;
glm::vec4 emissiveColor;
SharedTexture2D mainTexture;
SharedTexture2D normalTexture;
SharedTexture2D SpecularSmoothnessTexture;
ConstSharedTextureBase mainTexture;
ConstSharedTextureBase normalTexture;
ConstSharedTextureBase specularSmoothnessTexture;
SharedShaderProgram prog;
bool castShadow;
RenderQueue queue;
......
......@@ -36,6 +36,8 @@ struct RenderPass {
ACGL::OpenGL::SharedFrameBufferObject compositingTarget;
ACGL::OpenGL::SharedFrameBufferObject txaaHistory;
Entity camera;
bool active;
bool renderToTextureOnly;
};
class RendererSystem : public System {
......@@ -121,7 +123,34 @@ public:
txaa->validate();
m_passIds[name] = m_passes.size();
m_passes.push_back({ kilobytes(4), kilobytes(4), kilobytes(4), target, txaa, cam });
m_passes.push_back({ kilobytes(4), kilobytes(4), kilobytes(4), target, txaa, cam, true, false });
}
void setRenderPassActive(StringHash pass, bool active) {
auto id = getRenderPassId(pass);
if (id == -1) {
return;
}
m_passes[id].active = active;
}
void setRenderPassOnlyTexture(StringHash pass, bool active) {
auto id = getRenderPassId(pass);
if (id == -1) {
return;
}
m_passes[id].renderToTextureOnly = active;
}
ACGL::OpenGL::ConstSharedTextureBase getRenderPassTarget(StringHash pass) {
auto id = getRenderPassId(pass);
if (id == -1) {
return nullptr;
}
return m_passes[id].txaaHistory->getColorAttachments()[0].texture;
}
uint32_t getRenderPassId(StringHash sh) {
......
......@@ -38,7 +38,6 @@ private:
Transform::Handle skyboxCamTransform;
Camera::Handle camera;
bool m_keyState[SDL_NUM_SCANCODES];
double speed = 5;
......@@ -47,6 +46,8 @@ private:
void update(float dt);
bool m_hasControl = true;
public:
CONSTRUCT_SYSTEM(PlayerSystem) {}
......@@ -57,6 +58,14 @@ public:
cameraTransform->position = p;
}
void setCockpitPosition(glm::dvec3 p) {
cockpitCamTransform->position = p;
}
void setHasControl(bool val) {
m_hasControl = val;
}
glm::dmat4 getRotation() {
return cameraTransform->rotation;
}
......@@ -65,6 +74,11 @@ public:
return cameraTransform->lastGlobalTransform.pos;
}