Author Topic: 3D Shader  (Read 28887 times)

0 Members and 1 Guest are viewing this topic.

Offline dtewksbury

  • Jr. Member
  • **
  • Posts: 94
  • Milliwatts: 1
  • Gender: Male
    • View Profile
3D Shader
« on: November 06, 2009, 06:06:02 pm »
Hey James, where in the code do I find your 2D projection. You know the part that takes the 3D points that have been rotated, zoomed etc, and converts them to 2D points for display on the screen.

I am just about to start working on that in my software, and believe it or not I can't find many examples on the net. I believe because that is usually done by shaders in the graphics cards GPU.

Am I correct in assuming that the x and y points simply get scaled by the z depth. That is how I was going to start to tackle it anyway (assuming the camera is directly pointing back along the z axis).


Offline James

  • Administrator
  • Hero Member
  • *****
  • Posts: 2132
  • Milliwatts: 47
  • Gender: Male
    • View Profile
    • LaserBoy !!!
Re: 3D Shader
« Reply #1 on: November 06, 2009, 06:16:49 pm »
The LaserBoy 3D universe is isometric orthographic.

Depth distortion and fading are effects.

Look at frame 15. Shift 'D' to zoom out away from it. Go to 'u' and enable '1' vertices, '2' blanking, '9' floating bounds.

[Esc] back to main menu. Press and hold '4' to orbit the art.

See!

James.  :)
LaserBoy is Sofa King Cool!
But it will never be Alpha King Done!

Offline Fanny Pack

  • Hero Member
  • *****
  • Posts: 645
  • Milliwatts: -20
  • Gender: Male
    • View Profile
Re: 3D Shader
« Reply #2 on: November 06, 2009, 06:19:46 pm »
You can apply a perspective projection matrix to your points to convert them to 2D.  And you could use the z depth as a factor for dimming the points farther away if you wanted.

Offline dtewksbury

  • Jr. Member
  • **
  • Posts: 94
  • Milliwatts: 1
  • Gender: Male
    • View Profile
Re: 3D Shader
« Reply #3 on: November 06, 2009, 06:40:09 pm »
OK I will look up perspective projection in wiki. Thanks.

Offline James

  • Administrator
  • Hero Member
  • *****
  • Posts: 2132
  • Milliwatts: 47
  • Gender: Male
    • View Profile
    • LaserBoy !!!
Re: 3D Shader
« Reply #4 on: November 06, 2009, 07:01:19 pm »
If you look in the code, you will see that I have functions for rotating 3D vectors. The result is always looking at it straight into Z. So, if you want to know where "floating axis" or "floating bounds" are, you draw them before you rotate the points. Obviously, I have a line drawing function. So it only takes two points to make any line.

Bitmaps get rendered into my own memory object and slammed into the window whole.

I use this on a temp set of coordinates right before I create the 2D bitmap for the screen. This is also where X, Y and Z come from for waves (sort-of).

James.  :)
« Last Edit: November 06, 2009, 07:04:54 pm by James »
LaserBoy is Sofa King Cool!
But it will never be Alpha King Done!

Offline meandean

  • Sr. Member
  • ****
  • Posts: 466
  • Milliwatts: 13
  • It's about sight AND sound.
    • View Profile
Re: 3D Shader
« Reply #5 on: November 06, 2009, 09:13:36 pm »
  I just use the rotated Z value to ramp down the RGB values in linear fashion, as well as a means to reduce XY to create a vanishing point effect.
"Patience is for the dead."

Offline BlinkenLights

  • he's just this guy, ya know?
  • Administrator
  • Hero Member
  • *****
  • Posts: 730
  • Milliwatts: 4
  • Gender: Male
  • 'The Messenger' by Will Cascio
    • View Profile
Re: 3D Shader
« Reply #6 on: November 06, 2009, 09:32:05 pm »
laserboy also has a DEPTH effect that can take a animation and shrink it a little on the Z axis to make it look more 3d.

also the fader_z effect dims the laser on the z axis to add another layer of depth

Offline dtewksbury

  • Jr. Member
  • **
  • Posts: 94
  • Milliwatts: 1
  • Gender: Male
    • View Profile
Re: 3D Shader
« Reply #7 on: November 07, 2009, 12:12:10 am »
Cool, which source file are those functions in?

Offline James

  • Administrator
  • Hero Member
  • *****
  • Posts: 2132
  • Milliwatts: 47
  • Gender: Male
    • View Profile
    • LaserBoy !!!
Re: 3D Shader
« Reply #8 on: November 07, 2009, 12:22:02 am »
Look in LaserBoy_frame.cpp at line 1704 for the function void LaserBoy_frame::render(int skin) const

The stuff aabout bit_masked_color and bit_masked_position is about reducing the number of significant bits in each signal stream. So, you can specify, for example, that your X and Y data is only 10 bits.

James.  :)
« Last Edit: November 07, 2009, 12:41:20 am by James »
LaserBoy is Sofa King Cool!
But it will never be Alpha King Done!

Offline dtewksbury

  • Jr. Member
  • **
  • Posts: 94
  • Milliwatts: 1
  • Gender: Male
    • View Profile
Re: 3D Shader
« Reply #9 on: November 07, 2009, 01:09:50 am »
OK thanks, I will have a look.

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.7 © 2008-2024, SimplePortal