Skip to content

Commit

Permalink
progrèsen cours
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-deliot committed Nov 6, 2017
1 parent 91a4717 commit a98069b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ vector<Vector> Camera::GetFrustumNearCorners()
Vector toTop = gameObject->GetUpVector() * nearZ * tan(fovWHalf * deg2rad);

vector<Vector> res;
Vector lol = gameObject->GetForwardVector();
res.push_back(gameObject->GetForwardVector() * nearZ - toRight + toTop); // Top Left
res.push_back(gameObject->GetForwardVector() * nearZ + toRight + toTop); // Top Right
res.push_back(gameObject->GetForwardVector() * nearZ + toRight - toTop); // Bottom Right
Expand Down
10 changes: 5 additions & 5 deletions Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ class Engine : public App
renderer->LoadTexture("data/debug2x2red.png");
gameObjects.push_back(guy);
rootObject->AddChild(guy);
guy->SetPosition(-10.0f, 0.0f, 0.0f);
guy->SetPosition(10.0f, 0.0f, 0.0f);
renderer->SetColor(Color(1.0, 1.0, 1.0, 1.0));
RotateObjectMouse* rotater = new RotateObjectMouse();
guy->AddComponent(rotater);
//guy->AddComponent(rotater);

GameObject* guy4 = new GameObject();
/*GameObject* guy4 = new GameObject();
guy4->SetName("guy4");
MeshRenderer* renderer5 = new MeshRenderer();
guy4->AddComponent(renderer5);
Expand All @@ -169,7 +169,7 @@ class Engine : public App
gameObjects.push_back(guy4);
rootObject->AddChild(guy4);
guy4->SetPosition(10.0f, 0.0f, 0.0f);
renderer5->SetColor(Color(1.0, 1.0, 1.0, 1.0));
renderer5->SetColor(Color(1.0, 1.0, 1.0, 1.0));*/

GameObject* cube1 = new GameObject();
cube1->SetName("cube1");
Expand Down Expand Up @@ -220,7 +220,7 @@ class Engine : public App
//cameraObject->RotateAround(cameraObject->GetRightVector(), 90);
mainCamera->SetupFrameBuffer(frameWidth, frameHeight);
FlyCamera* flyCam = new FlyCamera();
//cameraObject->AddComponent(flyCam);
cameraObject->AddComponent(flyCam);

// Set up skybox
skybox = new Skybox();
Expand Down
3 changes: 3 additions & 0 deletions GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ class GameObject
rotation.m[i][j] = temp[i * 4 + j];
}
}
/*rotation.m[2][0] = -rotation.m[2][0];
rotation.m[2][1] = -rotation.m[2][1];
rotation.m[2][2] = -rotation.m[2][2];*/
MarkTransformAsChanged();
}

Expand Down
2 changes: 1 addition & 1 deletion Shaders/basic_shader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ void main()
+ specular * (lightColor * lightStrength);

gl_FragData[0] = fragment_color;
gl_FragData[1] = vec4(worldNormal, 1.0);
gl_FragData[1] = vec4(worldNormal.xyz * 0.5f + 0.5f, 1.0);
}
#endif
26 changes: 14 additions & 12 deletions Shaders/ssr_fx.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ uniform vec3 nearBottomLeft;
const vec2 quadVertices[4] = vec2[4]( vec2( -1.0, -1.0), vec2( 1.0, -1.0), vec2( -1.0, 1.0), vec2( 1.0, 1.0));

out vec2 vtexcoord;
out vec3 vViewPos;
out vec3 vsNearPos;

void main( )
{
gl_Position = vec4(quadVertices[gl_VertexID], 0.0, 1.0);
vtexcoord = (quadVertices[gl_VertexID] + 1.0) / 2.0;
vViewPos.x = mix(nearBottomLeft.x, nearBottomRight.x, vtexcoord.x);
vViewPos.y = mix(nearBottomLeft.y, nearTopLeft.y, vtexcoord.y);
vViewPos.z = nearBottomLeft.z;
vsNearPos.x = mix(nearBottomLeft.x, nearBottomRight.x, vtexcoord.x);
vsNearPos.y = mix(nearBottomLeft.y, nearTopLeft.y, vtexcoord.y);
vsNearPos.z = -nearBottomLeft.z;
}
#endif

Expand All @@ -37,11 +37,11 @@ uniform float farZ;

const float maxSteps = 256;
const float maxDistance = 200.0;
const float stride = 2.0;
const float zThickness = 0.1;
const float stride = 1.0;
const float zThickness = 1.0;

in vec2 vtexcoord;
in vec3 vViewPos;
in vec3 vsNearPos;

out vec4 pixelColor;

Expand Down Expand Up @@ -128,6 +128,7 @@ bool FindSSRHit(vec3 csOrig, vec3 csDir, float jitter,
hitPixel = permute ? P.yx : P;
// You may need hitPixel.y = renderSize.y - hitPixel.y; here if your vertical axis
// is different than ours in screen space
//hitPixel.y = renderSize.y - hitPixel.y;
float tempZ = (2 * nearZ) / (farZ + nearZ - texture(depthBuffer, hitPixel / renderSize).x * (farZ - nearZ));
sceneZMax = -(tempZ * (farZ - nearZ) + nearZ);
}
Expand All @@ -148,17 +149,17 @@ void main()
if(z >= 0.9999f)
return;

vec3 vsPos = vViewPos + normalize(vViewPos) * (z * (farZ - nearZ) + nearZ);
vsPos.z = -vsPos.z;
vec3 vsNormal = (viewMatrix * vec4(texture(normalBuffer, vtexcoord).xyz, 0)).xyz;
vec3 vsPos = vsNearPos + normalize(vsNearPos) * (z * (farZ - nearZ) + nearZ);
vec3 vsNormal = (viewMatrix * vec4(texture(normalBuffer, vtexcoord).xyz * 2.0f - 1.0f, 0)).xyz;
//vec3 vsNormal = texture(normalBuffer, vtexcoord).xyz * 2.0f - 1.0f;

// Screen Space Reflection Test
vec3 vsReflect = reflect(normalize(vViewPos), vsNormal);
vsReflect.z = -vsReflect.z;
vec3 vsReflect = reflect(normalize(vsNearPos), vsNormal);
vec2 hitPixel = vec2(0, 0);
vec3 hitPoint = vec3(0, 0, 0);
vec2 uv2 = vtexcoord * renderSize;
float jitter = mod((uv2.x + uv2.y) * 0.25, 1.0);
jitter = 0;
bool hit = FindSSRHit(vsPos, vsReflect, jitter, hitPixel, hitPoint);

// Move hit pixel from pixel position to UVs
Expand All @@ -173,6 +174,7 @@ void main()
float blend = blendScreen * blendBackFace * blendDist;

// Combine colors
blend = 1;
vec4 hitColor = texture(colorBuffer, hitPixel.xy);
pixelColor = mix(pixelColor, hitColor, blend * 0.5);
}
Expand Down

0 comments on commit a98069b

Please sign in to comment.