Commit b8c3cc2f authored by David Gilbert's avatar David Gilbert

Fixed normals - there should be no cracks anymore.

parent 6d5e240d
......@@ -17,21 +17,16 @@ 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];
gNormal = tNormal[0];
gTexCoord = tTexCoord[0];
gPosition = tPosition[0];
gTriDistance = vec3(1, 0, 0);
gl_Position = gl_in[0].gl_Position; EmitVertex();
//gNormal = tNormal[1];
gNormal = tNormal[1];
gTexCoord = tTexCoord[1];
gPosition = tPosition[1];
......@@ -39,7 +34,7 @@ void main()
gTriDistance = vec3(0, 1, 0);
gl_Position = gl_in[1].gl_Position; EmitVertex();
//gNormal = tNormal[2];
gNormal = tNormal[2];
gTexCoord = tTexCoord[2];
gPosition = tPosition[2];
......
......@@ -18,29 +18,26 @@ uniform vec3 cameraPosition;
float getTessLevel(float d0, float d1){
//return 1;
float avg = (d0 + d1) / 2.0;
if(avg >= 500){
if(avg >= 1000){
return 1;
}
if(avg >= 400){
if(avg >= 500){
return 2;
}
if(avg >= 300){
if(avg >= 400){
return 4;
}
if(avg >= 250){
if(avg >= 200){
return 8;
}
if(avg >= 200){
if(avg >= 100){
return 16;
}
if(avg >= 150){
if(avg >= 50){
return 32;
}
if(avg >= 100){
return 64;
}
if(avg >= 0){
return 64;
}
......
......@@ -213,7 +213,7 @@ void main(){
tPosition += tNormal * fBM( tPosition , 8, 64, 0.007) ;
tNormal = inverse(transpose(mat3(uModelMatrix))) * normalize(tNormal);
//tNormal = inverse(transpose(mat3(uModelMatrix))) * normalize(tNormal);
tPosition = (uModelMatrix * vec4(tPosition, 1)).xyz;
......
......@@ -15,23 +15,19 @@ out vec2 gTexCoord;
void main()
{
vec3 A = tPosition[2] - tPosition[0];
vec3 B = tPosition[1] - tPosition[0];
gNormal = -normalize(cross(A, B));
//gNormal = vec3(1.11, 1.11, 1.11);
gNormal = tNormal[0];
gTexCoord = tTexCoord[0];
gPosition = tPosition[0];
gl_Position = gl_in[0].gl_Position; EmitVertex();
//gNormal = tNormal[1];
gNormal = tNormal[1];
gTexCoord = tTexCoord[1];
gPosition = tPosition[1];
gl_Position = gl_in[1].gl_Position; EmitVertex();
//gNormal = tNormal[2];
gNormal = tNormal[2];
gTexCoord = tTexCoord[2];
gPosition = tPosition[2];
......
......@@ -11,8 +11,9 @@ out vec2 tcTexCoord[];
out vec3 tcPosition[];
uniform mat4 uModelMatrix;
uniform vec3 cameraPosition;
uniform float recursionDepth;
uniform vec2 viewport;
#define ID gl_InvocationID
......@@ -20,31 +21,33 @@ uniform vec3 cameraPosition;
float getTessLevel(float d0, float d1){
float avg = (d0 + d1) / 2.0;
if(avg >= 2500){
float factor = 1.0;
if(avg >= 2500 * factor){
return 1;
}
if(avg >= 1500){
if(avg >= 1500 * factor){
return 2;
}
if(avg >= 1000){
if(avg >= 1000 * factor){
return 4;
}
if(avg >= 500){
if(avg >= 500 * factor){
return 8;
}
if(avg >= 200){
if(avg >= 200 * factor){
return 16;
}
if(avg >= 100){
if(avg >= 100 * factor){
return 32;
}
if(avg >= 50){
if(avg >= 50 * factor){
return 64;
}
if(avg >= 0){
return 64;
}
else return 1;
else return 0;
}
......
......@@ -210,7 +210,7 @@ void main(){
//tPosition += tNormal * fBM( tPosition , 8, 32, 0.005 ) ;
tNormal = inverse(transpose(mat3(uModelMatrix))) * normalize(tNormal);
//tNormal = inverse(transpose(mat3(uModelMatrix))) * normalize(tNormal);
//tPosition = (uModelMatrix * vec4(tPosition, 1)).xyz;
//gl_Position = uViewProjectionMatrix * vec4(tPosition, 1);
......
......@@ -34,7 +34,7 @@ private:
bool m_keyState[SDL_NUM_SCANCODES];
float speed = 200;
float speed = 20;
void handleKeyboard(KeyboardEvent e);
void handleMouse(MouseEvent e);
......
......@@ -88,7 +88,7 @@ bool RendererSystem::startup() {
m_transformFeedbackBuffer->bind(GL_TRANSFORM_FEEDBACK_BUFFER);
m_transformFeedbackVAO->bind();
m_transformFeedbackBuffer->setData(GL_TRANSFORM_FEEDBACK_BUFFER, 200000*3*3*2, NULL, GL_DYNAMIC_COPY);
m_transformFeedbackBuffer->setData(GL_TRANSFORM_FEEDBACK_BUFFER, 100000 *3*3*2, NULL, GL_DYNAMIC_COPY);
// Second buffer
m_transformFeedbackVAO2 = SharedVertexArrayObject(new VertexArrayObject(GL_TRIANGLES));
......@@ -102,7 +102,7 @@ bool RendererSystem::startup() {
m_transformFeedbackBuffer2->bind(GL_TRANSFORM_FEEDBACK_BUFFER);
m_transformFeedbackVAO2->bind();
m_transformFeedbackBuffer2->setData(GL_TRANSFORM_FEEDBACK_BUFFER, 200000 * 3 * 3 * 2, NULL, GL_DYNAMIC_COPY);
m_transformFeedbackBuffer2->setData(GL_TRANSFORM_FEEDBACK_BUFFER, 100000 * 3 * 3 * 2, NULL, GL_DYNAMIC_COPY);
// Feedback objects
......@@ -283,12 +283,10 @@ void RendererSystem::frame(double interp, double totalTime) {
m_tfShaderProg->setUniform("uModelMatrix", drawCall.thisRenderTransform);
m_tfShaderProg->setUniform("uViewProjectionMatrix", viewProjectionMatrix);
m_tfShaderProg->setUniform("cameraPosition", glm::vec3{ camPos.x, camPos.y, camPos.z });
//m_transformFeedbackVAO->bind();
//m_transformFeedbackBuffer->bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
q->begin();
m_tfShaderProg->setUniform("recursionDepth", (float) i+1);
m_tfShaderProg->setUniform("viewport", windowSize);
q->begin();
// First pass will render the geometry vao into the transform feedback buffer which is the first one initially
if (i == 0) {
......@@ -299,8 +297,8 @@ void RendererSystem::frame(double interp, double totalTime) {
glEndTransformFeedback();
}
// If we're doing 2 recursion, render the first buffer into the second one.
else {
// If we're doing an odd number of recursion, render the first buffer into the second one.
else if (i % 2 == 1){
m_transformFeedbackVAO->bind();
m_transformFeedbackBuffer->bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
......@@ -311,6 +309,17 @@ void RendererSystem::frame(double interp, double totalTime) {
glEndTransformFeedback();
}
// Even number: Second -> First
else if (i % 2 == 2) {
m_transformFeedbackVAO2->bind();
m_transformFeedbackBuffer2->bindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, Feedback);
glBeginTransformFeedback(GL_TRIANGLES);
glDrawTransformFeedback(GL_PATCHES, Feedback2);
glEndTransformFeedback();
}
q->end();
......@@ -337,22 +346,23 @@ void RendererSystem::frame(double interp, double totalTime) {
drawCall.material.prog->setUniform("uPrevModelMatrix", drawCall.lastRenderTransform);
drawCall.material.prog->setUniform("uPrevViewProjectionMatrix", prevViewProjectionMatrix);
// Draw buffer content
if (drawCall.recursionDepth == 1) {
// Draw directly to screen
if (drawCall.recursionDepth == 0) {
drawCall.geometry.vao->render();
}
// Render feedback buffer 1
else if (drawCall.recursionDepth % 2 == 1) {
m_transformFeedbackVAO->bind();
m_transformFeedbackBuffer->bind(GL_ARRAY_BUFFER);
glDrawTransformFeedback(GL_PATCHES, Feedback);
}
else if (drawCall.recursionDepth){
// Render feedback buffer 2
else if (drawCall.recursionDepth % 2 == 0){
m_transformFeedbackVAO2->bind();
m_transformFeedbackBuffer2->bind(GL_ARRAY_BUFFER);
glDrawTransformFeedback(GL_PATCHES, Feedback2);
}
// Draw other stuff
else {
drawCall.geometry.vao->render();
}
m_lastGBufferRenderSubmitTime += (double)(SDL_GetPerformanceCounter() - counter2Start) * 1000.0 / SDL_GetPerformanceFrequency();
}
......
......@@ -142,7 +142,7 @@ Entity OrbitalSimulationSystem::addPlanet(Transform::Handle sun, std::string n,
auto planetEntity = m_scene->create();
auto planetTransform = planetEntity.assign<Transform>();
planetTransform->parent = sun;
planetEntity.assign<Drawable>(defaultGeom, planetMat, 1);
planetEntity.assign<Drawable>(defaultGeom, planetMat, 1 );
//planetEntity.assign<Light>(glm::vec4(1, 1, 1, 1), glm::vec3(1, 0, 0), false);
// Mass, Radius, 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