Thursday, June 28, 2007

How to determine shader working in slim icon preview or normal prman render

通常Shader如果在rat slim palette中做一些事情會讓整個rat crash掉,
例如bake3d這個function,
或者是需要在preview的時候做一些取巧的小步驟,
這時候就需要判斷現在是rat的internal render還是一般的prman render,
比較傳統的做法是shdader code是genrate出來的,
這樣就可以利用Context來做一些區分,
可是這樣的Shader要寫一堆的output,
而且如果本來的shader就不是這樣寫的就需要花很多的工夫改寫,

這時候可以用option()這個function來作弊,
仔細看preview產生的rib內容,
會發現他會設定 Option "user" "int PreviewRender" [1]
這一般的Render並不會這個otion,
所以可以藉由 option("user:PreviewRender", isPreviewRender) 來做判斷,
這樣應該大部分的情況都可以適用吧!

---------------------------------------------
Some operations will make rat crash in rat slim internal render, like bake3D().
Sometimes we also want to do some trick in preview render.
How to determine shader working environment become very important.
In general case, we can use "Context" to get the environment.
If we want to use this approach, we will write very output to generate code.
If the original shader is rsl shader, it spends a lot time for converting to slim TCL code.

We can do some trikc by using option function.
The preview rib code contains such line:
Option "user" "int PreviewRender" [1]
General prman render didn't set this option.
Therefore, option("user:PreviewRender", isPreviewRender) will get the setting.
I think it would work fine in general case.

No comments: