注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Madao

MaDao 废柴!傻逼和牛逼,某些角度看,其实没区别

 
 
 

日志

 
 

MaxScriptRayTracing 2 之渲染深度值  

2010-06-25 19:20:07|  分类: MaxDev |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
MaxScriptRayTracing 2 之渲染深度值 - 脑残猥琐怪 - 我就是想看看网易博客的名字到底能有多长啊
 

预留空间

Fn IntersectRaySphere theRay theSphere =
(
    helperVector = theSphere.Pos - theRay.Pos
    helperValue = Dot helperVector theRay.Dir
    theRayShadow = theRay.Dir * HelperValue
    theEdgeLength = (theSphere.Radius ^ 2) - (distance helperVector theRayShadow) ^
2

    if theEdgeLength >= 0
then
   
(
        theEdgeLengthSqrtRoot = sqrt theEdgeLength
        if (distance theRay.Pos theSphere.Pos) < theSphere.Radius
then
       
(
            helperValue +=  theEdgeLengthSqrtRoot
       
)
       
else
       
(
            helperValue -=  theEdgeLengthSqrtRoot
       
)
        theRay.Dir * helperValue + theRay.Pos
   
)
    else
undefined
)

Fn
WrapperCamera TheCamera
=
(
    local NewCamera,tempCamera,CreateRay

    Struct NewCamera

   
(
        Base
,
        Pos,Front,Up,Right,TM,Fov,FovScale
,
        fn GenerateRay canvX canvY =

       
(
            local camX,camY,rayDir
            camX = right * ((canvX - 0.5) * fovScale
)
            camY = UP * ((canvY - 0.5) * fovScale
)
            rayDir = Normalize (Front + camX + camY
)
            ray Pos rayDir
       
)
   
)
    tempCamera = NewCamera
()
    tempCamera.Base = theCamera
    tempCamera.Pos = theCamera.Pos
    tempCamera.TM = theCamera.Transform
    tempCamera.Front = Normalize (-theCamera.Transform.Row3
)
    tempCamera.UP = Normalize theCamera.Transform.Row2
    tempCamera.Right = Normalize theCamera.Transform.Row1
    tempCamera.Fov = theCamera.Fov
    tempCamera.FovScale = (tan (theCamera.Fov * 0.5)) *
2
    tempCamera
)

Fn
RenderDepth theCanvas theCamera depthMax =

(
    local canvasHeight , canvasWidth
    canvasHeight = theCanvas.Height - 1

   
canvasWidth = theCanvas.Width -
1
   
   
for canvY = 0.0 to canvasHeight
do
   
(
        screenY = 1 - canvY/theCanvas.Height
        for canvX = 0.0 to canvasWidth
do
       
(
            screenX = canvX/theCanvas.Width
            theRay = theCamera.GenerateRay screenX screenY
            rayResult = IntersectRaySphere theRay Geometry[1
]
            if rayResult != undefined
do
           
(
                resultDepth = ((distance theCamera.pos rayResult)/ depthMax) *
255
                depth =  255 - (if resultDepth < 255 then resultDepth else 255
)
                R = G = B = depth
                SetPixels theCanvas [canvX,canvY] #((color  R G B
))
           
)
       
)
   
)
    Display theCanvas
)


delete
objects
Sphere
()
MaxCamera = FreeCamera
()
MaxCamera.Pos.Z =
100
theCamera = WrapperCamera (MaxCamera
)
GC
()
FreeSceneBitmaps
()
UnDisplay theCanvas
CanvasWidth =
200
CanvasHeight =
200
theCanvas = Bitmap CanvasWidth CanvasHeight color:
black
RenderDepth theCanvas theCamera  100



预留空间

还没写注释,有兴趣的朋友可以尝试用MaxScript的IntersectRay、IntersectRayEX、IntersectRayScene来做这个范例。

该贴搬到博客园

http://www.cnblogs.com/sitt/articles/1767174.html

  评论这张
 
阅读(394)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018