Recent

Author Topic: Demo Scene Blitter Objects  (Read 1106 times)

Gigatron

  • Jr. Member
  • **
  • Posts: 78
  • Amiga Rulez !!
Demo Scene Blitter Objects
« on: May 28, 2024, 11:21:51 pm »
Hi,
On the same idea to display blitter object BOBs , made a little program coded faster than light , using BGRA Component to play with formula;

I think I would die in front of my PC before exploiting the full potential of the BGRA component..

Have fun ;

https://www.youtube.com/watch?v=VFs2qnfrHO8&t=534s

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Spin,
  9.   StdCtrls, BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     BGRAVirtualScreen1: TBGRAVirtualScreen;
  17.     FloatSpinEdit1: TFloatSpinEdit;
  18.     FloatSpinEdit2: TFloatSpinEdit;
  19.     FloatSpinEdit3: TFloatSpinEdit;
  20.     GroupBox1: TGroupBox;
  21.     SpinEdit1: TSpinEdit;
  22.     Timer1: TTimer;
  23.     procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure Timer1Timer(Sender: TObject);
  26.   private
  27.    star  : TBGRABitmap;
  28.   public
  29.  
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.   size  : integer;
  35.   fc,fs,t : single;
  36.  
  37. implementation
  38.  
  39. {$R *.lfm}
  40.  
  41. { TForm1 }
  42.  
  43. procedure TForm1.FormCreate(Sender: TObject);
  44. begin
  45.    size :=160;
  46.    fc  := 2.0;
  47.    fs  := 8.0 ;
  48.    t := 0;
  49.    star := TBGRABitmap.Create('ball.png');
  50.  
  51. end;
  52.  
  53. procedure TForm1.Timer1Timer(Sender: TObject);
  54. begin
  55.        t    := t + FloatSpinEdit3.value;
  56.        fc   := FloatSpinEdit1.value;
  57.        fs   := FloatSpinEdit2.value;
  58.        size := SpinEdit1.value;
  59.        BGRAVirtualScreen1.RedrawBitmap;
  60. end;
  61.  
  62. procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  63. var
  64.   i: integer;
  65. begin
  66.        for i:=0 to 79 do
  67.        begin
  68.        Bitmap.PutImage(320+round(size*sin(i*fc+t)),220+round(size*cos(i*fs+t)),star,dmDrawWithTransparency);
  69.  
  70.        end;
  71. end;
  72.  
  73. end.
  74.  
« Last Edit: May 28, 2024, 11:23:40 pm by Gigatron »
Sub Quantum Technology ! We are in a micro universe.

circular

  • Hero Member
  • *****
  • Posts: 4276
    • Personal webpage
Re: Demo Scene Blitter Objects
« Reply #1 on: May 28, 2024, 11:40:17 pm »
I think I would die in front of my PC before exploiting the full potential of the BGRA component..
Haha at least that's dying doing something you like  :D
Conscience is the debugger of the mind

TRon

  • Hero Member
  • *****
  • Posts: 2801
Re: Demo Scene Blitter Objects
« Reply #2 on: May 29, 2024, 06:22:57 am »
Again a nice one Gigatron.

Quote
* ball.png (1.42 kB, 32x32 - viewed 31 times.)
what a shame....  all this bgra treasures and then leaving us with some ugly ball  :P

Code: Pascal  [Select][+][-]
  1. ..
  2. uses
  3.   BGRAGradients;
  4. ..
  5.  
  6. procedure TForm1.createstar;
  7. var
  8.   ps: TPhongShading;
  9. begin
  10.   ps := TPhongShading.Create;
  11.   ps.LightPositionZ := 180;
  12.   ps.SpecularIndex := 7;
  13.   ps.AmbientFactor := 0.5;
  14.   ps.LightSourceIntensity := 350;
  15.   ps.LightSourceDistanceTerm := 200;
  16.   ps.LightPosition := point(200,120);
  17.  
  18.   star := TBGRABitmap.Create(32,32, BGRAPixelTransparent);
  19.   ps.DrawSphere(star,rect(0,0,32,32), 8,BGRA(255,255,0));
  20.   ps.Free;
  21. end;
  22.  

I fully admit to have no idea how all the phongshading settings work but it's fun to play with nonetheless  :)
« Last Edit: May 29, 2024, 06:57:41 am by TRon »

circular

  • Hero Member
  • *****
  • Posts: 4276
    • Personal webpage
Re: Demo Scene Blitter Objects
« Reply #3 on: May 29, 2024, 11:02:41 am »
Here are some explanations on the settings.  :)

Overview
The TPhongShading component is designed to simulate realistic shading on 3D shapes standing on a plane at Z = 0. The shapes, such as a half-sphere, occupy a square in the X and Y coordinates with its top left corner at the origin (0, 0), with the sphere rising in altitude at the center of the square, giving its points a positive Z coordinate.

