Quote from: TheExDeus on December 31, 2014, 11:39:28 AMYes
Is it working for you too?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Quote from: TheExDeus on December 31, 2014, 11:39:28 AMYes
Is it working for you too?
Quote from: TheExDeus on December 28, 2014, 09:57:24 PMNo your picture looks correct. When I was speaking about the floor being blue, I was speaking of outputting JUST the vertex normals, not combined with the normal matrix. When you combine it with the normal matrix then:QuoteNo it seems correct. Compared it to Model Creator and had same color.Weird. What shader and what normal matrix did you use? I tried both your code which creates the normal matrix in shader, as well as the modified my code which does it on the CPU. In both cases I cannot get the floor to be blue. This is what I get:
I also tested the surface fix, that is why the surface draws correct side up. But the floor and walls are still wrong. The floor is in x/y plane, so the normal should be in z (blue).

d3d_draw_floor( 0, 0, 0, 512, 512, 0, background_get_texture(bkg_0), 16, 16 );
Quote from: TheExDeus on December 27, 2014, 10:39:17 PMQuoteI think that the normal matrix isn't calculated properly.If that would be the case, then model_view matrix would be wrong, as well as model_view_projection matrix. Essentially everything would be wrong then. I did have problems with normal matrix calculation previously though. Right now it's used in lighting engine, and it took me some time to make it look correctly. This is the part that calculates the matrices:
...
I believe that the view matrix isn't properly calculated.Code (edl) Selectvoid transformation_update(){It seems you try inverting and then transposing, while I think it should be the other way around. To be honest, I have seen both being used, so I never figured out which is correct. Like here it shows the way I did it: http://stackoverflow.com/questions/21079623/how-to-calculate-the-normal-matrix
if (enigma::transform_needs_update == true){
//Recalculate matrices
enigma::mv_matrix = enigma::view_matrix * enigma::model_matrix;
enigma::mvp_matrix = enigma::projection_matrix * enigma::mv_matrix;
//normal_matrix = invert(transpose(mv_submatrix)), where mv_submatrix is modelview top-left 3x3 matrix
enigma::Matrix4 tmpNorm = enigma::mv_matrix.Transpose().Inverse();
enigma::normal_matrix = enigma::Matrix3(tmpNorm(0,0),tmpNorm(0,1),tmpNorm(0,2),
tmpNorm(1,0),tmpNorm(1,1),tmpNorm(1,2),
tmpNorm(2,0),tmpNorm(2,1),tmpNorm(2,2));
enigma::transform_needs_update = false;
}
}
I will test some.
public static Matrix3f createNormalMatrix(Matrix4f matrix, Matrix3f normalMatrix){
// extract 4x4 matrix to 3x3 matrix
extract(matrix, normalMatrix);
// Invert the matrix
normalMatrix.invert();
// Transpose the matrix
normalMatrix.transpose();
return normalMatrix;
}// Vertex
in vec3 in_Position;
in vec3 in_Normal;
out vec3 v_Normal;
void main() {
v_Normal = normalize(normalMatrix * in_Normal);
gl_Position = modelViewProjectionMatrix * vec4( in_Position.xyz, 1.0);
}// Fragment
in vec3 v_Normal;
out vec4 out_FragColor;
vec3 encodeNormal(vec3 normal) {
normal = normalize( normal );
vec3 shifted = (normal+vec3(1.0, 1.0, 1.0))/2.0;
return shifted;
}
void main() {
out_FragColor = vec4( encodeNormal(v_Normal), 1.0 );
}in vec3 in_Position;
in vec3 in_Normal;
out vec3 v_Normal;
void main() {
mat3 extractedViewMatrix = mat3(viewMatrix);
mat3 normalMatrix = transpose(inverse(extractedViewMatrix));
v_Normal = normalize(normalMatrix * in_Normal);
gl_Position = modelViewProjectionMatrix * vec4( in_Position.xyz, 1.0);
}// Vertex
in vec3 in_Position;
in vec3 in_Normal;
out vec3 v_Normal;
void main() {
v_Normal = normalize(in_Normal);
gl_Position = modelViewProjectionMatrix * vec4( in_Position.xyz, 1.0);
}// Fragment
in vec3 v_Normal;
out vec4 out_FragColor;
void main() {
out_FragColor = vec4( v_Normal, 1.0 );
}Quote from: TheExDeus on December 27, 2014, 09:17:49 PMIt does? Well I spent the past 10 minutes arguing with Josh for no reason then.
ENIGMA does provide you with normal matrix. "uniform mat3 normalMatrix;" in GLSL.
Quote from: TheExDeus on December 27, 2014, 09:17:49 PMBecause OpenGL flips the y axis so the surfaces are flipped when drawn. An easy fix is to modify draw_surface(...). In my own OpenGL Java engine that I wrote, when I draw a surface like I do in this example, I just draw it with a quad model that has flipped y texture coords. I think that is the most practical fix, as it doesn't disrupt any math down the line, it is solely for viewing purposes.
Also, you can see the two surfaces are upside down. I don't really have an idea what to do in this case. I guess we just can keep it like this and allow people to rotate the projection how they choose. In 2D they will be correct side up, because in recent changes I made the default projection in surface_set_target() to flip the projection. We cannot do that when we want surfaces to be used with 3D.
Quote from: TheExDeus on December 27, 2014, 09:17:49 PMThanks ^^
The example is very well written. Has comments for every line, divides everything in chunks so people can learn more easily. I'm also impressed that you managed to do this even though we haven't documented some of the stuff, like the fact that surface_create() has a third optional parameter enabling depth buffer for that FBO.
Quote from: TheExDeus on December 27, 2014, 09:17:49 PMTo be completely honest I don't know if there would be a major performance gain in doing this. Regardless, I couldn't figure out how to do it in my own Java engine :c
We could also make a way to assign buffers to surfaces like GL, so you could add a depth texture and use that instead, without making a specific shader for that. I'm not sure how to do it efficiently now though.

