Problem with shader

Started by
0 comments, last by DividedByZero 8 years, 3 months ago

Hi Guys,

Today I started making a shader with the purpose of distorting anything below y=1 to follow the slope of the land.

Initial tests worked perfectly with a subdivided quad, but I am finding the geometry is getting corrupted for more complex models.

This is what is happening;

OMnBfTL.png

The vertex shader is as follows;

attribute vec3 in_Position;
uniform float in_Angle;
void main()
{
    vec4 object_space_pos=vec4(in_Position.x,in_Position.y,in_Position.z,1.0);
      
    float angle=in_Angle;
       
    if(angle>0.0)
    {
        if(object_space_pos.y<1.0 && object_space_pos.x<0.0)
            object_space_pos.y = tan(angle * (1.0 - object_space_pos.y) * 0.0174533) * object_space_pos.x;
        if(object_space_pos.y<1.0 && object_space_pos.x>0.0)
            object_space_pos.y -= (tan(angle * (1.0 - object_space_pos.y) * 0.0174533) * -object_space_pos.x);
    }
    if(angle<0.0)
    {
        if(object_space_pos.y<1.0 && object_space_pos.x<0.0)
            object_space_pos.y -= tan(angle * (1.0 - object_space_pos.y) * 0.0174533) * -object_space_pos.x;
        if(object_space_pos.y<1.0 && object_space_pos.x>0.0)
            object_space_pos.y = (tan(angle * (1.0 - object_space_pos.y) * 0.0174533) * object_space_pos.x);
    }
    gl_Position=gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION]*object_space_pos;
}

Any help would be greatly appreciated :)

Advertisement

Seems I was missing a + symbol on two of the lines.

This topic is closed to new replies.

Advertisement