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 8536411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:39:27+00:00 2026-06-11T10:39:27+00:00

I’m working on creating a shader to generate terrain with shadows. My starting point

  • 0

I’m working on creating a shader to generate terrain with shadows.

My starting point is to clone the lambert shader and use a ShaderMaterial to eventually customise it with my own script.

The standard method works well:

var material = new MeshLambertMaterial({map:THREE.ImageUtils.loadTexture('images/texture.jpg')});

var mesh = new THREE.Mesh(geometry, material);

etc

The result:
Result with standard lambert material

However I’d like to use the lambert material as a base and work on top of it, so I tried this:

var lambertShader = THREE.ShaderLib['lambert'];
var uniforms = THREE.UniformsUtils.clone(lambertShader.uniforms);

var texture = THREE.ImageUtils.loadTexture('images/texture.jpg');
uniforms['map'].texture = texture;

var material = new THREE.ShaderMaterial({
    uniforms: uniforms,
    vertexShader: lambertShader.vertexShader,
    fragmentShader: lambertShader.fragmentShader,
    lights:true,
    fog: true
});

var mesh = new THREE.Mesh(geometry, material);

The result for this one:
Result for cloning lambert shader and changing map uniforms

It looks as if the shader is not taking into account the new texture I have added, however looking at the inspector when I logged the uniforms, the map object has the correct values.

I’m pretty new to three so I might be doing something fundamentally wrong, if someone could point me in the right direction here, that would be great.

I can also put up demo links if that would be helpful?

Thanks,
Will

EDIT:

Here are some demo links.

Demo with shader material: http://dev.thinkjam.com/experiments/threejs/terrain/terrain-shader-material.html

Demo with working lambert material: http://dev.thinkjam.com/experiments/threejs/terrain/terrain-lambert-material.html

  • 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-06-11T10:39:28+00:00Added an answer on June 11, 2026 at 10:39 am

    The reason this doesn’t work is the default Three.js lambert shader uses the preprocessor macro directive #ifdef to determine whether to use maps, envmaps, lightmaps, etc etc.

    The Three.js WebGLRenderer sets the appropriate preprocessor directives (#define) to enable these pieces of the shaders based on whether certain properties exist on the material object.

    If you’re set on taking the approach of cloning & modifying the default shaders, you will have to set relevant properties on the material. For texture maps, the Three.js WebGLRenderer.js has this line:

    parameters.map ? "#define USE_MAP" : ""
    

    So try setting material.map = true; for your shader material.

    Of course, if you know you’re going to be writing your own shader and you don’t need the dynamic inclusion of various shader snippets, you can just write the shader explicitly and you won’t need to worry about this.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.