Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:17:34+00:00 2026-05-28T16:17:34+00:00

I am trying to make an app which use displacement map for 3d effect.

  • 0

I am trying to make an app which use displacement map for 3d effect. In Flash it can be done using displacement filter like shown here: http://flashflex.com/pixel-bender-displacement-map-fakes-3d-effect-update/. There are few apps who do that on iPhone like one here: http://www.youtube.com/watch?v=NvCHHUN8nnE

I am wondering how do they perform this.

I am trying to use displacement map based technique describe here: http://www.cocos2d-iphone.org/forum/topic/11659 but it seems to be slow to be done on the fly.

Any pointer would be highly appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:17:35+00:00Added an answer on May 28, 2026 at 4:17 pm

    Perhaps the simplest way to achieve displacement mapping in OpenGL ES 2.0 is also probably the fastest. You need two textures, one to contain color (a regular one), and a displacement map. When sampling the regular texture normally, your fragment shader would look like:

    uniform sampler2D myTexture;
    varying vec2 texcoords;
    
    void main()
    {
        gl_FragColor = texture2D(myTexture, texcoords);
    }
    

    This is pretty simple stuff. Now, to achieve displacement mapping, you need to:

    uniform sampler2D myTexture;
    uniform sampler2D myDisplacementMap;
    varying vec2 texcoords;
    
    void main()
    {
        vec2 displacement = 0.1 * texture2D(myDisplacementMap, texcoords).rg;
        gl_FragColor = texture2D(myTexture, texcoords + displacement);
    }
    

    This is also simple. You have another texture where red and green are used as x and y for the displacement. This way, however, you only get static, view-independent displacement. To get real displacement, one would need to generate texture tangents and bitangents which contain the directions of texture axes in object space (a tricky concept, read the article). Once you have them, all you need is object-space eye position (can be calculated by multiplying vertex position by modelview-projection inverse in vertex shader), and by projecting this on the tangent/bitangent vectors, you can modulate the displacement in order to be view dependent:

    attribute vec3 position, tangent, bitangent;
    attribute vec2 texcoord;
    varying vec2 texcoords;
    varying vec3 eye_dir, tan, bitan;
    uniform matrix4f modelviewProjectionMatrix;
    uniform matrix4f modelviewProjectionMatrixInverse;
    
    void main()
    {
        gl_Position = modelviewProjectionMatrix * vec4(position, 1.0);
        tan = tangent;
        bitan = bitangent;
        texcoords = texcoord;
    }
    

    (that was vertex shader), and fragment shader here:

    uniform sampler2D myTexture;
    uniform sampler2D myDisplacementMap;
    varying vec2 texcoords;
    varying vec3 eye_dir, tan, bitan;
    
    void main()
    {
        vec2 eyen = normalize(eye_dir);
        vec2 modulation = vec2(dot(eyen, normalize(tan)), dot(eyen, normalize(bitan)));
        vec2 displacement = 0.1 * texture2D(myDisplacementMap, texcoords).rg * modulation;
        gl_FragColor = texture2D(myTexture, texcoords + displacement);
    }
    

    And that should do the trick … (note i wrote that from head so if there are any errors, don’t hesitate to comment)

    EDIT: And there were errors, I swapped order of arguments to texture2D (sampler goes first).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make my app a good Windows citizen, so I use matching
I was trying to make an app which also had the facility to let
I'm trying to make a real simple app in which clicking a button has
I'm trying to set up gradual engagement in my utility app which people can
OK I am trying to make a app which will only accept 1 word
I'm trying to make an app for android using facebook's SSO, so first i
I'm trying to make an app that can work on multiple devices. Desktop, Mobile
I am trying to make an app that will pass data between two servers
I'm trying to make my app publish to all my friend's walls. From what
I have an app with tabbar and webview. I'm trying to make the app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.