Recent

Author Topic: A Graphics Effect Challenge  (Read 8226 times)

Akira1364

  • Hero Member
  • *****
  • Posts: 530
Re: A Graphics Effect Challenge
« Reply #15 on: October 10, 2017, 12:59:45 am »
The video explained enough, looks like light is being stopped by each pixel in the map. Challenge worth trying. I have only done similar with polygons and opengl before, those principles don't work here.

Don't think you got my point... I was saying that the idea that implementing the lighting in OpenGL would be somehow more "hard to understand" doesn't make sense. As shown by your example code, doing it in software requires a whole lot of manual math that wouldn't be necessary if you did use OpenGL.
« Last Edit: October 10, 2017, 01:01:20 am by Akira1364 »

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: A Graphics Effect Challenge
« Reply #16 on: October 10, 2017, 02:07:26 am »
The video explained enough, looks like light is being stopped by each pixel in the map. Challenge worth trying. I have only done similar with polygons and opengl before, those principles don't work here.

Don't think you got my point... I was saying that the idea that implementing the lighting in OpenGL would be somehow more "hard to understand" doesn't make sense. As shown by your example code, doing it in software requires a whole lot of manual math that wouldn't be necessary if you did use OpenGL.
actually it would make things harder to learn for any one that has no idea what opengl does and how.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: A Graphics Effect Challenge
« Reply #17 on: October 10, 2017, 03:20:01 am »
Still no luck.

But so far I found that the running trapped in the loop in DrawScreen:
If you change this:
Code: Pascal  [Select]
  1. with image1.Picture.Bitmap.Canvas do begin
  2.     image1.Picture.Bitmap.BeginUpdate(true);
  3.     ...
  4.     image1.Picture.Bitmap.EndUpdate();
  5.   end;
Into this:
Code: Pascal  [Select]
  1.   image1.Picture.Bitmap.BeginUpdate(true);
  2.   with image1.Picture.Bitmap.Canvas do begin
  3.     ...
  4.   end;
  5.   image1.Picture.Bitmap.EndUpdate(false);
Will it work? I don't actually know what BeginUpdate does internally, maybe even changing the TCanvas reference to something else temporarily just for the doublebuffering effect. It led to virtual method so it has to have some platform specifics. To me adding BeginUpdate had biggest impact when i maximize the window. It has same speed as small window now.

You can also manually draw it to a temporary bitmap and then while removing BeginUpdate/EndUpdate's, just call 1 line to draw the temp bitmap to image.bitmap.canvas. Or 3rd option for setting DoubleBuffered:=true; for the form and also trying with and without the update pair.

Lastly i hope it's not coming down to the speed of the cpu. You could debug i and j getting bigger if you paused? It's not infinite loop especially if you changed it to click. Maybe it's the debugging feature itself that's dragging it down. Let operating system start the binary software file.

Akira1364

  • Hero Member
  • *****
  • Posts: 530
Re: A Graphics Effect Challenge
« Reply #18 on: October 10, 2017, 04:43:33 am »
The video explained enough, looks like light is being stopped by each pixel in the map. Challenge worth trying. I have only done similar with polygons and opengl before, those principles don't work here.

Don't think you got my point... I was saying that the idea that implementing the lighting in OpenGL would be somehow more "hard to understand" doesn't make sense. As shown by your example code, doing it in software requires a whole lot of manual math that wouldn't be necessary if you did use OpenGL.
actually it would make things harder to learn for any one that has no idea what opengl does and how.

Still makes no sense. You're saying that you think implementing something from scratch using entirely custom math is easier than using a graphics API that has built-in functions specifically meant for those purposes.

That being said, for the sake of Handoko's original challenge, I made a reworked version of User137's example that uses TBGRABitmaps and a TBGRAVirtualScreeen (instead of TBitmaps and a TImage), and have attached a zip file that contains my modified project files as well as the PNG backgrounds to this post. You'll need the "BGRAControls" package installed, obviously.

This version actually runs at what I would call "full speed", although I would still strongly recommend that nobody ever attempt to actually write real games using software imaging techniques. Use OpenGL or a similiar hardware graphics API. There is nothing harder or "scarier" about them then any other aspect of programming you'd need to know to make games...
« Last Edit: October 12, 2017, 12:35:25 am by Akira1364 »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: A Graphics Effect Challenge
« Reply #19 on: October 10, 2017, 09:34:56 am »
Don't think you got my point... I was saying that the idea that implementing the lighting in OpenGL would be somehow more "hard to understand" doesn't make sense. As shown by your example code, doing it in software requires a whole lot of manual math that wouldn't be necessary if you did use OpenGL.
I haven't been debating against that, and i completely agree that doing lights with pixels and software rendering is not something you do or want to see in any real games. It was just an experiment and he wanted to see how it can be done. What the app does is send a thousand or more rays to different directions, move them 1 pixel at the time and define polygon by where they end up unrestricted or collisioned. It is only feasible for 1 light source even if the fade was rendered by OpenGL. Games can have hundreds of lights at same camera distance, and without having much of an effect on performance it means very different approaches.

About hard to understand... i actually still don't understand how shadows work in most of 3D. This app however, as you noticed came up in a matter of hours.
« Last Edit: October 10, 2017, 09:36:28 am by User137 »