Light Position and Color
  • Light X and Y coordinates: by default, the light source is positioned at (-100, -100), to the top-left of the square.
  • LightPositionZ: this is the Z coordinate of the light source. Increasing this value changes the angle of the light. To achieve visually appealing shapes, the altitude should be sufficient for reflections but not too high.
  • LightColor: typically white as human perception adjusts gray objects to appear consistent under different lighting conditions, for example daylight blueness changes during the day. Altering it can introduce an unrealistic look.
  • LightSourceDistanceTerm: adds an extra distance between the light source and the object, reducing contrast due to the object's size.
The shading considers three main phenomena: ambiant light, diffuse light and specular highlight.

Ambiant light
AmbientFactor: determines the base illumination of the object, independent of the light's position.

Diffuse light
  • DiffuseFactor: controls how much light is diffused by the object based on the angle of the light. This creates brighter and darker areas on the sphere, depending on the light's angle of incidence.
  • NegativeDiffusionFactor: Darkens the side opposite to the light source, accounting for the limited travel of light around the object (considering the light source contributes to ambiant light).
Specular highlight
  • SpecularFactor: indicates how shiny the object is, simulating light bouncing off like a mirror. The position of the highlight depends on the relative positions of the light source and the observer.
  • SpecularIndex: defines the narrowness of the reflection. The specular reflection matches the light source color, which can differ from the object's color.
Conscience is the debugger of the mind

Gigatron

  • Jr. Member
  • **
  • Posts: 78
  • Amiga Rulez !!
Re: Demo Scene Blitter Objects
« Reply #4 on: May 29, 2024, 04:02:57 pm »
:)  @Tron
Of course the ball.png is not perfect but you can replace it with better image..

Sub Quantum Technology ! We are in a micro universe.

TRon

  • Hero Member
  • *****
  • Posts: 2801
Re: Demo Scene Blitter Objects
« Reply #5 on: May 30, 2024, 01:54:36 am »
Here are some explanations on the settings.  :)
Thank you very much for the extensive explanation(s) circular. That is very much appreciated.

Pardon my ignorance but instead of what seems to be you repeating documentation is there something I can read about such details of the different effects that BGRA contains/support ? Right now I just try and dive into the examples, sources and wiki to get myself acquainted by playing with them but it is not always enough to get a good understanding of some of details of the effects.

For lolz I modified Gigatron's example to draw phong shaded spheres that have a light source originating from the middle of the screen at a certain distance (which would have taken me days to figure out without your splendid explanation). It could just as well be an animated point to make it appear even more dynamic.

Of course the ball.png is not perfect but you can replace it with better image..
Yes, I know  :)

I understand that it is easy enough to add other graphics for the bob routine but that is imho a bit besides the point.

My point is that BGRA contains so many nice features that it almost feels like a shame that the code you present looks like it does not make full use of BGRA. That is not meant to criticize the code itself but in all honestly for most of the effects you showed there is no need to use BGRA et all. For instance all effects shown so far are pretty easy to implement using f.e. PTC and/or normal bitmap graphics.

I look at BGRA as the tool that can be used to create such images and color-schemes as attached in your post, and not (only) for displaying them  :)


edit: for some colourful addition:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  2. const
  3.   h: byte = 0;         // hue value
  4. var
  5.   i,x,y : integer;     // index, xcoord and ycoord of bob
  6.   box   : TRect;       // boxed position of bob
  7.   r,g,b : byte;        // red, green and blue color values
  8.   cd    : integer = 2; // color distance between bobs
  9.   cs    : integer = 1; // color cycling speed
  10. begin
  11.   for i:=0 to 39 do
  12.   begin
  13.     FShading.LightPosition := point(320, 220);
  14.     x := 320+round(size*sin(i*fc+t));
  15.     y := 220+round(size*cos(i*fs+t));
  16.     box := bounds(x, y, 32, 32);
  17.     HLStoRGB((h + i * cd) mod 255, 255 shr 1, 255, r,g,b);
  18.     FShading.DrawSphere(bitmap,box,8,BGRA(r,g,b));
  19.   end;
  20.  
  21.   h := (h + cs) mod 255;
  22. end;
  23.  
« Last Edit: May 30, 2024, 03:18:35 am by TRon »

Gigatron

  • Jr. Member
  • **
  • Posts: 78
  • Amiga Rulez !!
Re: Demo Scene Blitter Objects
« Reply #6 on: May 30, 2024, 04:02:02 pm »
Awesome @Tron thanks for the Phong effect..
Sub Quantum Technology ! We are in a micro universe.

 

TinyPortal © 2005-2018