Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angled Planes #3

Open
sdraper69 opened this issue Jan 25, 2019 · 0 comments
Open

Angled Planes #3

sdraper69 opened this issue Jan 25, 2019 · 0 comments

Comments

@sdraper69
Copy link

This is great, however it only seems to work if the section box is aligned to the XYZ axis.

I am trying to get it to work when the box is at any angle, however I cant get the shader to work right, i believe due to the camera position. I am working out the dot product but the results are not always correct. Heres my shader code...

fragmentClipping2: '
uniform vec3 color;
uniform vec3 clippingLow;
uniform vec3 clippingHigh;
uniform vec3 planeNormal1;
uniform vec3 planeNormal2;
uniform vec3 planeNormal3;
uniform vec3 planeNormal4;
uniform vec3 planeNormal5;
uniform vec3 planeNormal6;

uniform float planeDistance1;
uniform float planeDistance2;
uniform float planeDistance3;
uniform float planeDistance4;
uniform float planeDistance5;
uniform float planeDistance6;

uniform int reverse;

varying vec3 pixelNormal;
varying vec4 worldPosition;
varying vec3 camPosition;

bool isClipped(vec4 point){

vec4 planes[6];
planes[0]=vec4(planeNormal1.x,planeNormal1.y,planeNormal1.z,planeDistance1);
planes[1]=vec4(planeNormal2.x,planeNormal2.y,planeNormal2.z,planeDistance2);
planes[2]=vec4(planeNormal3.x,planeNormal3.y,planeNormal3.z,planeDistance3);
planes[3]=vec4(planeNormal4.x,planeNormal4.y,planeNormal4.z,planeDistance4);
planes[4]=vec4(planeNormal5.x,planeNormal5.y,planeNormal5.z,planeDistance5);
planes[5]=vec4(planeNormal6.x,planeNormal6.y,planeNormal6.z,planeDistance6);

for (int i=0;i<6;i++){
float dotProduct=dot(point.xyz,planes[i].xyz)+planes[i].w;
float dotProduct2=dot(camPosition.xyz,planes[i].xyz);

if(dotProduct<0.0 && dotProduct2 <0.0){
return true;
}

if(dotProduct<0.0 && dotProduct2>0.0){
return false;
}
}
return false;
}

void main( void ) {

float shade = (
3.0 * pow ( abs ( pixelNormal.y ), 2.0 )
+ 2.0 * pow ( abs ( pixelNormal.z ), 2.0 )
+ 1.0 * pow ( abs ( pixelNormal.x ), 2.0 )
) / 3.0;


if(isClipped(worldPosition)){

discard;
}
else{
gl_FragColor = vec4( color * shade, 1.0 );
return;
}
}'

looks good here...

image

but if i rotate the camera you can see its not capping correctly

image

Any help or suggestions would be greatly appriciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant