Home Technical Talk

How to get Texel Density in a shader in realtime?

interpolator
Offline / Send Message
Shrike interpolator
Hey, so I want to change my tiling based on texel density but for that I need the texel density in runtime somehow for my generic material library. 

Ive tried DDX DDY for screen space UVs but that dosnt work. Tiling by mesh bounds or so also dosnt make sense.

One idea would maybe be to calculate relative distance from 2 vertexes or something like that maybe?

How is texel density usually calculated in offline? Does anyone have any ideas or pointers how to achieve this in runtime at best on shader level? 

Replies

  • Klunk
    Offline / Send Message
    Klunk ngon master
    think you'd need to preprocess the mesh and encode the per vertex ratio of uv density to spatial density in say a vertex alpha channel.  
    not sure on the best method to compute this but off the top of my head I'd say....
    <area of all faces used by the vert >/<area of all map faces used by the vert>

  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter

    I've seen this done in engine l. it was basically like klunk describes but  we were generating textures and using material overrides for the viewmode rather than encoding anything into the mesh(cos that gets used for other stuff) 

    Imo it's a bit of a waste of time.  You can't use the GPU to get a good representation and it's a pain in the arse/slow to generate and handle the required data.
    Imo. It's much better to handle texel density validation at the authoring stage (which is very easy by comparison). 

    You can check whether you're using bigger textures than you need using the GPU - unreal has a viewmode that indicates how far from 1:1 pixel/texel density you are - copying that has potential to be useful but it's not giving you texel density,

    There's lots of ways to hack this in if you're prepared to do that sort of thing but it's kind of a dead end in terms of doing it in a normal pixel/vertex shader cos the information simply isn't there to work with
  • Shrike
    Offline / Send Message
    Shrike interpolator

    Thanks, Yeah thats a bit sad, I guess ill go with a combination of using mesh data to change tiling based on need, and a fixed houdini setup.

    Are you sure we couldnt calculate the uv offset of vertex 0 and vertex 1 as example and compared it to world offset of the same vertexes (assuming a perfectly projection with no distortion) somehow? IT dosnt need to be perfectly accurate. Youd need to somehow save that same variable for all the other verts however but thats not really how shaders work I guess. Youd need to keep the info around per UV island, yeah ok thats likely not going to happen. Edit: Or no youd need to keep the info for the entire mesh.
Sign In or Register to comment.