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

Sending a simple heightmap as texture to vertex shader

3 posts in this topic

Hello,

I am developing a fractal terrain generation based on an original 256x256 heightmap.
I need to use a texture to represent this heightmap, together with other gradients in each point, that is, 3 floats per 'texel'.

//////////////////////////////////////////////////////////////////////////////in the vertex shader, I am doing:

uniform sampler2D TexHeightMap;


vec4 GetVertCellParameters( uint i, uint j )
{
return texture( TexHeightMap, vec2( i, j ) ) * 2500.0f;
}

the * 2500.0f multiplication was used just to make sure the values are not somewhere between 0-1; in the final code,
the function will just return texture( TexHeightMap, vec2( i, j ) );

//////////////////////////////////////////////////////////////////////////////in the CPU, I am using:

void GLTexture::CreateHTExture( const void* pvBytes, unsigned int unW, unsigned int unH )
{
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, &m_uglID );
glBindTexture( GL_TEXTURE_2D , m_uglID );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, unW + 1, unH + 1, 0, GL_RGB, GL_FLOAT, pvBytes );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
}

glEnable(GL_TEXTURE_2D );
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D , pTexture->GetID());
glUniform1i(m_ugl_HeightMapTexture, 0);

pTexture is of type GLTexture;

m_ugl_HeightMapTexture = glGetUniformLocation(m_uglProgram, "TexHeightMap");

for some reason, I am only getting zeros in the vertex shader ( when calling GetVertCellParameters ).
I checked the parameters pvBytes with memory view and they look fine.
I just need to get the float values, unmodified, just as I send them, in the vertex shader, and access them via texture as vec4.

Thank you.
0

Share this post


Link to post
Share on other sites
You should use glGetError() when having problems (be warned that it automatically sets the error value to 0 after returning the value). Your problem is probably described at OpenGL Wiki http://www.opengl.org/wiki/Common_Mistakes#Creating_a_complete_texture – you HAVE to set GL_TEXTURE_MIN_FILTER to GL_NEAREST (returns pixelated texture) or GL_LINEAR (returns average of the four texels). That makes your texture incomplete to OpenGL. You want GL_LINEAR for your heightmap (so the slopes are nice).
0

Share this post


Link to post
Share on other sites
hello,

I don't need 'nice slopes', since my grid of 256x256 is much smaller than my 3d world. I am using interpolation functions to create the smooth surface. I just want every texel to contain 3 floats and I want o access them as memory data. Here is a snippet from my shader:

[CODE]
#define OPENTG_HEIGHTMAPRES 256
float xn = X / OPENTG_SUBCELLSIZE;
float yn = Y / OPENTG_SUBCELLSIZE;

unsigned int i = (uint)floor( yn );
unsigned int j = (uint)floor( xn );

float u = fract(xn);
float v = fract(yn);

if( OPENTG_HEIGHTMAPRES == i )
{
i --;
v = 1;
}
if( OPENTG_HEIGHTMAPRES == j )
{
j --;
u = 1;
}
vec4 vH00 = GetVertCellParameters( i, j );
vec4 vH10 = GetVertCellParameters( i + 1u, j );
vec4 vH01 = GetVertCellParameters( i, j + 1u );
vec4 vH11 = GetVertCellParameters( i + 1u, j + 1u );
/*do something with the vec4's
they contain infos of height values in i, j cell and gradient information
*/
}
[/CODE]

it seems there are problems if some of those values are negative - the rendering looks somehow like it renders part of the scene and then stops rendering anything else in a certain point.
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