c++ - How to obtain texture coordinate from arbitrary position in HLSL -


enter image description here

i'm working on c++ project using directx 11 hlsl shaders.

i have texture mapped onto geometry. each vertex of geometry has position , texture coordinate.

in pixel shader, can obtain texture coordinate 1 pixel. how can sample color neighboring pixels?

for example pixel @ position 0.2 / 0, texture coordinate 0.5 / 0, blue. how texture coordinate let's 0.8 / 0?

edit:

what i'm implementing volume renderer using raycasting. volume to-be-rendered set of 2d slices parallel , aligned, not equidistant. volume use directx's texture3d class in order interpolation in z direction.

now cast rays through volume , sample 3d texture value @ equidistant steps on ray. problem comes play. cannot sample texture3d @ current ray position, slices not equidistant. have somehow "lookup" texture coordinate of position in 3d space , sample texture using texture coordinate.

i have idea how implement this, additional texture3d of same size color of texel @ position xyz can interpreted texture coordinate @ position xyz.

this solve problem think maybe overkill , there might simpler way accomplish same thing.

edit 2:

here illustration of sampling problem trying fix.

enter image description here

the root of problem texture3d distorted in z direction.

from within 1 single pixelshader instance want obtain texture coordinate any given position xyz in volume, not current fragment being rendered.

edit 3:

thanks comments , suggestions.

the distances between slices in z-order can random, cannot described mathematically function. have simple class, e.g.

struct vertex {   float4 position; // position in space   float4 texcoord; // position in dataset } 

i pass objects buffer of vertex shader. there, values passed through pixel shader. interpolation set d3d11_filter_min_mag_mip_linear nice interpolation data , respective texture coordinates. signature of pixel shader looks this:

float4 pshader( float4 position : sv_position               , float4 texcoord : texcoord               ) : sv_target {   ... } 

so each fragment to-be-rendered on screen, position in space ( position ) , corresponding position ( texcoord ) in ( interpolated ) dataset. far good.

now, pshader instance, want access not texcoord @ position, texcoords of other positions.

i want raycasting, each screen-space fragment, want cast ray , sample volume dataset @ discrete steps.

enter image description here

the black plane symbolizes screen. other planes dataset slices aligned , parallel, not equidistant. green line ray cast screen dataset. red spheres locations want sample dataset.

directx knows how interpolate stuff correctly, every screen-space fragment.

i thought access interpolation function , query interpolated texcoord position xyz. seems directx has not mechanism this.

so solution might use 1d-texture z-lookup , interpolate between values manually in shader. use information lookup pixel value @ position.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -