Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- state_out main( state_in s, inputs in )
- {
- scalar PI = 3.1415926535897;
- # s: raster_x, raster_y, resolution_x, resolution_y, C, src, memory
- # out: C
- state_out out;
- vector y_axis = vector(0,1,0);
- //new base...
- vector portalNormal = ntransform(in.global, vector(0,0,1));
- normalize( portalNormal );
- scalar thetaN = atan2(portalNormal.x ,portalNormal.z); //-PI/2 PI/2
- scalar phiN = asin(portalNormal.y) ; //-PI/2.0 +PI/2.0
- scalar thetaP = (s.raster_x / s.resolution_x -0.5)*PI(); //-PI/2.0 +PI/2.0
- scalar phiP = (s.raster_y / s.resolution_y -0.5)*PI(); //-PI/2.0 +PI/2.0
- scalar theta = thetaP + thetaN;
- scalar phi = phiP + phiN;
- if(theta <-PI() )
- {
- theta = PI() - ((abs(theta) % (PI())));
- }
- if(theta > PI())
- {
- theta = -PI() + (theta % PI());
- }
- if(phi > (PI()/2.0))
- {
- phi = PI()/2.0 - (phi % (PI()/2.0));
- if(theta > 0.0)
- {
- theta = theta - PI();
- }
- else
- {
- theta = theta + PI();
- }
- }
- if(phi <( - PI()/2.0))
- {
- phi = -PI()/2.0 + (abs(phi) % (PI()/2.0));
- if(theta > 0.0)
- {
- theta = theta - PI();
- }
- else
- {
- theta = theta + PI();
- }
- }
- vector uv = toUVfromThetaPhi( theta, phi);
- scalar _x = uv.x * width(in.out0);
- scalar _y = uv.y * height(in.out0);
- color pixColor = evaluate(in.out0,_x,_y);
- out.C = pixColor;
- return out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement