Skip to content Skip to sidebar Skip to footer

gamemaker 3d reduce draw calls

We've covered cartoon basic meshes, and we've covered the earth-shaking transformation functions. We've likewise covered lighting. Now that we have all these nuts down, information technology's time to outset on some of the nifty tricks that you can pull using what we've learned.

Billboards and Texturing

Up until now, we've been cartoon pretty patently meshes. Sure, y'all can add some visual diversity past changing the describe colour of objects, and you can throw a petty more dynamism in by using lighting, but nothing adds particular and visual pizzazz to your 3D globe like textures.

To prove off how texturing works, and to show you a scrap of applied transformation, nosotros'll be putting together a billboard in Game Maker. Simply put, a billboard is a textured plane that is always rotated to face the camera. These were used a lot dorsum in the days of software 3D engines (and are still used today!) as a manner of drawing objects inexpensively. They're specially useful when the object y'all're drawing looks the same from all angles, like an energy ball or a plume of fume.

Billboarding in action

The energy assurance in the above screenshots are done using billboards. Detect how they keep facing the camera regardless of where it's pointing.

Smoke trails!

In this screenshot, the smoke trail particles are done using billboards. The soldier firing them is also a textured airplane that is rotated to face the camera.

Firstly, I'm going to assume that nosotros take a fully-functional camera that the histrion can pitch and rotate. The actual implementation of this isn't something that I'll go into, since it'southward a programming exercise rather than an explicit 3D function. If you have a static camera at a fixed position, you lot can easily insert abiding values instead of these variables. For at present, even so, permit's assume that the photographic camera has variables for its direction (side-to-side) and pitch (upward and downwardly) in degrees. [Yaw! Roll, pitch and yaw! Use the proper terms; it makes you sound fancy. 😛 – Ed]

We'll kickoff past importing a texture that we tin can place on the billboard. Textures for 3D objects are imported into GM as standard sprites or backgrounds, just as y'all'd unremarkably do for 2D games. For now, create or import whatever sprite, and call it BillboardTex.

Next, we need to create our Billboard object. Put the following in its Create event:

myTex=sprite_get_texture(BillboardTex,0); z=32;

This will give united states a handle to the texture to use in our 3D describe functions. The commencement argument specifies which sprite we're pulling the texture from, and the second argument tells GM from which frame in the sprite to pull the texture from. Every bit you lot can imagine, this allows you to take animated textures (just utilize -1 equally your frame argument, simply like in your draw_sprite() command). Notation that you can also use the background_get_texture() role to pull textures from background images.

We'll besides add together a variable called z, which will specify the height that nosotros want the billboard to be drawn at. Information technology isn't essential, merely information technology helps to have a specific variable defined to control this. You can either leave it every bit-is, or you tin add or subtract from the variable as your needs require.

Next, slap the following in its Draw event:

d3d_transform_set_identity(); d3d_set_culling(false); d3d_transform_add_rotation_y(Camera.direction); d3d_transform_add_rotation_z(Photographic camera.Pitch); d3d_transform_add_translation(x,y,z); d3d_draw_wall(-16,-16,0,16,16,0,myTex,1,i); d3d_set_culling(true); d3d_transform_set_identity();

Nigh of the in a higher place code should wait familiar now that yous know near transfomations. What I'd like to describe your attending to is the d3d_draw_wall() command. In this case, I've fatigued it to exist 32 units broad and tall, merely it can be any size you want. More chiefly, you'll see that the last iii arguments accept been populated with the myTex handle (the texture we divers earlier) and the texture hrepeat and vrepeat arguments have been set to i. Equally I mentioned last time, these two arguments control how many times the texture is tiled across the mesh. Try playing around with dissimilar values and you'll soon see how it works. All mesh functions in GM accept these final iii arguments, allowing you to specify textures for all of them.

And that's all there is to information technology! The textured plane volition orient itself to friction match the camera's direction and pitch, significant that information technology looks the same from all angles.

Heads-upwards-display (HUD)

So, we accept a fantastic 3D globe, brimming with lit, textured meshes, crawly billboarded special effects, and (hopefully) keen gameplay. But how to convey information to the player? Every bit novel as it would exist to incorporate in-world health indicators and target reticles a-la Dead Space, sometimes you need to be able to slap information upward on the screen in 2D every bit well.

Let's say you want to place a targeting reticle in the centre of the screen to assist with aiming, and an indicator in the corner of the screen that shows how many frames per second your game is running at. Y'all would place the following code in the HUD object'southward Draw consequence:

//disable lighting to preclude HUD from beingness drawn in black d3d_set_lighting(false); //disable hidden surface removal, to cease the HUD from being obscured by 3D geometry d3d_set_hidden(fake); //Set ortho aeroplane d3d_set_projection_ortho(0,0,view_wport,view_hport,0); //Draw FPS text in top left corner of screen draw_text(0,0,cord(fps)); //Depict reticle sprite in center of screen draw_sprite(TargetReticle,-ane,window_get_width()/2,window_get_height()/2) //reenable hidden surface removal d3d_set_hidden(true); //Reenable lighting d3d_set_lighting(true);

Firstly, we need to disable lighting. If we don't, GM volition endeavour to light the things nosotros draw to the HUD, which volition result in solid black icons and text. Secondly, we disable hidden surface removal. This prevents our HUD from beingness hidden by 3D objects in the globe, as in these screenshots:

Hidden surface removal

Adjacent, we tell GM that we're drawing to an orthographically projected (2D) plane, and set its x and y position (in screen coordinates, not room coordinates!) and its width and height. For width and meridian, I've set it to make full the screen, running from 0,0 to the edges of the viewport. Finally, you can specify the rotation of the projection plane. With our orthographic airplane divers, we then apply the same 2D drawing functions that we always practise to place text and the reticle sprite on the plane. Finally, we re-enable lighting.

Warning! Recall how the Camera object must e'er exist drawn first? Well, the HUD object must always exist drawn last. If the HUD is drawn before whatsoever of your other 3D objects, the 3D objects fatigued after the HUD will exist rendered orthographically as well. Manifestly we don't want this, unless you're deliberately planning on putting an orthographic 3D model on the HUD as well.

Decision

In this instalment, you've learned a practical application of transformation by creating billboards, and learned a scrap well-nigh texture mapping in the process. Nosotros've likewise covered how to build a heads upward brandish to convey information to the role player. Equally always, play around with these concepts to get a experience for them – there's a lot more that can exist done with them.

Adjacent time, we'll finally learn most building, importing and texturing 3D models in GM, and go through some answers to a few of the more common niggles people experience.

foyagard1947.blogspot.com

Source: http://devmag.org.za/2009/05/04/3d-graphics-with-game-maker-part-3/

Postar um comentário for "gamemaker 3d reduce draw calls"