Hello Admins, Devs and Users, any help would be appreciated.
I am trying to use the displacement maps to get the displaced effect rather than create a geometry for my 3D models which will go into millions of faces. On the web, I was able to get these instructions for an older version of Defold which is no longer valid:
-
Create a New Project:
- Open Defold and create a new project using the “Basic 3D” template.
-
Import Textures:
- Drag your diffuse map (e.g.,
diffuse.png
) and displacement (height) map (e.g.,height.png
) into theassets
folder in your Defold project.
- Drag your diffuse map (e.g.,
-
Create a Material:
- Go to
Game
→Materials
and create a new material file nameddisplacement.material
.
- Go to
-
Setup the Vertex Shader:
- Right-click on the
assets
folder, go toNew
→Shader
, and create a new shader nameddisplacement.vp
. - Open
displacement.vp
and paste the following code:attribute vec4 position; attribute vec2 texcoord0; uniform mat4 view_proj; uniform sampler2D displacementMap; varying vec2 var_texcoord0; void main() { float displacement = texture2D(displacementMap, texcoord0).r; vec4 displaced_position = position + vec4(0.0, displacement * 0.1, 0.0, 0.0); // Adjust multiplier for displacement strength gl_Position = view_proj * displaced_position; var_texcoord0 = texcoord0; }
- Right-click on the
-
Setup the Fragment Shader:
- Right-click on the
assets
folder, go toNew
→Shader
, and create a new shader nameddisplacement.fp
. - Open
displacement.fp
and paste the following code:varying vec2 var_texcoord0; uniform sampler2D diffuseMap; void main() { gl_FragColor = texture2D(diffuseMap, var_texcoord0); }
- Right-click on the
-
Link Shaders in the Material:
- Open
displacement.material
and set theVertex Program
todisplacement.vp
andFragment Program
todisplacement.fp
. - Set the
Tag
todisplacement
.
- Open
-
Assign Textures in the Material:
- In
displacement.material
, add two texture units:- Name:
diffuseMap
, Type:texture
- Name:
displacementMap
, Type:texture
- Name:
- In
-
Create a Material File:
- Create a new
.material
file in theassets
folder (e.g.,displacement.material
) and set up the following properties:- Vertex Shader:
displacement.vp
- Fragment Shader:
displacement.fp
- Textures:
diffuseMap
,displacementMap
- Tag:
displacement
- Vertex Shader:
- Create a new
-
Create a Model:
- Right-click on the
assets
folder, go toNew
→Model
, and create a new model file namedplane.model
. - Set the material to
displacement.material
. - Assign the plane geometry (e.g.,
plane.dae
) to the model.
- Right-click on the
-
Assign Textures to the Model:
- In
plane.model
, assigndiffuse.png
to thediffuseMap
slot andheight.png
to thedisplacementMap
slot.
- In
-
Update the Render Script:
- Open your render script (e.g.,
main.render_script
) and ensure it includes the material tagdisplacement
.
- Open your render script (e.g.,
-
Run the Project:
- Save all changes and run your project.
- You should see your plane surface displaced based on the height map.
Can anyone help me with creating displaced surfaces using the Height Maps/Displacement Maps?
I just want to know how to take a “Plane” mesh(just flat surface) and give it artificial geometry so as to save the game from millions and billions of polys.
Any help please?