• Advertisement
Sign in to follow this  

Problem with shader

This topic is 839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement