Author Topic: Stereoscopic geometry test  (Read 17465 times)

0 Members and 2 Guests are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Stereoscopic geometry test
« Reply #20 on: November 01, 2010 »
I almost went to see Clash Of The Titans. And I missed Toy Story 3D :(
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stereoscopic geometry test
« Reply #21 on: November 01, 2010 »
yeah thats right fryer magenta and green. i never got a chance to see resi 3d :( im a huge fan aswell played all the games and watched all the movies so i was dissapointed not to have seen it.

i did see scruge 3d with the new clear filter glasses method and it was a huge leap forward.

for some reason all the two toned 3d movies i try on my phillips 47 ambi light just doesnt work it does work on my old tv in the room though.
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Stereoscopic geometry test
« Reply #22 on: November 01, 2010 »
i did see scruge 3d with the new clear filter glasses method and it was a huge leap forward.
Is that the dolby 3d?

Quote
for some reason all the two toned 3d movies i try on my phillips 47 ambi light just doesnt work it does work on my old tv in the room though.
Do you mean the effect doesn't work? Something was going wrong with some I've tried to play, it looked like either my player or tv was trying to align the 2 channels. Maybe try a different player or switching your tv to game mode or turn off some of the tv's image processing if you can.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stereoscopic geometry test
« Reply #23 on: November 02, 2010 »
sorry ment scrooge 3d :)

not sure what scrooge was. i went to the odieon to see it and got the clear glasses. when you remove the glasses you get the same effect as waking up with a very bad hang over. blurred vision.

Quote
Do you mean the effect doesn't work? Something was going wrong with some I've tried to play, it looked like either my player or tv was trying to align the 2 channels. Maybe try a different player or switching your tv to game mode or turn off some of the tv's image processing if you can.

yeah i bet thats it i have all the image processing switched on for movies and games, i play my movies through the ps3.

im going to have a play around now :).

cheers.
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Stereoscopic geometry test
« Reply #24 on: November 02, 2010 »
In Dolby 3D, instead of using polarised light, the filters let very narrow bands of precise frequencies of light pass for each of the primary colours, the left and right filters having very slightly differing sets of frequencies. Unlike RealD which needs a silvered screen, Dolby 3D can use a normal screen but the glasses are expensive. I've not seen any movies with it yet and not actually sure if there's any local cinemas that do it, have to look into that.

I think playing through my PS3 was fine, it's possibly the image processing in your tv. I'd try switching to game mode and/or turning off any motion smoothing and stuff like that.

Not that you should be using things like motion smoothing when watching movies anyway, my dad keeps turning it on on his and it makes movies look like Eastenders or The Bill.
« Last Edit: November 02, 2010 by Stonemonkey »

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stereoscopic geometry test
« Reply #25 on: November 02, 2010 »
yeah i think it was in RealD, i dont think after looking any of my local cinemas do Dolby 3D either.

and it was my tv i tryed lots of diffrent things last night and started getting the 3d effect working. i didnt even realise the tv filtered images that much! and you were right its made a huge difference in normal movie playback also not so like easties :)

the one format i cant wait for is imax 3d. when it finally makes it round my way ill be going to watch just to see how good it is. im not even caring if its a chick flick lol
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stereoscopic geometry test
« Reply #26 on: November 03, 2010 »
hey sm,

i was trying to adjust the colors on your solid example last night but i cant really get my head around your color scheme. and was just wondering if you could point me in the direction of changing it to blue/magenta.

cheers.
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Stereoscopic geometry test
« Reply #27 on: November 03, 2010 »
For a simple solution a couple of things you could try:

red=0
green=green
blue=blue

Or:

red=50% blue
green=50% (original)red + 50% green
blue=50% blue

Or:

flip the image horizontally so left  becomes right then swap the green and blue channels, the image'll be the wrong way round but I think the depth should still be correct.

I'll post the code within the next couple of days so you can mess around with it then.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stereoscopic geometry test
« Reply #28 on: November 03, 2010 »
i meant the example from your first post mate, but i got it working and wow thats some of the best 3d iv seen its much better tham the movies iv seen. i always thought this sort of 3d was a bit pointless but i see it in a new light now! cheers for that.

i also tried what you said on your image i changed the color channels around and again its really really awsome work. i might have a go at 3d myself.

looking at your code it doesnt look too bad too do.
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Stereoscopic geometry test
« Reply #29 on: November 03, 2010 »
Oops, sorry about that, glad you got it working.

With anaglyph it's not just a matter of making the left channel one colour and the right channel another, the side with two primary colours (magenta=red+blue) can be used to convey quite a bit of colour information while the side with only one colour is more about brightness, there will always be some problems but for something like a demo selection of particular colour schemes could minimise that but that could be tricky if you're going to cater for different types of glasses.

I see quite a lot of potential for 3D in movies and gaming and even though it's nothing new (except the new technology is a vast improvement) it looks like it's going to take a while for it to shrug off the opinion that it's only for the cheesy things jumping out the screen, Avatar and Res Evil are a step in that direction and some of the scenes in My Bloody Valentine were really well done but I think the movie makers are just starting to find out what they can do.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stereoscopic geometry test
« Reply #30 on: November 04, 2010 »
Quote
With anaglyph it's not just a matter of making the left channel one colour and the right channel another, the side with two primary colours (magenta=red+blue) can be used to convey quite a bit of colour information while the side with only one colour is more about brightness.

yeah it took me ages to figuare that out to be able to get the colors right for my glasses.i still have to break it down further to fully get it right in my head, im about 60% there with coloring and i can see whats going on with the projection so i think if i do some basic stuff i can get the basic effect going. im really inpressed that you figuared all that out and got it working as well as it is.

what i did notice with your example was that i was getting the effect much better than my girlfreind, but when changing the brightness and color slightly the opposit was happening. to me it seems like a fine line as to wether someone gets the effect or not, maybe a calibration test before the demo would be good to give the individual the best experiance.


Quote
I see quite a lot of potential for 3D in movies and gaming and even though it's nothing new (except the new technology is a vast improvement) it looks like it's going to take a while for it to shrug off the opinion that it's only for the cheesy things jumping out the screen, Avatar and Res Evil are a step in that direction and some of the scenes in My Bloody Valentine were really well done but I think the movie makers are just starting to find out what they can do.

yeah same here. i cant wait to get the right tv and try out some 3d games and movies at home when it all settles down although iv heard that gt5 doesnt work that well so i just hope sony and others get this right. its only just recently iv started taking a real interest.
« Last Edit: November 04, 2010 by ninogenio »
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Stereoscopic geometry test
« Reply #31 on: November 04, 2010 »
To explain how I'm doing the projection onto the screen:

Consider the screen as a rectangular frame within the scene, it stays in exactly the same position for both the left and right eye projections but each eye is looking through that frame from a slightly different angle.
For each vertex you have two vectors, one to each eye (each eye has to have it's own 3D coordinates), and you use the points where those vectors intersect the screen for the left and right eye screen coordinates. That also takes care of perspective.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Stereoscopic geometry test
« Reply #32 on: November 04, 2010 »
yeah im sort of in the middle of a small demo trying it out the now. just a spining cube.

iv learned loads so far, i must admit i was off with the projection, mines the now doesnt look right but that makes sense cheers.

iv not done any coloring yet im just trying to get the projection looking right first.
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Stereoscopic geometry test
« Reply #33 on: November 10, 2010 »
Sorry, I've not had much time so here's the code for the raytracer as it is.

Code: [Select]
type vec3d
    x as double
    y as double
    z as double
end type

type sphere
   
    union
        coords as vec3d
        type
            x as double
            y as double
            z as double
        end type
    end union
   
    radius as double
    radius2 as double
    radius_recip as double
    min_dist as double
    argb as uinteger
    red as double
    gre as double
    blu as double
    dif as double
    ref as double
    next_sphere as sphere ptr
end type

type world
    first_sphere as sphere ptr
    first_light as sphere ptr
    current_sphere as sphere ptr
    eye as vec3d
    fac as double
    red as double
    gre as double
    blu as double
    ambient as double
end type

sub trace(byref world as world ptr,byval origin as vec3d,byval vec as vec3d)
    dim as sphere ptr sphere=world->first_sphere,current_sphere
    dim as double current_dist=100000,d
    dim as double dist,dx,dy,dz,dtc,lx,ly,lz,s,spec,ca
   
'find closest hit
    while sphere<>0
        if sphere<>world->current_sphere then
            dx=sphere->x-origin.x
            dy=sphere->y-origin.y
            dz=sphere->z-origin.z
            dist=dx*vec.x+dy*vec.y+dz*vec.z
            if dist>0.0 then
                dx-=vec.x*dist
                dy-=vec.y*dist
                dz-=vec.z*dist
                dtc=dx*dx+dy*dy+dz*dz
                if dtc<=sphere->radius2 then
                    d=dist-sqr(sphere->radius2-dtc)
                    if (d>0)and(d<current_dist) then
                        current_sphere=sphere
                        current_dist=d
                    end if
                end if
            end if
        end if
        sphere=sphere->next_sphere
    wend
   
    dim as double vecx,vecy,vecz,sv
    dim as double shadow
   
'if hit found then
    if current_sphere<>0 then
        origin.x+=current_dist*vec.x
        origin.y+=current_dist*vec.y
        origin.z+=current_dist*vec.z
       
        vecx=world->first_light->x-origin.x
        vecy=world->first_light->y-origin.y
        vecz=world->first_light->z-origin.z
        d=1.0/sqr(vecx*vecx+vecy*vecy+vecz*vecz)
        vecx*=d
        vecy*=d
        vecz*=d
        shadow=0
        sphere=world->first_sphere
        sv=1.0
       
'test for shadow
        while (sphere<>0)'and(shadow=0)
            if sphere<>current_sphere then
                dx=sphere->x-origin.x
                dy=sphere->y-origin.y
                dz=sphere->z-origin.z
                dist=dx*vecx+dy*vecy+dz*vecz
                if dist>0.0 then
                    dx-=vecx*dist
                    dy-=vecy*dist
                    dz-=vecz*dist
                    dtc=dx*dx+dy*dy+dz*dz
                    if dtc<=sphere->radius2 then
                        shadow=sqr(dtc)/sphere->radius
                        if shadow<sv then sv=shadow
                    end if
                end if
            end if
            sphere=sphere->next_sphere
        wend

'shade
        sv=sv*sv
        dx=(origin.x-current_sphere->x)*current_sphere->radius_recip
        dy=(origin.y-current_sphere->y)*current_sphere->radius_recip
        dz=(origin.z-current_sphere->z)*current_sphere->radius_recip
        ca=(dx*-vec.x+dy*-vec.y+dz*-vec.z)
        if ca<0.0 then ca=0.0
        lx=world->first_light->x-origin.x
        ly=world->first_light->y-origin.y
        lz=world->first_light->z-origin.z
        d=2.0*(dx*vec.x+dy*vec.y+dz*vec.z)
        vec.x-=dx*d
        vec.y-=dy*d
        vec.z-=dz*d
 
        d=1.0/sqr(lx*lx+ly*ly+lz*lz)
        s=((lx*dx+ly*dy+lz*dz)*d)*ca
        spec=(lx*vec.x+ly*vec.y+lz*vec.z)*d
        if s<0.0 then s=0.0
        spec=(spec-0.8)*5.0
        if spec<0.0 then spec=0.0
        spec=spec*spec*spec*spec*spec*current_sphere->ref
           
        world->red+=(current_sphere->red*s+spec)*world->fac*sv
        world->gre+=(current_sphere->gre*s+spec)*world->fac*sv
        world->blu+=(current_sphere->blu*s+spec)*world->fac*sv
       
        world->fac*=current_sphere->ref
        world->current_sphere=current_sphere
        if world->fac>0.125 then trace(world,origin,vec)
    end if
   
end sub


sub main
   
    screenres 1360,768,32,1
   
    dim as integer wwidth,height
    screeninfo wwidth,height
   
    dim as uinteger ptr buffer(0 to 1)
    buffer(0)=callocate(len(uinteger)*wwidth*height)
    buffer(1)=callocate(len(uinteger)*wwidth*height)
   
    dim as world world
    dim as sphere sphere1,sphere2,sphere3,sphere4,light
    sphere1.radius=150
    sphere1.radius2=sphere1.radius*sphere1.radius
    sphere1.radius_recip=1.0/sphere1.radius
    sphere1.x=210
    sphere1.y=-180.0
    sphere1.z=780.0
    sphere1.ref=0.6
    sphere1.red=rnd
    sphere1.gre=rnd
    sphere1.blu=rnd
   
    sphere2.radius=150
    sphere2.radius2=sphere2.radius*sphere2.radius
    sphere2.radius_recip=1.0/sphere2.radius
    sphere2.x=-20.0
    sphere2.y=-60.0
    sphere2.z=550.0
    sphere2.ref=0.6
    sphere2.red=rnd
    sphere2.gre=rnd
    sphere2.blu=rnd
   
    sphere3.radius=150
    sphere3.radius2=sphere3.radius*sphere3.radius
    sphere3.radius_recip=1.0/sphere3.radius
    sphere3.x=-180.0
    sphere3.y=-60.0
    sphere3.z=-1150.0
    sphere3.ref=0.6
    sphere3.red=rnd
    sphere3.gre=rnd
    sphere3.blu=rnd
   
    sphere4.radius=10000
    sphere4.radius2=sphere4.radius*sphere4.radius
    sphere4.radius_recip=1.0/sphere4.radius
    sphere4.x=2000.0
    sphere4.y=500.0
    sphere4.z=15000.0
    sphere4.ref=0.0
    sphere4.red=rnd*.25
    sphere4.gre=rnd*.25
    sphere4.blu=rnd*.25
   
    dim as sphere floor(0 to 2000)
    dim as integer sc
    for x as integer=0 to 30 step 4
        for y as integer=0 to 60 step 4
            floor(sc).radius=20
            floor(sc).radius2=floor(sc).radius*floor(sc).radius
            floor(sc).radius_recip=1.0/floor(sc).radius
            floor(sc).x=x*30-450
            floor(sc).y=200.0+10.0*sin((x+1.0)/2)*cos(y/1.73)
            floor(sc).z=y*40-800'+z_pos
            floor(sc).ref=0.2
            floor(sc).red=.6+rnd*.2
            floor(sc).gre=.6+rnd*.2
            floor(sc).blu=.2+rnd*.2
            floor(sc).next_sphere=@floor(sc+1)
            sc+=1
        next
    next
   
    light.x=1500
    light.y=-2000
    light.z=-1000
    dim as vec3d v,p
    dim as double d,red,gre,blu
    world.first_sphere=@sphere1
    sphere1.next_sphere=@sphere2
    sphere2.next_sphere=@sphere3
    sphere3.next_sphere=@sphere4
    sphere4.next_sphere=@floor(0)
    world.first_light=@light
    world.ambient=0.2
   
    p.x=-40.0
    p.y=0.0
    p.z=-3000.0
    dim as integer pix,q
for frame as integer=0 to 1
    for y as double=-384 to 383
        for x as double=-680 to 679
            q+=1
            if q=50 then
                'sleep 1
                q=0
            end if
           
            v.x=x-p.x
            v.y=y-p.y
            v.z=-p.z
            d=1.0/sqr(v.x*v.x+v.y*v.y+v.z*v.z)
            v.x*=d
            v.y*=d
            v.z*=d
            world.red=0.0
            world.gre=0.0
            world.blu=0.0
            world.fac=1.0
            world.current_sphere=0
            trace(@world,p,v)
if 1=2 then
            v.x=x+0.5-p.x
            v.y=y-p.y
            v.z=-p.z
            d=1.0/sqr(v.x*v.x+v.y*v.y+v.z*v.z)
            v.x*=d
            v.y*=d
            v.z*=d
            world.fac=1.0
            world.current_sphere=0
            trace(@world,p,v)
            v.x=x-p.x
            v.y=y+0.5-p.y
            v.z=-p.z
            d=1.0/sqr(v.x*v.x+v.y*v.y+v.z*v.z)
            v.x*=d
            v.y*=d
            v.z*=d
            world.fac=1.0
            world.current_sphere=0
            trace(@world,p,v)
            v.x=x+0.5-p.x
            v.y=y+0.5-p.y
            v.z=-p.z
            d=1.0/sqr(v.x*v.x+v.y*v.y+v.z*v.z)
            v.x*=d
            v.y*=d
            v.z*=d
            world.fac=1.0
            world.current_sphere=0
            trace(@world,p,v)
            world.red*=0.25
            world.gre*=0.25
            world.blu*=0.25
endif
            if world.red>1.0 then world.red=1.0
            if world.gre>1.0 then world.gre=1.0
            if world.blu>1.0 then world.blu=1.0
            pset(x+680,y+384),((world.red*255.0)shl 16)or((world.gre*255.0)shl 8)or(world.blu*255.0)
            pix=(x+(wwidth shr 1))+(y+(height shr 1))*wwidth
            *(buffer(frame)+pix)=((world.red*255.0)shl 16)or((world.gre*255.0)shl 8)or(world.blu*255.0)
        next
        sleep 1
    next
    p.x=-p.x
    'p.y=0.0
    'p.z=-1400.0
next
dim as uinteger argb0,argb1,red0,gre0
    for y as integer=0 to height-1
        for x as integer=0 to wwidth-1
            argb0=*(buffer(0)+x+y*wwidth)
            argb1=*(buffer(1)+x+y*wwidth)
           
            argb1=((argb1 and &hff)*178)+(((argb1 shr 8) and &hff)*39)+(((argb1 shr 16) and &hff)*39)
           
            red0=217*((argb0 shr 16)and &hff)+39*(argb0 and &hff)
            gre0=217*((argb0 shr 8)and &hff)+39*(argb0 and &hff)
           
            pset(x,y),(argb1 shr 8) or ((red0 shl 8)and &hff0000) or (gre0 and &hff00)
        next
    next
   
end sub

main

sleep

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Stereoscopic geometry test
« Reply #34 on: August 06, 2012 »
Hi all, got the chance to mess around with this a bit over the weekend.

Press A to cycle through glasses
amber/blue
red/blue (seems to be best for depth)
green/magenta

Press B to switch between light/dark background, light gives best effect though.

The colouring needs some work but I think the 3d effect works pretty well.
« Last Edit: August 06, 2012 by Stonemonkey »