Jump to content


Photo

3D Lighting not visible


  • Please log in to reply
5 replies to this topic

#1 fluidic ice

fluidic ice

    GMC Member

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

Posted 25 April 2012 - 05:15 AM

Hey, first post in the 3D topic, and Iwas wondering what i'm doing wrong when setting up my 3D lighting in my 2D game. (There's a few 3d object i'm trying to light)

DRAW:
d3d_set_lighting(true);
//d3d_set_shading(true);
d3d_light_define_direction(1,mouse_x,mouse_y,300,c_white);
d3d_light_define_point(2,mouse_x,mouse_y,500,100000,c_white);
d3d_light_enable(1,true);
d3d_light_enable(2,true);
d3d_set_lighting(false);

  • 0

#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Retired Staff
  • 15416 posts
  • Version:GM:Studio

Posted 25 April 2012 - 05:23 AM

did you d3d_start()?

and dont call
d3d_set_lighting(false);

it must be on for the object to know it's on when they draw.

the lights must also be defined before the objects draw, so in the draw of an object at a depth before everything else. in the same code block as your camera is a good place to put this.
  • 0

#3 fluidic ice

fluidic ice

    GMC Member

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

Posted 25 April 2012 - 05:33 AM

Yes I did start 3D and i've ended it after those calls, here's the full 3D code that also sets the view etc.
This object is technically the camera too. Each object sets the camera before drawing 3d. Is that slow?

d3d_start();
        aspect = view_wview / view_hview;
        angle = 2 * radtodeg (arctan (0.5 / aspect));
        d3d_set_projection_ext(Obj_View_Controller.x, Obj_View_Controller.y,view_wview,Obj_View_Controller.x, Obj_View_Controller.y ,0,0,-1,0,angle,aspect,1,32000);
        d3d_draw_cylinder(x - (sprite_width / 2),etc....);
        d3d_draw_cone(x - (sprite_width * 0.75),etc....);
        d3d_set_lighting(true);
        d3d_set_shading(true);
        d3d_light_define_direction(1,mouse_x,mouse_y,300,c_green);
        d3d_light_define_point(2,mouse_x,mouse_y,500,10000,c_green);
        d3d_light_enable(1,true);
        d3d_light_enable(2,true);
        d3d_set_lighting(false);
        d3d_end();

Edited by fluidic ice, 25 April 2012 - 05:37 AM.

  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Retired Staff
  • 15416 posts
  • Version:GM:Studio

Posted 25 April 2012 - 06:41 AM

Above, you draw your 3d objects before you defined your lights or told the system to draw with lights and shadow...

Analogy
you draw what you see to a canvas, with lighting and shading off, they draw at full color
you turned the house power ON (d3d_set_lighting(true))
you screwed in some light bulbs (d3d_light_define...)
you flipped the light switches on (d3d_light_enable(1,true))
you turned the house power off (d3d_set_lighting(false))


You only need (usually, unless you are playing some king of trick) to set the camera position when the drawing starts in like a very deep camera controller. I like to set my camera at depth right above the background depth.


Obj_View_Controller depth 1000000
draw
//init 3d
d3d_start()
//global 3d settings
d3d_set_culling(1);
d3d_set_hidden(1);
d3d_set_lighting(1);
d3d_set_shading(1);

d3d_set_color(cwhite);
aspect = view_wview / view_hview;
angle = 2 * radtodeg (arctan (0.5 / aspect));
d3d_set_projection_ext(Obj_View_Controller.x, Obj_View_Controller.y,view_wview,Obj_View_Controller.
x, Obj_View_Controller.y ,0,0,-1,0,angle,aspect,1,32000);

//here I define my lights... or in other objects at depth 999999
d3d_light_enable(1,true);
d3d_light_enable(2,true);
d3d_light_define_direction(1,mouse_x,mouse_y,300,c_green);
d3d_light_define_point(2,mouse_x,mouse_y,500,10000,




My regular 3d objects start at depth 0

d3d_transform_add_translation(x,y,z); //position is 3d world
d3d_draw_cylinder(-5,-5,-5,5,5,5,...); //draw relative to said position
d3d_transform_set_identity(); //segregate this draw as a 3d item in the system


Anyway, yeah, you want 3d drawing but in a 2d world. so what you have is fine apart from the order...

d3d_start();
aspect = view_wview / view_hview; //use a global var for this, calc only once
angle = 2 * radtodeg (arctan (0.5 / aspect)); //ditto

d3d_set_projection_ext(Obj_View_Controller.x, Obj_View_Controller.y, view_wview, Obj_View_Controller.x, Obj_View_Controller.y 0, 0, -1, 0, angle, aspect, 1, 32000);

//what 3d settings this needs to draw
d3d_set_lighting(true);
d3d_set_shading(true);
d3d_light_define_direction(1,mouse_x,mouse_y,300,c_green);
d3d_light_define_point(2,mouse_x,mouse_y, 500, 10000, c_green);
d3d_light_enable(1,true);
d3d_light_enable(2,true);
draw_set_color(c_white);

//draw at position
d3d_transform_add_translation(x,y,z); //position
d3d_draw_cylinder(-(sprite_width / 2),etc....); //relative, no x,y,z
d3d_draw_cone(- (sprite_width * 0.75),etc....); //relative, no x,y,z
d3d_transform_set_identity(); //done with this 3d guy

//reset
d3d_light_enable(1,false);
d3d_light_enable(2,false);
d3d_set_lighting(false);
d3d_set_shading(false);
d3d_end();
  • 0

#5 fluidic ice

fluidic ice

    GMC Member

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

Posted 25 April 2012 - 09:00 AM

Ahh thanks very much for that explanation! I've got it working now and i'll be sure to have a play around with it and see what effects I can produce.
Is there a way I can blend the "d3d_light_define_point" with the natural color of the texture, as it fades to black on the non-lit side.
  • 0

#6 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Retired Staff
  • 15416 posts
  • Version:GM:Studio

Posted 25 April 2012 - 06:06 PM

you can play with is the draw_set_color... Not really sure what you mean by it fades to black... You can disable the shadow and draw a light on the other side, a c_black light.

You can also play with doubling the draw, overlay a draw of the same d3d model with a different texture with bm_add or bm_subtract. for example if you want to add shininess...

http://gmc.yoyogames...howtopic=363505
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users