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

something similar to GL_POINT_SPRITE

7 posts in this topic

Hi i am trying to draw a spiral galaxy without usage of point sprites, so far i was able to draw billboards, but in order to display galaxy properly i need to change their size in realtime, with glpointsprites i could just define where i want to put a sprite and set its maximum and minimum size (the whole sizing thing was automatic), like in this video.

 

http://www.youtube.com/watch?v=dGiO5XlMVTE

 

 

Main problem is that i set point sprite size with pixels, and with billboards i use numbers.

So far i set a fixed size:

maybebeybe.jpg

 

 

 

But it only looks good from this distance.

 

 

Anyway, i am now trying to write a sizing function for these billboards, where minimum size is  1 pixel (less than 100.0f dist from a billboard) and maximum is 35 pixels. (more than 3500.0f dist from a billboard)

 

BUT the problem is how do i calculate size of a billboard to a coressponding size in pixels?

 

 

I tried to do some perspective calculations but i am far from getting it done, any help? tongue.png

 

and pls dont ask why i dont want to use point sprites, cuz i won't run my program on a different computer after every build, and mine (that i work on) does not support such thing. Oh and i cant use shaders aswell.

But maybe my GL_POINT_SPRITE implementation lacks of something since my cards supports them but i cant make these point textured.

Edited by WiredCat
0

Share this post


Link to post
Share on other sites

Here is my slower, but good enough version to do this:

	vec4 projsize = matproj * vec4(in_data.xx, position.zw);
	gl_PointSize = max(2.0, in_data.x / 64.0 * sizemult.x / projsize.z);

sizemult is screensize in pixels

in_data.x is from the particle vertex structure, and is the size of the particle

 

so, to get the pointsize we transform (size, size, Z, W) with the projection matrix

the rest from there is really up to you

 

Translated to make any sense:

vec4 position = matview * vec4(in_vertex.xyz, 1.0);
vec4 projsize = matproj * vec4(size, size, position.zw);
gl_PointSize = size * screensize.x / projsize.x;

... which means that all of this can be done with fewer calculations

i'm just not any good at math to begin with

 

Also, to texture your particles just use GL_TEXTURE_2D_ARRAY. Simple and works.

Edited by Kaptein
1

Share this post


Link to post
Share on other sites

i am very very pleased, however i dont quite understand this maybe i am a lil bit drunk (ok i am) but could you describe 'so, to get the pointsize we transform (size, size, Z, W) with the projection matrix' and this second code, it looks like a fragment shader, i am not aware of multiplying a matrix with 4d point.

0

Share this post


Link to post
Share on other sites

I have few questions:

First of all will vector * matrix will look similar to this? : MatVecMult01.gif

 

where right [] is my vector ;]

 

 

 

second thing is about your code:

 

 

 

vec4 position = matview * vec4(in_vertex.xyz, 1.0);
vec4 projsize = matproj * vec4(size, size, position.zw); <- whats this size?
gl_PointSize = size * screensize.x / projsize.x;

 

 

maybe i didnt precise my needs: i have a billboard and i must make it to be 32 pixels big when i am 3500 units away from it. ;] 

0

Share this post


Link to post
Share on other sites

I believe i found a solution, had to use pencil and ruler ;]

 

take a look at this there will be an explanation under it:

 

sol.jpg

 

 

 

So we have a viewport, we know how far a particle is from our camera.

we also know FOV, and we know what screen_width we have (the opengl window width in pixels ;])

 

so now ze math: we calculate C from distance_particle_camera / (cosine of FOV/2)

 

then we calculate a from C*C - distance_particle_camera*distance_particle_camera

 

now we know that 2*a is related to our screen_width (that opengl window - in pixels)

 

as we know what size in pixels should particle be (depending on the distance from camera) we can calculate:

x = (dest_particle_size_in_pixels / screen_width_in_pixels) and then

2*a*x is our numeric particle width, tommorow i will check it ;f

0

Share this post


Link to post
Share on other sites

I'll try it, hold on for edit

EDIT: I couldn't make it work

 

This is what I did:

	float size = in_data.x / screensize.x;
	gl_PointSize = max(2.0, 2.0 * size * nearPlaneHalfSize.x);

Unless I misunderstood you, it didn't work.

 

I did find another solution that worked almost as good as my first response.

I tested it, and the particles disappear a little too early, but it's not a huge deal for me. I think maybe I'll keep it:

	float angle = asin(size / length(view_position));
	gl_PointSize = max(2.0, angle / (61.0 / 3.14159) * screensize.y);

I hardcoded the FOV in radians (61 / PI)

 

Anyways, after some testing, my first response has the one that works best, so I'm using that.

Edited by Kaptein
0

Share this post


Link to post
Share on other sites

yep it works, however i have another question:

 

det.jpg

 

 

 

On what distance particles go to their max size?

 

 

the code looks like this:

 float sizeFromDistance(float dist,float maxsize)
 {

  if (dist >= 8000.0f) return maxsize;

 return      (dist / 8000.0f) * maxsize;

//  return 1.0f;
 }



elsefunc()
{
sizecoeff = cos(45.0f*imopi);  where 45.0f is FOV /2.0f and const float imopi           = 0.017453292519943295769236907684886;   //PI / 180

float dst = n3ddistance(particlepos, campos); // just a distance between 2 points
	float C = 	dst / sizecoeff;
	float x = sizeFromDistance(dst,35.0f) / 1024.0f; //where 1024 is my screen width in pixels
	float a = C*C - dst*dst;
	a = sqrt(a);
	float pointsize = 2.0f*a*x;


}
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