Jump to content


Photo

[University Work] Black Outlines?


  • Please log in to reply
19 replies to this topic

#1 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 03 February 2012 - 09:21 AM

Howdy folks, Tetiro here with another cracker of a need help scenario

If you saw my realistic ball rolling topic, you'll have realised I'm my final year of university work and am HAVING to make a 3D demo/game.

Well I was looking at the models today and I realised they look very rough around the edges and then I realised it's because I'm used to my graphics having black outlines

Now I've done searching for how to do black outlining, tried it and failed.

So now I ask for help from GMC. Does anyone know of a fool-proof way to get black outlining on models?
  • 0

#2 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 03 February 2012 - 09:36 AM

How do you make your models?
There are two ways of doing it, the good way and the bad way. The good way is to protrude all vertices a certain amount (depending on how thick an outline you want) in the direction of their normal vector, invert the drawing order of the vertices, and draw the model in black. This creates a nice looking dynamic outline.
The bad method, which only works properly with symmetrical, origin-centered models, is scaling them with negative values less than -1 in all dimensions and drawing them in black. This is what I do in my jam5 game Duality, but there it isn't a problem, as all my models are basic primitives.

Edited by TheSnidr, 03 February 2012 - 10:23 AM.

  • 0

#3 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 03 February 2012 - 09:50 AM

How do you make your models?
There are two ways of doing it, the good way and the bad way. The good way is to protrude all vertices a certain amount (depending on how thick an outline you want) in the direction of their normal vector, invert the drawing order of the triangles, and draw the model in black. This creates a nice looking dynamic outline.
The bad method, which only works properly with symmetrical, origin-centered models, is scaling them with negative values less than -1 in all dimensions and drawing them in black. This is what I do in my jam5 game Duality, but there it isn't a problem, as all my models are basic primitives.


For my project, I am drawing the models entirely out of basic shapes and polygons.
  • 0

#4 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 03 February 2012 - 10:03 AM

Then you can safely use the bad method. Also, culling must be turned ON, otherwise there's no point
  • 0

#5 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 03 February 2012 - 10:09 AM

Ok go through the bad way step by step as if you're talking to an idiot. Because when it comes to 3D, I am an idiot.
  • 0

#6 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 03 February 2012 - 05:02 PM

Ok go through the bad way step by step as if you're talking to an idiot. Because when it comes to 3D, I am an idiot.

