Parallax Mapping Shader concave and convex feeling "turn"

Source: Internet
Author: User

Original http://www.azure.com.cn/default.asp?cat=11&page=2

Parallax Mapping is to offset the texture coordinates by the height in the height map,
To visually deceive the observer, producing a very concave and convex illusion.

Uniform VEC3 fvlightposition;
Uniform VEC3 fveyeposition;

Varying VEC2 texcoord;
Varying VEC3 viewdirection;
Varying VEC3 lightdirection;

Attribute VEC3 Rm_binormal;
Attribute VEC3 rm_tangent;

void Main (void)
{
Gl_position = Ftransform ();
Texcoord = Gl_multitexcoord0.xy;

VEC4 fvobjectposition = Gl_modelviewmatrix * GL_VERTEX;

VEC3 fvviewdirection = fveyeposition-fvobjectposition.xyz;
VEC3 fvlightdirection = fvlightposition-fvobjectposition.xyz;

VEC3 fvnormal = Gl_normalmatrix * GL_NORMAL;
VEC3 fvbinormal = Gl_normalmatrix * RM_BINORMAL;
VEC3 fvtangent = Gl_normalmatrix * rm_tangent;

viewdirection.x = Dot (fvtangent, fvviewdirection);
VIEWDIRECTION.Y = Dot (fvbinormal, fvviewdirection);
Viewdirection.z = Dot (fvnormal, fvviewdirection);

lightdirection.x = Dot (fvtangent, fvlightdirection.xyz);
LIGHTDIRECTION.Y = Dot (fvbinormal, fvlightdirection.xyz);
Lightdirection.z = Dot (fvnormal, fvlightdirection.xyz);

}

Uniform VEC4 fvambient;
Uniform VEC4 fvspecular;
Uniform VEC4 fvdiffuse;
Uniform float fspecularpower;

Uniform sampler2d basemap;
Uniform sampler2d BumpMap;
Uniform sampler2d Parallax;

Varying VEC2 texcoord;
Varying VEC3 viewdirection;
Varying VEC3 lightdirection;

Void main (void)
{
   vec3  fvviewdirection  = normalize (viewdirection);
   vec4  height           = Texture2D (Parallax, Texcoord);
   Float uoffset          = (height.x-0.5) *0.11* fvviewdirection.x;
   Float voffset          = (height.x-0.5) *0.11* FVVIEWDIRECTION.Y;
   vec2 modifytexcoord    = vec2 (Texcoord.x+uoffset, texcoord.y+voffset); 
  
   vec3  fvlightdirection = normalize (lightdirection);
   vec4  avent = texture2d (BumpMap, Modifytexcoord);
   Float d = dot (avent.xyz, fvlightdirection);
   Float Shadow = Clamp ((D-AVENT.W) * 1.8 + 0.5, 0.0, 1.0);
   shadow = Shadow * Shadow * (3.0-2.0 * shadow);

  
   vec3  fvnormal         = Normalize (   AVENT.XYZ * 2.0-1.0 );
   float fndotl           = dot (fvnormal, Fvlightdirection);
  
   vec3  fvreflection     = Normalize (((2.0 * fvnormal) * Fndo TL)-fvlightdirection);
 
   float frdotv           = max (0.0, Dot ( Fvreflection, fvviewdirection));

VEC4 Fvbasecolor = texture2d (Basemap, Modifytexcoord);

VEC4 fvtotalambient = fvambient * FVBASECOLOR;
VEC4 fvtotaldiffuse = fvdiffuse * Fndotl * FVBASECOLOR;
VEC4 fvtotalspecular = fvspecular * (Pow (FRDOTV, fspecularpower));

Gl_fragcolor = Fvtotalambient + (fvtotaldiffuse + fvtotalspecular) * shadow;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.