쉐이더를 자동 생성해주는 MEL.
JSH_TEXTURE_SHADOW_OCC_DEPTH_SHADER_MAKER_V1.0
일명 판맵을 이용한 씬 구성에서 쉐도우와 오클루젼과 뎁스를 뽑기 위해 만든 MEL입니다.
컬러 텍스쳐 이미지의 알파값을 이용해 오브젝트마다 쉐도우 쉐이더를 일괄적으로 만들어 적용시킵니다.
즉, 오브젝트 갯수만큼 쉐이더가 생깁니다.
JSH_TEXTURE_SHADOW_OCC_DEPTH_SHADER_MAKER_V1.0.mel 실행 화면아래 소스 공개이며
첨부파일 다운 받아 마야로 Drag&Drop하면 실행 됩니다.
소스보기
/*** JSH_Make_TEXTURE_OCC_SHADOW V1.0 ***********************************************************************************************
제작자 : 정순홍, KBS 미디어텍 특수영상부(본 멜 스크립트는 저작권을 행사합니다)
버전 0.9 : shadow만 처리, OCC는 V1.0에 추가 예정
버전 1.0 : shadow에 이어 occlusion, depth 기능 추가
설명 : 텍스쳐, 맵소스로 제작된 씬에서 그림자, 오클루젼, 뎁스 를 뽑기 위해 usebackground를 자동 생성하고 기존 텍스쳐를 이용해 알파 마스크를 연결하여 쉐이딩을 자동으로 해줌.
사용법 : 1. 적용할 오브젝트를 모두 선택한 뒤
2. MEL 스크립트 파일을 마우스로 끌어다 창에다 떨어뜨리면 됨 (drag&drop)
3. 자동으로 해당 오브젝트별로 usebackground를 만들어 적용을 시켜줌.
기타문의 : jshong.com@gmail.com 으로 메일 주세요.
명시내용 : 제작자의 동의 없이 무단복제, 배포, 수정을 금합니다.
만약 불특정인이 JSHong_SCRIPT™ 사용시 발생하는 에러 및 피해에 대해서는 제작자가 책임을 지지 않습니다.
*******************************************************************************************************************/
global proc POP_homepage()
{
system("explorer http://www.jshong.com/");
}
/*****************************************************************************************************************
오브젝트에서 메터리얼 알아내는 함수
******************************************************************************************************************/
global proc string getSurfaceShader (string $objName)
{
string $myShapeNode[] = `listRelatives -children -shapes $objName`;
string $mySGs[] = `listConnections -type shadingEngine $myShapeNode[0]`;
string $surfaceShader[] = `listConnections ($mySGs[0] + ".surfaceShader")`;
return $surfaceShader[0];
}
/*****************************************************************************************************************
메터리얼에서 텍스쳐 파일 노드 알아내는 함수
******************************************************************************************************************/
global proc string getTextureFromMaterial( string $material )
{
string $texture = "";
string $class[] = getClassification( `nodeType $material` );
if ( "shader/surface" == $class[0]&&`connectionInfo -id ( $material + ".color" )` )
{
$texture = plugNode( `connectionInfo -sfd ( $material + ".color" )` );
}
return $texture;
}
/*****************************************************************************************************************
SHADOW 생성 함수
******************************************************************************************************************/
global proc Make_TEXTURE_SHADOW_RenderLayer()
{
string $OBJ_List[];
$OBJ_List=`ls -sl`;
int $obj_count;
int $size_obj_count=size($OBJ_List);
string $obj_Name;
string $material_Name;
string $texture_Name;
/*****************************************************************************************************************
FOR 반복문 시작
******************************************************************************************************************/
for ($obj_count=0;$obj_count<$size_obj_count;$obj_count++)
{
string $obj_Name = $OBJ_List[$obj_count];
$material_Name = getSurfaceShader ($obj_Name);
$texture_Name = getTextureFromMaterial($material_Name);
/*****************************************************************************************************************
쉐이더 만들기
******************************************************************************************************************/
$SHADOW_Shader = stringArrayToString({$obj_Name,"_shadow" }, "");
shadingNode -name $SHADOW_Shader -asShader lambert;
/*****************************************************************************************************************
쉐이더 속성 조절하기
******************************************************************************************************************/
string $SHADOW_Shader_color = stringArrayToString({$SHADOW_Shader,".color" }, "");
string $SHADOW_Shader_diff = stringArrayToString({$SHADOW_Shader,".diffuse" }, "");
string $SHADOW_Shader_trans = stringArrayToString({$SHADOW_Shader,".translucence" }, "");
string $SHADOW_Shader_transD = stringArrayToString({$SHADOW_Shader,".translucenceDepth" }, "");
string $SHADOW_Shader_transF = stringArrayToString({$SHADOW_Shader,".translucenceFocus" }, "");
string $SHADOW_Shader_shadowA = stringArrayToString({$SHADOW_Shader,".shadowAttenuation" }, "");
setAttr $SHADOW_Shader_color -type double3 1 1 1 ;
setAttr $SHADOW_Shader_diff 1;
setAttr $SHADOW_Shader_trans 1;
setAttr $SHADOW_Shader_transD 5;
setAttr $SHADOW_Shader_transF 0;
setAttr $SHADOW_Shader_shadowA 0;
string $texture_outAlpha = stringArrayToString({$texture_Name,".outTransparency" }, "");
string $SHADOW_Shader_Trans= stringArrayToString({$SHADOW_Shader,".transparency" }, "");
connectAttr -f $texture_outAlpha $SHADOW_Shader_Trans;
/*****************************************************************************************************************
쉐이더 적용하기
******************************************************************************************************************/
select $obj_Name;
hyperShade -assign $SHADOW_Shader;
}
}
/*****************************************************************************************************************
OCC 생성 함수
******************************************************************************************************************/
global proc Make_TEXTURE_OCC_RenderLayer()
{
string $OBJ_List[];
$OBJ_List=`ls -sl`;
int $obj_count;
int $size_obj_count=size($OBJ_List);
string $obj_Name;
string $material_Name;
string $texture_Name;
/*****************************************************************************************************************
OCC 텍스쳐 생성
******************************************************************************************************************/
mrCreateCustomNode -asTexture "" mib_amb_occlusion;
rename mib_amb_occlusion1 "OCC_Texture" ;
/*****************************************************************************************************************
FOR 반복문 시작
******************************************************************************************************************/
for ($obj_count=0;$obj_count<$size_obj_count;$obj_count++)
{
string $obj_Name = $OBJ_List[$obj_count];
$material_Name = getSurfaceShader ($obj_Name);
$texture_Name = getTextureFromMaterial($material_Name);
/*****************************************************************************************************************
OCC 쉐이더 만들기
******************************************************************************************************************/
$OCC_Shader = stringArrayToString({$obj_Name,"_OCC" }, "");
shadingNode -name $OCC_Shader -asShader lambert;
/*****************************************************************************************************************
OCC 쉐이더 속성 조절하기
******************************************************************************************************************/
string $OCC_Shader_outV = stringArrayToString({$OCC_Shader,".outValue" }, "");
string $OCC_Shader_ambColor = stringArrayToString({$OCC_Shader,".ambientColor" }, "");
string $OCC_Shader_color = stringArrayToString({$OCC_Shader,".color" }, "");
string $OCC_Shader_diff = stringArrayToString({$OCC_Shader,".diffuse" }, "");
string $OCC_Shader_trans = stringArrayToString({$OCC_Shader,".translucence" }, "");
string $OCC_Shader_transD = stringArrayToString({$OCC_Shader,".translucenceDepth" }, "");
string $OCC_Shader_transF = stringArrayToString({$OCC_Shader,".translucenceFocus" }, "");
string $OCC_Shader_shadowA = stringArrayToString({$OCC_Shader,".shadowAttenuation" }, "");
connectAttr -f OCC_Texture.outValue $OCC_Shader_ambColor;
setAttr $OCC_Shader_diff 1;
setAttr $OCC_Shader_trans 1;
setAttr $OCC_Shader_transD 5;
setAttr $OCC_Shader_transF 0;
setAttr $OCC_Shader_shadowA 0;
setAttr $OCC_Shader_color -type double3 1 1 1 ;
string $texture_outAlpha = stringArrayToString({$texture_Name,".outTransparency" }, "");
string $OCC_Shader_Trans= stringArrayToString({$OCC_Shader,".transparency" }, "");
connectAttr -f $texture_outAlpha $OCC_Shader_Trans;
/*****************************************************************************************************************
쉐이더 적용하기
******************************************************************************************************************/
select $obj_Name;
hyperShade -assign $OCC_Shader;
}
}
/*****************************************************************************************************************
DEPTH 쉐이더 생성 함수
******************************************************************************************************************/
global proc Make_TEXTURE_DEPTH_RenderLayer()
{
string $OBJ_List[];
$OBJ_List=`ls -sl`;
int $obj_count;
int $size_obj_count=size($OBJ_List);
string $obj_Name;
string $material_Name;
string $texture_Name;
/*****************************************************************************************************************
기본 depth 쉐이더 생성
******************************************************************************************************************/
shadingNode -name "DEPTH_SHADER" -asShader surfaceShader;
addAttr -ln "depth" -at double DEPTH_SHADER;
shadingNode -name "depth_samplerInfo" -asUtility samplerInfo;
setAttr DEPTH_SHADER.depth 100;
expression -s "float $depth=DEPTH_SHADER.depth;\nfloat $distance=sqrt(pow(depth_samplerInfo.pointCameraX,2)+pow(depth_samplerInfo.pointCameraY,2)+pow(depth_samplerInfo.pointCameraZ,2))/$depth;\n$distance=1-$distance;\n \nDEPTH_SHADER.outColorR=$distance;\nDEPTH_SHADER.outColorG=$distance;\nDEPTH_SHADER.outColorB=$distance;" -o "" -n "depth_exp" -ae 1 -uc all ;
/*****************************************************************************************************************
depth 라이트 생성
******************************************************************************************************************/
defaultDirectionalLight(1, 0,0,0, "0", 0,0,0, 0);
rename "depthLight";
/*****************************************************************************************************************
FOR 반복문 시작
******************************************************************************************************************/
for ($obj_count=0;$obj_count<$size_obj_count;$obj_count++)
{
string $obj_Name = $OBJ_List[$obj_count];
$material_Name = getSurfaceShader ($obj_Name);
$texture_Name = getTextureFromMaterial($material_Name);
/*****************************************************************************************************************
depth 쉐이더 만들기
******************************************************************************************************************/
$DEPTH_Shader = stringArrayToString({$obj_Name,"_depth" }, "");
shadingNode -name $DEPTH_Shader -asShader lambert;
string $DEPTH_Shader_color = stringArrayToString({$DEPTH_Shader,".color" }, "");
string $DEPTH_Shader_ambColor = stringArrayToString({$DEPTH_Shader,".ambientColor" }, "");
string $DEPTH_Shader_diff = stringArrayToString({$DEPTH_Shader,".diffuse" }, "");
string $DEPTH_Shader_trans = stringArrayToString({$DEPTH_Shader,".translucence" }, "");
string $DEPTH_Shader_transD = stringArrayToString({$DEPTH_Shader,".translucenceDepth" }, "");
string $DEPTH_Shader_transF = stringArrayToString({$DEPTH_Shader,".translucenceFocus" }, "");
string $DEPTH_Shader_shadowA = stringArrayToString({$DEPTH_Shader,".shadowAttenuation" }, "");
/*****************************************************************************************************************
depth 쉐이더 속성 조절하기
******************************************************************************************************************/
setAttr $DEPTH_Shader_diff 1;
setAttr $DEPTH_Shader_trans 1;
setAttr $DEPTH_Shader_transD 5;
setAttr $DEPTH_Shader_transF 0;
setAttr $DEPTH_Shader_shadowA 0;
string $texture_outAlpha = stringArrayToString({$texture_Name,".outTransparency" }, "");
string $DEPTH_Shader_Trans= stringArrayToString({$DEPTH_Shader,".transparency" }, "");
connectAttr -f $texture_outAlpha $DEPTH_Shader_Trans;
connectAttr -f DEPTH_SHADER.outColor $DEPTH_Shader_color;
connectAttr -f DEPTH_SHADER.outColor $DEPTH_Shader_ambColor;
/*****************************************************************************************************************
depth 쉐이더 적용하기
******************************************************************************************************************/
select $obj_Name;
hyperShade -assign $DEPTH_Shader;
}
}
/*****************************************************************************************************************
메인 함수
******************************************************************************************************************/
global proc Make_TEXTURE_OCC_SHADOW_RenderLayer()
{
if (`window -ex Make_TEXTURE_OCC_SHADOW_RenderLayer`) { deleteUI Make_TEXTURE_OCC_SHADOW_RenderLayer; }
window -t "JSH_Make_TEXTURE_OCC_SHADOW_RenderLayer" -menuBar true Make_TEXTURE_OCC_SHADOW_RenderLayer;
menu -label "제작자";
menuItem -label "JSHong" -c POP_homepage;
menu -label "도움말" -helpMenu true;
menuItem -label "준비중(digitalog@naver.com)" -c POP_homepage;
columnLayout -adjustableColumn true;
separator - height 10 -width 320 -style "in";
text -l "Shading for Shadow 만들기";
string $OBJ_List[];
button -l "Shading for Shadow" -c "Make_TEXTURE_SHADOW_RenderLayer";
separator - height 10 -width 320 -style "out";
text -l "Shading for OCC 만들기";
string $SG_List[];
button -l "Shading for OCC" -c "Make_TEXTURE_OCC_RenderLayer";
separator - height 10 -width 320 -style "out";
text -l "Shading for DEPTH 만들기";
string $SG_List[];
button -l "Shading for DEPTH" -c "Make_TEXTURE_DEPTH_RenderLayer";
separator - height 10 -width 320 -style "out";
text -l "※ 같은 이름의 오브젝트가 2개 이상일때 실행 불가";
text -l "※ 쉐이딩 정보가 없는 카메라나 커브등이 포함되면 실행 불가";
separator - height 10 -width 320 -style "out";
showWindow Make_TEXTURE_OCC_SHADOW_RenderLayer;
window -edit -w 250 -h 250 Make_TEXTURE_OCC_SHADOW_RenderLayer;
}
Make_TEXTURE_OCC_SHADOW_RenderLayer();