Step 1: Set color to black (Black texture works nicely if you're using vertex colors and texture coordinates)
Step 2:
outline_scale = 1.1; // Anything more than 1 works. Smaller value = thinner outline.
d3d_transformation_set_scaling(-outline_scale, outline_scale, outline_scale); // Scale around whichever axis is symmetrical (I think what I posted will work fine for GM primitives)
Step 3: Draw your primitive.
  • 0

#7 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 03 February 2012 - 05:37 PM


Ok go through the bad way step by step as if you're talking to an idiot. Because when it comes to 3D, I am an idiot.

Step 1: Set color to black (Black texture works nicely if you're using vertex colors and texture coordinates)
Step 2:
outline_scale = 1.1; // Anything more than 1 works. Smaller value = thinner outline.
[b]d3d_transformation_set_scaling(-outline_scale, outline_scale, outline_scale); // Scale around whichever axis is symmetrical (I think what I posted will work fine for GM primitives)[/b]
Step 3: Draw your primitive.


Where and what do I set to black?

I'm guess the transforumation_set is before during the transformation phase?
  • 0

#8 Zesterer

Zesterer

    Professor of Articul

  • GMC Member
  • 1019 posts
  • Version:GM8

Posted 06 February 2012 - 01:36 AM

Do
draw_set_color(c_black)
And yes, the d3d transform bit refers to the scaling.
  • 0

#9 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 06 February 2012 - 01:30 PM

Do
draw_set_color(c_black)
And yes, the d3d transform bit refers to the scaling.

You haven't exactly answered my questions.

Does anyone have an example they've done so I can have a look because I am at a loss here.
  • 0

#10 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 06 February 2012 - 02:01 PM

Here you go
http://www.host-a.ne...e outlines.gm81
  • 0

#11 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 07 February 2012 - 01:24 PM

Here you go
http://www.host-a.net/u/playway/Simple%20outlines.gm81


I've used the tutorial and it's throwing it back in my face. It completely covers the ball in black.

EDIT: Haha nevermind. Found the problem. Though the culling cuts off parts of the model I do want. Why does it do that?

Edited by King Tetiro, 07 February 2012 - 01:25 PM.

  • 0

#12 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 07 February 2012 - 01:30 PM

Because the order of the vertices is defined in the wrong order. Vertices must be defined in a clockwise order to draw correctly when using culling. Read more here:
http://en.wikipedia....ck-face_culling

So you're gonna have to fix your models I'm afraid
  • 0

#13 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 07 February 2012 - 01:37 PM

Because the order of the vertices is defined in the wrong order. Vertices must be defined in a clockwise order to draw correctly when using culling. Read more here:
http://en.wikipedia.org/wiki/Back-face_culling

So you're gonna have to fix your models I'm afraid

Fortunately I've only done 1 model so it's not a problem. Can you give me tips to prevent vertices in the wrong order?

EDIT: I've updated most of the model. I'm doing the primitives. How do you do black outlining for primitives?

Edited by King Tetiro, 07 February 2012 - 01:48 PM.

  • 0

#14 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 07 February 2012 - 08:34 PM

Unless you're just using the basic primitives, you're gonna have to protrude the vertices a fixed amount, in addition to inverting their drawing order to make culling work the other way.
I've never attempted this myself, but I imagine you'll need vector math, or more specifically, cross product, to find the normal of each triangle, then for each vertex you'll need to get the average of the normal vectors of all adjacent triangles, and protrude the vertex in the resulting direction.

In other words, that method is hard. If I were you I'd search around a little and see if anyone else have done this before, which would save you a lot of trouble

If I misunderstood and you're simply using the basic primitives, the answer is still in the example I posted

Edited by TheSnidr, 07 February 2012 - 08:36 PM.

  • 0

#15 Venomous

Venomous

    GMC Member

  • GMC Member
  • 1469 posts
  • Version:GM:Studio

Posted 07 February 2012 - 09:12 PM

This tool might help you.
  • 0

#16 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 08 February 2012 - 12:58 AM

Not sure if you are able to do this in gamemaker 8.1 - (I only use 8.0), but just change the culling from backface (CCW culling) to frontface (CW culling). This will not draw any triangles with their fronts shown to you. Draw the model slightly larger and with frontface culling (outline) then draw it again, but smaller with backface culling.
  • 0

#17 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2187 posts
  • Version:GM8

Posted 08 February 2012 - 10:11 AM

I think I'll just try to avoid using primitives then. Cheers for the help guys!
  • 0

#18 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 08 February 2012 - 10:33 AM

Not sure if you are able to do this in gamemaker 8.1 - (I only use 8.0), but just change the culling from backface (CCW culling) to frontface (CW culling). This will not draw any triangles with their fronts shown to you. Draw the model slightly larger and with frontface culling (outline) then draw it again, but smaller with backface culling.

How do you switch between the two? This is all I can find in the manual:

d3d_set_culling(cull) Indicates to start backface culling (true) or stop backface culling (false).


  • 0

#19 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 08 February 2012 - 06:05 PM

I think I'll just try to avoid using primitives then. Cheers for the help guys!


I assume you are referring to triangles, lines, or points. Unfortunately "primitives" is used to describe everything that GM can draw. I hear it used for triangles. I hear it used for cylinders. I hear it used for spheres. I hear it used for walls and floors. It's not descriptive. Stop assuming it is.

Triangle meshes can be extruded, but care must be taken when handling edges and corners, or your finished outline hull will have gaps. A simple solution is to extrude vertices, not individual triangles (May have trouble with sharp corners, but otherwise fine). You can find the vector to extrude along by calculating the vertex normal. This is typically the average of the normals of all triangles that share that vertex.
  • 0

#20 brett14

brett14

    GMC Member

  • GMC Member
  • 1150 posts
  • Version:GM8

Posted 09 February 2012 - 05:58 AM

How do you switch between the two? This is all I can find in the manual:

As I said I use GM8.0 which does not support this. I'm not sure if GM8.1 supports it, but if that's a quote from the manual then it does not support frontface culling. If you use GMAPI and the DX SDK, all you need to do is something like this.

device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);//Backface culling (Counter Clockwise)
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);//Frontface culling (Clockwise)
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);//No culling (None)
Pick one and set the culling mode.

Edited by brett14, 09 February 2012 - 05:59 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users