ldirko

bm

Jul 30th, 2020 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. program BumpMapper;
  2.  
  3. Uses Crt,Dos,TJVga; { This file won't compile without TJVga, haha }
  4.  
  5. Type ronne=Array[0..255,0..254]of byte; { The environmentmap array }
  6. rptr=^ronne; { Same, but pointer }
  7.  
  8. Var environmentmap:rptr;
  9. i,j:integer;
  10. mx,my:integer; { Light position }
  11. xdir,ydir:integer;
  12. VirScr2:VirtPtr; { The second virtual screen, used for the bumpmap }
  13. Vaddr2:word;
  14.  
  15. Procedure CreateEnvironmentMap; { Guess??? }
  16. Var I,J:Integer;
  17. nx,ny,nz:real;
  18. begin
  19. getmem(environmentmap,sizeof(environmentmap^)); { Biggos pointeros }
  20. for i := 0 to 255 do { Very slooooow }
  21. for j := 0 to 254 do begin
  22. nX:=(i-128)/128;
  23. nY:=(j-128)/128;
  24. nZ:=1-sqrt(nX*nX+nY*nY);
  25. if nz<0 then nZ:=0;
  26. environmentmap^[i,j]:=Round(nZ*128);
  27. end;
  28. end;
  29.  
  30. Procedure Bumpmap(lightx,lighty:integer);
  31. var xtemp,ytemp,temp,i,j:integer;
  32. nx,ny:integer;
  33. begin
  34. for i := 0 to 319 do
  35. for j := 1 to 198 do begin {Skip the first and last line, cause they look bad}
  36. nx:=getpixel(i-1,j,vaddr2)-getpixel(i+1,j,vaddr2);
  37. ny:=getpixel(i,j-1,vaddr2)-getpixel(i,j+1,vaddr2);
  38. asm
  39. mov ax,i
  40. sub ax,lightx { xtemp:=i-lightx;}
  41. mov xtemp,ax
  42. mov ax,j
  43. sub ax,lighty { ytemp:=j-lighty;}
  44. mov ytemp,ax
  45. mov ax,nx
  46. sub ax,xtemp { dec(nx,xtemp);}
  47. mov nx,ax
  48. mov ax,ny
  49. sub ax,ytemp { dec(ny,ytemp);}
  50. mov ny,ax
  51. mov ax,nx
  52. add ax,128 { inc(nx,128); }
  53. mov nx,ax
  54. mov ax,ny
  55. add ax,128 { inc(ny,128;}
  56. mov ny,ax
  57. end;
  58.  
  59. if (nx<0) or (nx>255) then nx:=0; { Check ranges }
  60. if (ny<0) or (ny>255) then ny:=0;
  61. putpixel(i,j,environmentmap^[nx,ny],vaddr); { Put the pixel }
  62. end;
  63. end;
  64.  
  65. begin
  66. Writeln('[Creating Environment map]');
  67. CreateEnvironmentMap; { Bla,bla}
  68. Writeln('Done.');
  69. SetMCGA; { Init the graphics mode }
  70. mx:=160; { Start position of the light }
  71. my:=100;
  72. SetupVirtual; { Init virtual screens}
  73. getmem(virscr2,sizeof(virscr2^));
  74. vaddr2:=seg(virscr2^);
  75. cls(vaddr,0);
  76. LoadPCX('bumpmap.pcx',0,0,Vaddr2); { Load the PCX-file to use as bumpmap }
  77. for i := 0 to 63 do { Set the fire palette }
  78. pal(i,i,0,0);
  79. for i := 64 to 127 do
  80. pal(i,63,i-64,0);
  81. for i := 128 to 255 do
  82. pal(i,63,63,i div 4);
  83. xdir:=4;
  84. ydir:=-4;
  85. repeat
  86. BumpMap(mx,my);
  87. flip(vaddr,vga);
  88. inc(mx,xdir);
  89. inc(my,ydir);
  90. if mx<0 then xdir:=-xdir;
  91. if mx>319 then xdir:=-xdir;
  92. if my<0 then ydir:=-ydir;
  93. if my>199 then ydir:=-ydir;
  94. until keypressed;
  95. freemem(environmentmap,sizeof(environmentmap^));
  96. freemem(virscr2,sizeof(virscr2^));
  97. ShutDown; { Deallocate virtual screen }
  98. SetText; { Set text mode }
  99. Writeln('TJ -1998');
  100. end.
Add Comment
Please, Sign In to add comment