0
\$\begingroup\$

I'd like to use the determinant of a matrix to draw a plane in the fragment shader. But I don't understand how to come up with the matrix. Let's say that I have 3 points that lie on the plane: A, B, and C. I don't know how to combine them into the matrix I need.

// "point" represents the current pixel in the shader. I tried this:

mat4 matrix = mat4(vec4(A.x, A.y, A.z, 1.0), 
                    vec4(B.x, B.y, B.z, 1.0), 
                    vec4(C.x, C.y, C.z, 1.0), 
                    vec4(point.x, point.y, point.z, 1.0));
    float result = determinant(matrix);
    
    if (result == 0.0) {
        // Color the plane.
        ALBEDO = vec3(.3, .3, .3);
    }
\$\endgroup\$
7
  • \$\begingroup\$ It's not clear to me what you're trying to do. Can you show us an example of the kind of visual output you're trying to create? \$\endgroup\$ Commented May 2, 2022 at 19:31
  • \$\begingroup\$ @DMGregory I'd just like every point that lies on the plane to be this color: vec3(.3, .3, .3). The output would literally look like a flat plane \$\endgroup\$ Commented May 3, 2022 at 15:50
  • \$\begingroup\$ What's the geometry input here? Are you trying to do something like raymarching, where you render a fullscreen quad and then sculpt the virtual geometry in the math? If so, what you've shown here is not the way to do it. Try taking a step back and editing your question to explain the context where you're trying to use this shader and why - that can help us narrow down what solutions would be appropriate for that use case. \$\endgroup\$ Commented May 3, 2022 at 15:57
  • \$\begingroup\$ @DMGregory Thanks. There actually is no use case. This is just a problem I came up with to help me understand how determinants work. I read that you can use the determinant to figure out if a point lies on a plane so I figured that I should be able to draw a plane using determinants, but I cant seem to do that. I suspect I'm inputting the matrix wrong. I'm confused about how to convert 4 vectors into a matrix.For the determinant should the vectors become rows or columns in the new matrix? And when I create a mat4() are the vector parameters rows or columns? \$\endgroup\$ Commented May 3, 2022 at 16:07
  • \$\begingroup\$ I wouldn't use a determinant for this at all. A single 4-vector and a dot product is enough to define a plane. That's why I'm having trouble wrapping my head around what you're trying to do. Do you have a particular source you were reading from that might help fill in this context? \$\endgroup\$ Commented May 3, 2022 at 16:14

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.