• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
tomwindcloud

Anyone tell me the difference of tex2Dgrad and tex2D?

6 posts in this topic

tex2Dgrad was introduced in ps_2.0 where you can determine the LOD for mipmapping and filtering you cant use this function in ps_1.0.

tex2D was a ps_1.0 function which i think got lately also support for LOD ;)
0

Share this post


Link to post
Share on other sites
Thank you,Matt Aufderheide.
I think tex2D also support mipmap.
In the doc, we can see the follow:
"tex2Dgrad(s, t, ddx, ddy),2D gradient texture lookup.This function samples a texture using the sampler specified by s, the texture coordinates in t, the x gradient in ddx, and the y gradient in ddy. The gradient values select the appropriate mipmap level of the texture for sampling."
Now my questions are:
1.ddx: On doc, "Returns the partial derivative of x with respect to the screen-space x coordinate." What's the screen-space? how to computer the the partial derivative of x.
2. "The gradient values select the appropriate mipmap level of the texture for sampling." How to do it?
0

Share this post


Link to post
Share on other sites
You need to understand a bit about how graphics hardware works to understand ddx, ddy and tex2Dgrad. Graphics hardware works with 'quads' of pixels - four pixels together in a 2x2 grid. All four pixels are rendered at the same time by parallel hardware. The graphics hardware approximates the partial screen space derivative of a texture co-ordinate used for sampling a texture by taking the finite difference between adjacent pixels in the quad (ddx is the difference in the texture coordinate between a pixel and the pixel to the left or right of it in the quad and ddy between the pixel and the pixel above or below it in the quad).

This partial derivative says how fast the texture coordinate is changing in screen space and can be used to work out what mip level of the texture to sample (it will also feed into anisotropic filtering calcuations if aniso is enabled). A simple example: if you are mapping 1 texel to 1 pixel and rendering a screen aligned quad then the difference between the texture coordinate of a pixel and the adjacent pixel in the quad will be 1 / texwidth - from this the graphics card can work out it needs to use the top mip level. If you scale the quad down by half in each direction then the derivative will be twice as large and the card will know to use the next smaller mip level.

With ddx and ddy you can get those derivatives directly and they can be useful for things like anti-aliasing procedural textures. The tex2Dgrad instruction takes the derivatives as input and uses those derivatives to work out what mip to use rather than the ones from the texture coordinate being used to sample the texture. That can be useful in a variety of situations.

One common use for tex2Dgrad is when you want to sample a texture inside a dynamic branch. Because ddx and ddy are worked out from the adjacent pixels in a quad you can't do a dependent texture read inside a dynamic branch because the texture coordinate might be different or not available in the adjacent pixel if it goes down a different branch. You can work around this by explicitly calculating ddx and ddy yourself outside the branch and then using tex2Dgrad inside the branch to conditionally sample a texture.

Another use is if you want to implement texture wrapping yourself in a pixel shader - you don't want to sample using the difference between the wrapped coords but the difference using the unwrapped coords or you'll get artifacts at the wrapping point.
1

Share this post


Link to post
Share on other sites
thanx a lot, I understand it much better now.

however, when I try this in a shader

float dx = ddx(textureUV.x);
float dy = ddy(textureUV.y);

finalColor = tex2Dgrad(defaultTexsampler, textureUV, dx, dy);


it always choses the highest mip. what am I doing wrong? this is just an exercise, I could use tex2D here.
0

Share this post


Link to post
Share on other sites
The gradients need to be 2D - the texture u and v direction don't necessarily line up with the screen x and y. Try this:

float2 texDdx = ddx(texUV);
float2 texDdy = ddy(texUV);
float4 colour = tex2Dgrad(texSampler, texUV, texDdx, texDdy);
0

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  
Followers 0