Answer the question
In order to leave comments, you need to log in
Is there a problem with the shader when rendering?
I moved on. I figured out how to determine if a point is inside a frustum or not. I did it this way: I simply calculated the distance to each of the 6 planes, if it turns out to be negative, then the point does not lie inside the frustum. Implemented it all in a fragment shader.
Below is the implementation of this shader. I pass 6 square matrices of size 3 ABCDEF into it - each of them contains 3 vertices of the plane. A method was written in the shader that finds the distance between a point and a distancePointPlane. When the program starts, it draws color regardless of whether the polygon is selected or not. There shouldn't be any problems with transferring vertex coordinates. The problem is at the level of calculation in the shader. Help.
version 330 core
in vec3 normal_modelspace;
in vec3 vertex_modelspace;
in vec2 TexCoord;
in vec4 vertexColor;
in vec3 coord;
out vec4 color;
float distancePointPlane(float pointX, float pointY, float pointZ, float a, float b, float c, float d) {
float denom = sqrt(a * a + b * b + c * c);
return float((a * pointX + b * pointY + c * pointZ + d) / denom);
}
float distancePointPlane(vec3 point,mat3 matr) {
float v1Y0Y = matr[1][1] - matr[0][1];
float v2Z0Z = matr[2][2] - matr[0][2];
float v2Y0Y = matr[2][1] - matr[0][1];
float v1Z0Z = matr[1][2] - matr[0][2];
float v2X0X = matr[2][0] - matr[0][0];
float v1X0X = matr[1][0] - matr[0][0];
float a = v1Y0Y * v2Z0Z - v2Y0Y * v1Z0Z;
float b = v1Z0Z * v2X0X - v2Z0Z * v1X0X;
float c = v1X0X * v2Y0Y - v2X0X * v1Y0Y;
float d = -(a * matr[0][0] + b * matr[0][1] + c * matr[0][2]);
float s=0.0;
return distancePointPlane(a, point[1], point[2], a, b, c, d);
}
uniform mat3 A;
uniform mat3 B;
uniform mat3 C;
uniform mat3 D;
uniform mat3 E;
uniform mat3 F;
uniform vec3 light_worldspace;
uniform sampler2D ourTexture;
void main() {
vec3 n = normalize(normal_modelspace);
vec3 l = normalize(light_worldspace - vertex_modelspace);
float cosTheta = clamp( dot( n, l), 0,1 );
float ambient = 0.05;
float aF= distancePointPlane(vertex_modelspace,A);//нахожу расстояние от вершины модели до плоскости а
float bF= distancePointPlane(vertex_modelspace,B);
float cF= distancePointPlane(vertex_modelspace,C);
float dF= distancePointPlane(vertex_modelspace,D);
float eF= distancePointPlane(vertex_modelspace,E);
float fF= distancePointPlane(vertex_modelspace,F);
if(aF>=0.0 && bF>=0.0 && cF>=0.0 && dF>=0.0 && eF>=0.0 && fF>=0.0){
color = vertexColor;
}else{
color = texture(ourTexture, TexCoord)*(cosTheta + ambient);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question