• 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
d h k

Sending custom UVs to shader

2 posts in this topic

Hey there!

I'm working on a [b]2D[/b] game using D3D9 and HLSL. I use [b]one single vertex buffer holding 4 vertices that describe a simple quad[/b]. These vertices also hold [b]standard texture coordinates[/b] (from 0 to 1, as you would expect). At the moment I draw absolutely [b]everything[/b] in the game using that tiny vertex buffer (sprites, background layers and even interface elements such as buttons) and it's extremely nice and easy to work with.

My problem is that now my artists wants me to [b]load sprites off of sprite sheets[/b] (this is more efficient and, when working with bitmap fonts for example, really the only sane way to go) - so I don't want to split the sheets into tiny textures at load time, instead [b]I want to be able to control the texture region that is being used by altering the texture coordinates[/b].

I don't think switching to dynamic vertex buffers and punching in new texture coordinates for my 4 vertices makes a lot of sense so I thought it would be easiest to achieve this with a [b]simple HLSL shader[/b].

I can easily pass 4 vector2-type texture coordinate pairs to my shader to use for the 4 vertices of course - but[b] I need to find a way for the shader to know which texture coordinate to use[/b]. Essentially it needs to know which vertex it is currently processing I guess (if that is possible)?

I'm familiar with HLSL and have used it for a variety of more common things (mostly lighting and deferred rendering related) but how can I achieve this particular technique? Moreover, is this really the best way to go or are there alternative ways to do what I try to do that I'm not quite seeing yet?

Thanks ahead of time, let me know if you need any additional info! I tried searching for solutions myself but have a very hard time describing my problem in 'searchable' words and phrases. Any help is greatly appreciated!
0

Share this post


Link to post
Share on other sites
You need to send a Vector4 to the shader that contains the location in the texture and the size of the image located at that positoin, all these values are 0..1.

In the vertex shader you then access this to modify the texture coordinates as follows:
[code]
Vector4 textureUVInfo; //Passed from application
textureCoord.x = (in.texCoord.x * textureUVInfo.z) + textureUVInfo.x;
textureCoord.y = (in.texCoord.x * textureUVInfo.w) + textureUVInfo.y;
[/code]

In the above code the actual lookup location in the texture is stored in textureUVInfo.xy and the size of that area of interest is stored in textureUVInfo.wz. All the art assets should just use 0..1 coordinates just as if they are actually textures with a single texture instead of with a spritesheet. In your application you have to store a link between a particular location and size in the texture and which object uses it.

Google Atlas texturing to find out more information as that's what a spritesheet is essentially.
1

Share this post


Link to post
Share on other sites
That is so smart and elegant, wow! Thanks a ton, this works flawlessly and makes a TON of sense in retrospect!
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