Author Topic: Sky in raycaster  (Read 513 times)

darkhog

  • Newbie
  • *
  • Posts: 40
    • View Profile
Sky in raycaster
« on: June 03, 2016 »
I'm at a loss, really. Probably won't get any reply, what with the software and community virtually dead, but what the hell. I'm trying to render a sky in raycaster. To that end, I didn't define any ceiling in my map and just tiling sky image before I call RC_Render. My main loop:

Code: [Select]
do
proc UpdatePlayer
rem set color 0,0,0
cls
proc DrawSky
proc RC_Render player.x#, player.z#, player.angle#, sin(float(time()))
redraw
proc SPD_HoldFrame(60)
until keydown(VK_ESC)

DrawSky just tile sky image on screen (sidenote: STEP option for FOR loop would be nice so I don't have to add to iterator inside the loop). If I run it as it is now, it renders fine, but once you start moving around, the sky becomes hall of mirrors for some reason, as if any of the subsequent DrawSky calls didn't mean anything at all. If I uncomment set color line, there's no hall of mirrors effect, but the sky isn't rendered. If I set alpha to 0 in set color, there's both HOM and sky isn't shown.

As I said, I don't expect any reply with it being a dead project and all. Just needed to get it off my chest. Here's DrawSky for anyone interested:

Code: [Select]
procedure DrawSky()
for x=0 to 320
for y=0 to 240
draw image SKY,x,y
y=y+height(SKY)-1
next
x=x+width(SKY)-1
next
endproc

As you can see, nothing weird here, just tiling the sky image.

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 549
    • View Profile
Re: Sky in raycaster
« Reply #1 on: June 04, 2016 »
Actually I'm working on changes for the raycaster these Days.

Additive sprites:

https://www.youtube.com/watch?v=aMssDiXPXC8

Combination with the blur function from the IFX library I just posted about:

https://www.youtube.com/watch?v=NzbrbHK4Vhw

I'm also working on online multiplayer stuff for NaaLaa, so even if I'm away a lot I still work with and on NaaLaa :)
.\\\opz

darkhog

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Sky in raycaster
« Reply #2 on: June 05, 2016 »
Yeah, seen posts on FB (Dariusz G. Jagielski). But it needs to have support for skybox or at least skyplane displayed when ceiling is transparent or undefined. Also the fact that you are working on raycaster doesn't help with my issue.

Marcus

  • Administrator
  • Hero Member
  • *****
  • Posts: 549
    • View Profile
Re: Sky in raycaster
« Reply #3 on: June 09, 2016 »
I'll have a look at your code soon, sounds weird.

Have you looked at the Blaztap game example?

Code: [Select]
set color 0, 0, 0
cls
if vUseSky
set color 255, 255, 255
x = int(vPlayerAngle*320.0/60.0)%320
draw image SKY_IMG, -x, 0
draw image SKY_IMG, -x + 320, 0
endif

proc RC_Render vPlayerX, vPlayerZ, vPlayerAngle, 0.0

There I use a sky image the width of the window (320), which corresponds to the 60 degree field of view. So using the modulus operator on the player's current angle I just need to draw two images for the sky.

Edit  There's some sky rendering going on in the attached program too, don't remember, was just something that I wanted to show a friend.
« Last Edit: June 09, 2016 by Marcus »
.\\\opz

darkhog

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Sky in raycaster
« Reply #4 on: June 09, 2016 »
Here's full source:

Code: [Select]
rem Omnidirectional sprite demo.
rem With this technique you can avoid common for raytracing
rem "rotating around with you" synfrome.
rem Ideally, this would be part of the raycaster itself
rem but I don't have time or will to modify both raycaster
rem and the RC_Edit to accomodate the technique.
rem So someone else should do it. Marcus perhaps?
import "Raycaster.lib"
import "Speed.lib"
import "Keycodes.lib"
import "Math.lib"
constant:
rem Images:
HPACKDIR1=1
HPACKDIR2=2
HPACKDIR3=3
HPACKDIR4=4
HPACKDIR5=5
HPACKDIR6=6
HPACKDIR7=7
HPACKDIR8=8
SKY=666
visible:
packs?[100]
player?
packcount=0

procedure LoadAssets()
load image HPACKDIR1, "data/healthpack0.png"
load image HPACKDIR2, "data/healthpack1.png"
load image HPACKDIR3, "data/healthpack2.png"
load image HPACKDIR4, "data/healthpack3.png"
load image HPACKDIR5, "data/healthpack4.png"
load image HPACKDIR6, "data/healthpack5.png"
load image HPACKDIR7, "data/healthpack6.png"
load image HPACKDIR8, "data/healthpack7.png"
set image colorkey HPACKDIR1,true
set image colorkey HPACKDIR2,true
set image colorkey HPACKDIR3,true
set image colorkey HPACKDIR4,true
set image colorkey HPACKDIR5,true
set image colorkey HPACKDIR6,true
set image colorkey HPACKDIR7,true
set image colorkey HPACKDIR8,true
  load image SKY, "data/sky.png"
endproc

procedure LoadMap()
flags[][] = RC_LoadMap("data/demo.txt")
player.x# = float(flags[0][RC_X]) + 0.5
player.z# = float(flags[0][RC_Z]) + 0.5
player.angle# = float(flags[0][RC_ANGLE])
for i = 1 to sizeof(flags, 0) - 1
rem Enemy?
if flags[i][RC_FLAG] = 1
pack?
pack.angle#=0.0
pack.img=1
pack.x#=float(flags[i][RC_X]) + 0.5
pack.z#=float(flags[i][RC_Z]) + 0.5
pack.id=i
packs[packcount]=pack
packcount=packcount+1
proc RC_AddObject pack.id,pack.img,pack.x#,pack.z#,0.0,0.25,-1,-1
endif
next

endproc

procedure DrawSky()
for x=0 to 320
for y=0 to 240
draw image SKY,x,y
y=y+height(SKY)-1
next
x=x+width(SKY)-1
next
endproc

procedure UpdatePlayer()
rem Move.
if keydown(VK_LEFT) then player.angle# = player.angle# - 2.0
if keydown(VK_RIGHT) then player.angle# = player.angle# + 2.0
if keydown(VK_UP)
pos#[] = RC_Move(0.4, player.x#, player.z#, cos(player.angle#)*0.04, sin(player.angle#)*0.04)
player.x# = pos[RC_X]
player.z# = pos[RC_Z]
endif
if keydown(VK_DOWN)
pos#[] = RC_Move(0.4, player.x#, player.z#, -cos(player.angle#)*0.04, -sin(player.angle#)*0.04)
player.x# = pos[RC_X]
player.z# = pos[RC_Z]
endif
endproc

proc LoadAssets
proc LoadMap
set window 0, 0, 320, 240, false,2
set redraw off
proc RC_InitView 65.0, width(primary), height(primary)
rem mainloop

do
proc UpdatePlayer
rem set color 0,0,0
cls
proc DrawSky
proc RC_Render player.x#, player.z#, player.angle#, sin(float(time()))
redraw
proc SPD_HoldFrame(60)
until keydown(VK_ESC)

Tried to learn how to do that omnisprite thing I've talked about on FB (thanks, btw., will take a look at BlazTrap) but wanted to throw also sky rendering. I'm using whatever NaaLaa version is on the site.