Sign in to follow this  
quasty

HLSL to GLSL conversion: tex2Dgrad()

Recommended Posts

Hi, I'm trying to implement the Parallax Occlusion Example in GLSL and this is working fine so far - except for one part: I'm trying to find a GLSL counterpart for the HLSL function
vec4 texel = tex2Dgrad( sampler2D tex, vec2 UV, vec2 dx, vec2 dy);
I calculated the gradients dx & dy using dFdx()/dFdy() but I couldn't find anything similar in the GLSL reference manual for tex2Dgrad(). How do I get the same functionality in GLSL? thank you very much

Share this post


Link to post
Share on other sites
There is the "texture2D" function. It generates a 4-dimensional vector and takes some params I don't really know off-hand. This is how I use it to calculate a fragment's color based on the texture:

uniform sampler2D TexMap1;

void main()
{
vec4 color = texture2D(TexMap1, gl_TexCoords[0].st);
gl_FragColor = color;
}

Share this post


Link to post
Share on other sites
Thanks but I ment a texture2D lookup with additional gradients (dx & dy)?

In HLSL a tex2D(sampler, UV) exists, and a tex2Dgrad(sampler, UV, dx, dy)
In GLSL a texture2D(sampler, UV) exists, but I couldn't find any sort of texture2Dgrad(sampler, UV, dx, dy)?

Share this post


Link to post
Share on other sites
Quote:
Original post by quasty
Thanks but I ment a texture2D lookup with additional gradients (dx & dy)?

In HLSL a tex2D(sampler, UV) exists, and a tex2Dgrad(sampler, UV, dx, dy)
In GLSL a texture2D(sampler, UV) exists, but I couldn't find any sort of texture2Dgrad(sampler, UV, dx, dy)?
There is no texture2DGrad function, yet. It is part of the proposed extension GL_ARB_shader_texture_lod. You can read more about it here. If you need it to get around that flow-control issue they talk about in the article, you can just move the entire texture2D call outside of flow-control for now, like in their Fragment Shader 3, and it should give the same results as using texture2DGrad inside flow-control would give. If you need it for something else I'm afraid you will have to wait.

Share this post


Link to post
Share on other sites
I am not sure what you would be using dy/dx for when it comes to textures, but IIRC GLSL has


float x = dFdx(10.0);
float y = dFdy(10.0);




you could use them and send that to the texture function? Like I said I am not sure what you are trying to accomplish...

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
There is no texture2DGrad function, yet. It is part of the proposed extension GL_ARB_shader_texture_lod. You can read more about it here. If you need it to get around that flow-control issue they talk about in the article, you can just move the entire texture2D call outside of flow-control for now, like in their Fragment Shader 3, and it should give the same results as using texture2DGrad inside flow-control would give. If you need it for something else I'm afraid you will have to wait.


Thank you, although not the answer I was hoping for and ATM I don't see a way how this could work if a texture2D cannot be called from within a loop in GLSL. ??? But it still puzzles me - I found this approach of Parallax Occlusion Mapping using GLSL:
http://graphics.cs.brown.edu/games/SteepParallax/index.html

Although the shaders doesn't seemed to be complete, he somehow wasn't effected by this. In the PDF (http://graphics.cs.brown.edu/games/SteepParallax/mcguire-steepparallax.pdf) to this article a different shader is shown using texture2DLod() for the lookup in the loop. Does this somehow change things?

And I'm pretty sure I've seen OpenGL parallax occlusion mapping shaders out there. How could this work then?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this