question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gradientMap GLSL is probably not correct?

See original GitHub issue
Description of the problem

Looking at the gradientmap GLSL

this line

 vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );

this will not actually give a correct gradient. Imagine you have a 2x1 texture.

The correct gradient is here
       |             |
       V             V
+-------------+-------------+
|             |             |
+-------------+-------------+
^                           ^
|                           |
But the code above uses this. That means much of the sampling is outside gradient.

In other words you need to read the gradient from the center of the first texel to the center of the last texel. Past the center on either side is just solid color. The linear interpolation happens between texels which are defined by center points.

The correct code unfortunately requires the width of the gradient texture

 float gradientPos = dotNL * 0.5 + 0.5;
 float sampleLoc = 0.5 + (gradientWidth - 1) * gradientPos;
 vec2 coord = vec2(sampleLoc / gradientWidth, 0.0 );

Does anyone care?

Three.js version
  • Dev
  • r94

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Dec 5, 2019

I mean introducing an alternative API for defining gradients.

Sidenote: Apart from defining the amount of tones you could also allow the definition of the respective thresholds (which define when you switch from one tone to the next one).

1reaction
Mugen87commented, Dec 5, 2019

@WestLangley Sounds interesting, yes. I mean introducing an alternative API for defining gradients.

However, @greggman seems to have issues with the term gradientMap itself. Because in cel shading, you are not rendering real color gradients but single tones.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenGL GLSL: How to implement the concept of gradient map ...
Based on the image and description, it looks like this maps the original grayscale value of the image to the blue-green gradient.
Read more >
Gradient map - GDQuest
In this tutorial, you'll learn how to use a shader to change a sprite's colors. This is useful for refining or completely changing...
Read more >
Gradient Map Shader in Godot 3.1: shader tutorial - YouTube
Learn to code shaders with Godot: http://bit.ly/intro-to-shaders-godotGonkee's fog shader : https://www.youtube.com/watch?v=QEaTsz_0o44Fire ...
Read more >
P: Gradient Map Adjustment Layer PS 23 is not back...
I try again with a new post since the previous one has not been understood. Using in Photoshop 23.0 the "Gradient Map" adjustment...
Read more >
[LWRP] Creating a simple gradient map shader - Unity Forum
The outermost colors of the gradient texture are blue and yellow, yet in between the two there seem to be all sorts of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found