• 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
Migi0027

HLSL - Converting these 2d coordinates.

6 posts in this topic

Hi guys! wink.png

 

This may seem extremely simple, yet it isn't for me, and therefore I'm asking for your help on this topic. I'd like to convert coordinates from 0 to 1 that start at the top left corner, and end in the bottom right corner. Unfortunately I can't just insert these values into the NDC coordinates in my vertex shader, as that's not how they work, description from msdn: (http://msdn.microsoft.com/en-us/library/windows/desktop/cc308049(v=vs.85).aspx)

 

IC534071.png

 

The reason for this is because I'm starting on my 2d simple gui, nothing fancy. So I simply have a structure called Rectangle, defining x0, y0, x1, y1, where 0,0 is the top left cornor, and 1,1 is the bottom right, but I'd need to convert these into the NDC space coordinates, how?

 

Maybe I should know how to do this, maybe not, either way, how could this be done? Any input would be appreciated.

 

Thank you, as usual. happy.png

-MIGI0027

0

Share this post


Link to post
Share on other sites
x0 = x0 * 2.0f - 1.0f;
x1 = x1 * 2.0f - 1.0f;
y0 = y0 * -2.0f + 1.0f;
y1 = y1 * -2.0f + 1.0f;


L. Spiro

[EDIT]
Fixed to flip vertically.
[/EDIT] Edited by L. Spiro
2

Share this post


Link to post
Share on other sites

Thank you.

 

When using the coordinates: 0, 0, .5f, .5f, and transforming them using your method, the result isn't as expected.

 

2ur1rpk.png

 

I would have expected some thing going from the top left to the middle of the screen. My implementation:

// Creating the vertices
Surface->SetArea(&CDK::Rectangle::ToScreen(CDK::Rectangle(0, 0, .5f, .5f));

// ::ToScreen, I do realize that this can be optimized, but that's not the goal for now.
CDK::Rectangle& CDK::Rectangle::ToScreen(Rectangle& a)
{
	a.x0 = a.x0 * 2.0f - 1.0f;
	a.x1 = a.x1 * 2.0f - 1.0f;
	a.y0 = a.y0 * 2.0f - 1.0f;
	a.y1 = a.y1 * 2.0f - 1.0f;

	return a;
}

Edit:

...
Rectangle(float _x0, float _y0, float _x1, float _y1)
{
	x0 = _x0;
	x1 = _x1;
	y0 = _y0;
	y1 = _y1;
}
Edited by Migi0027
0

Share this post


Link to post
Share on other sites
You didn’t give much context.
Are you using a world-view-projection matrix?  Or projection matrix at all?
 
You shouldn’t be.  The purpose of the projection matrix you create with D3DXMatrixOrthoLH() and friends is to put coordinates into normalized device coordinates.
Since you were asking I had assumed you weren’t using this.
 
In other words, the vertex shader should look like:
OUT = IN;
I explained this in fair detail here.
 
Your parallax occlusion is looking nice.
 
[EDIT]
Your description of what you wanted to happen was hidden between imagery and code.
If your error is that it went to the lower-left instead of the upper-left, then the fix is simple:
CDK::Rectangle& CDK::Rectangle::ToScreen(Rectangle& a)
{
	a.x0 = a.x0 * 2.0f - 1.0f;
	a.x1 = a.x1 * 2.0f - 1.0f;
	a.y0 = a.y0 * -2.0f + 1.0f;
	a.y1 = a.y1 * -2.0f + 1.0f;

	return a;
}
[/EDIT]
 
 
L. Spiro Edited by L. Spiro
2

Share this post


Link to post
Share on other sites

Sorry for the confusion here, my vertex shader isn't anything fancy as it's user customization. (Notice the #REGION things, they are replaced by the engine).

 

Maybe I should, but no, there's no projection matrix involved here. I'm simply sending a structure containing x, y, tx, ty, (t -> texture).

 

So to convert those coordinates I'd have to use the ortho matrix? (D3DXMatrixOrthoLH)

#REGION_INPUTS
SamplerState ss;

struct VS_Output
{  
	float4 Pos : SV_POSITION;
	float2 Tex : TEXCOORD0;
};
 
VS_Output VShader(float2 position : POSITION, float2 tex : TEXCOORD)
{
	VS_Output Output;
	Output.Tex = tex; // Just pass it
	Output.Pos = float4(position.xy, 0, 1);

#REGION_VERTEX
	
	return Output;
}

float4 PShader(VS_Output input) : SV_TARGET
{
	float4 color;

#REGION_PIXEL

	return color;
}

PS. The post you sent me isn't read yet, doing it after this post is written.

 

And thank you. smile.png

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