Giter Club home page Giter Club logo

Comments (3)

kleonc avatar kleonc commented on July 3, 2024 3

It seems the Gradient fills it only up to 256 pixels, but I don't really see the connection with width.

The whole Polygon2D is filled, but its texture repeating is disabled as its texture_filter is set to Inherit, and rendering/textures/canvas_textures/default_texture_repeat project setting is set to Disabled (both are default values).
For disabled repeating the texture is clamped to edge. Might be more obvious with a different texture:

texture repeat disabled texture repeat enabled
Godot_v4 2 2-stable_win64_umNfwF1iTB YjOz2eNfg3
TxH8gAHJtc explorer_yiu4lWP2wc

This works as expected, no bug in here.


I expected the polygon to get filled completely in the first color if the Gradient offsets are 0 and 1 and the interpolation mode is constant.

Whether the polygon gradient texture should be filled completely with the first color in such case seems debatable / expectations might differ. I'm not sure what's the expected behavior here.

Currently the GradientTexture1D's i-th pixel color (0 <= i < width) is determined by point-sampling the assigned Gradient at i / (float)(width - 1).

So it's like if you'd stretch the Gradient from the middle of the first pixel to the middle of the last pixel, and assign each pixel the color from the Gradient corresponding to the pixel's center. Something like:
I20IGwH9H9
The example is for linear sampling but it's sampled like that for all sampling modes. That's why for constant sampling mode the last pixel (i == width - 1) gets the color at Gradient's 1.0 offset.

For linear/cubic sampling modes I think it might be expected that the first/last pixels match the colors at 0.0/1.0 offsets exactly, hence it's sampled like that.

But maybe specifically for constant mode it should sample like (i + 0.5) / (float)width instead? 🤔 Not sure.
(see also #76164, kinda related discussion)

Seems like an arbitrary decision / up to discussion (so not really a bug).


  • Set the width of the Gradient to 300

  • Still the texture doesn't fill the polygon

  • It does though, after you ran the project once

There's indeed some problem with the GradientTexture1D's preview not updating, and the polygon not accounting for the new size of the texture:
(same in v4.3.beta1.official [a4f2ea9])
NIaNUZuwY9

This is definitely a bug.

from godot.

3ter avatar 3ter commented on July 3, 2024 1

Thanks a ton for this awesome explanation and precise definition of the actual bug that appeared.

So I'm going to increase the width now to at least the width of the polygon so I have enough colors available (even if it's not really changing quite so often when using constant). And additionally I won't trust the editor for now regarding this and only try it in the running scene.

from godot.

3ter avatar 3ter commented on July 3, 2024

By the way. The real issue I had was that I couldn't figure out how to fill a centered polygon:
3ter/godot-issue-polygon2d-gradient-fill@c735740.

image

When setting the points centered from the beginning I couldn't for the life of me get the texture to work:
image
image

When setting the points and using a transform instead it works like a charm:
image
image

from godot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.