DAZ Script "Scripted Renderer - Render Pass Script" Sample

Description :

Below is the source of the DAZ Script that controls the rendering process for the DzScriptedRenderer in DAZ Studio Advanced.

 
Concepts Covered :
  • DESCRIPTION NEEDED
 
Source : ./samples/advanced/scripted renderer/scripts/support/ScriptedRendererExample/
00001 // DAZ Studio version 3.0  filetype DAZ Script
00002 /**********************************************************************
00003     File: StandardRenderPass.dsa
00004 
00005     Copyright © 2002-2009 DAZ Productions. All Rights Reserved.
00006 
00007     This file is part of the DAZ Script Documentation.
00008 
00009     This file may be used only in accordance with the DAZ Script 
00010     license provided with the DAZ Script Documentation.
00011 
00012     The contents of this file may not be disclosed to third parties, 
00013     copied or duplicated in any form, in whole or in part, without the 
00014     prior written permission of DAZ Productions, except as explicitly
00015     allowed in the DAZ Script license.
00016 
00017     See http://www.daz3d.com to contact DAZ Productions or for more 
00018     information about DAZ Script.
00019 **********************************************************************/
00020 // This script is called once per frame
00021 /**********************************************************************/
00022 var oOWNER = Renderer.getPropertyHolder();
00023 
00024 // Initialize
00025 var aShadows = [""];
00026 var aParams = [1];
00027 var aTokens = [""];
00028 var sizeRender = Renderer.getHandler().getSize();
00029 var i = 0;
00030 
00031 //SHADOW PASS
00032 /**********************************************************************/
00033 // This will reuse shadows
00034 var sShadowPass = String( "%1/shadowMaps" ).arg( App.getTempPath() );
00035 aShadows = Renderer.doDefaultShadowPass( RenderOptions, Camera, sShadowPass, true );
00036 // This will generate new shadows
00037 //aShadows = Renderer.doDefaultShadowPass( RenderOptions, Camera, sShadowPass, false );
00038 
00039 // OTHER PASSES
00040 /**********************************************************************/
00041 // Add other passes as desired. 
00042 // Passes start with Renderer.riBegin() and end with Renderer.EndWorld();
00043 //..........
00044 
00045 // BEAUTY PASS
00046 /**********************************************************************/    
00047 // Default to a standard render
00048 var sRIB = "";
00049 // Find the "Render to RIB" property
00050 oProperty = oOWNER.findProperty( "Render to RIB" );
00051 // If the property was found and its a bool property
00052 if( oProperty && oProperty.className() == "DzBoolProperty" && oProperty.getBoolValue() == true )
00053 {
00054     oProperty = oOWNER.findProperty( "RIB Path" );
00055     // If the property was found and its a file property
00056     if( oProperty && oProperty.className() == "DzFileProperty" )
00057     {
00058         // Get the property value
00059         sRIB = oProperty.getValue();
00060     }
00061 }
00062 // Begin describing the render
00063 Renderer.riBegin(sRIB);
00064 
00065 // Start with the default
00066 var nFilter = RenderOptions.pixelFilter;
00067 // Find the "Pixel Filter" property
00068 oProperty = oOWNER.findProperty( "Pixel Filter" );
00069 // If the property was found and its an enum property
00070 if( oProperty && oProperty.className() == "DzEnumProperty" )
00071 {
00072     switch(oProperty.getValue())
00073     {
00074         case 0:
00075             nFilter = RenderOptions.Box;
00076             break;
00077         case 1:
00078             nFilter = RenderOptions.Triangle;
00079             break;
00080         case 2:
00081             nFilter = RenderOptions.CatmullRom;
00082             break;
00083         case 3:
00084             nFilter = RenderOptions.Gaussian;
00085             break;
00086         default:
00087         case 4:
00088             nFilter = RenderOptions.Sinc;
00089             break;
00090     }
00091 }
00092     
00093 // Start with the default
00094 var nWidthX = RenderOptions.xFilterWidth;
00095 // Find the "Pixel Filter Width X" property
00096 oProperty = oOWNER.findProperty( "Pixel Filter Width X" );
00097 // If the property was found and its a float property
00098 if( oProperty && oProperty.className() == "DzFloatProperty" )
00099 {
00100     nWidthX = oProperty.getValue();
00101 }
00102 
00103 // Start with the default
00104 var nWidthY = RenderOptions.xFilterWidth;
00105 // Find the "Pixel Filter Width X" property
00106 oProperty = oOWNER.findProperty( "Pixel Filter Width Y" );
00107 // If the property was found and its a float property
00108 if( oProperty && oProperty.className() == "DzFloatProperty" )
00109 {
00110     nWidthY = oProperty.getValue();
00111 }
00112 
00113 // Set pixel filter
00114 Renderer.riPixelFilter( nFilter, nWidthX, nWidthY );
00115 
00116 // Specify shader search path
00117 aTokens = ["string shader"];
00118 aParams = [Renderer.getDefaultShaderSearchPath()];
00119 Renderer.riOption( "searchpath", aTokens, aParams );
00120 
00121 
00122 // Start with the default
00123 var sOrder = "horizontal";
00124 // Find the "Bucket Order" property
00125 oProperty = oOWNER.findProperty( "Bucket Order" );
00126 // If the property was found and its an enum property
00127 if( oProperty && oProperty.className() == "DzEnumProperty" )
00128 {
00129     sOrder = oProperty.getStringValue();
00130 }
00131 // Set bucket order
00132 aTokens = ["bucketorder"];
00133 aParams = [sOrder.lower()];
00134 Renderer.riOption( "render", aTokens, aParams );
00135 
00136 
00137 // Start with the default
00138 var nSize = 16;
00139 // Find the "Bucket Size" property
00140 oProperty = oOWNER.findProperty( "Bucket Size" );
00141 // If the property was found and its an int property
00142 if( oProperty && oProperty.className() == "DzIntProperty" )
00143 {
00144     nSize = oProperty.getValue();
00145 }
00146 // Set bucket size
00147 aTokens = ["integer bucketsize[2]"];
00148 aParams = [[nSize, nSize]];
00149 Renderer.riOption( "limits", aTokens, aParams );
00150 
00151 
00152 // Start with the default
00153 var nDepth = RenderOptions.rayTraceDepth;
00154 // Find the "Max Ray Depth" property
00155 oProperty = oOWNER.findProperty( "Max Ray Depth" );
00156 // If the property was found and its an int property
00157 if( oProperty && oProperty.className() == "DzIntProperty" )
00158 {
00159     nDepth = oProperty.getValue();
00160 }
00161 // Set max trace depth
00162 aTokens = ["integer maxdepth"];
00163 aParams = [nDepth];
00164 Renderer.riOption( "trace", aTokens, aParams );
00165 
00166 
00167 // Start with the default
00168 var nGain = RenderOptions.gain;
00169 // Find the "Gain" property
00170 oProperty = oOWNER.findProperty( "Gain" );
00171 // If the property was found and its a float property
00172 if( oProperty && oProperty.className() == "DzFloatProperty" )
00173 {
00174     nGain = oProperty.getValue();
00175 }
00176 
00177 // Start with the default
00178 var nGamma = RenderOptions.gamma;
00179 // Find the "Gain" property
00180 oProperty = oOWNER.findProperty( "Gamma" );
00181 // If the property was found and its a float property
00182 if( oProperty && oProperty.className() == "DzFloatProperty" )
00183 {
00184     nGamma = oProperty.getValue();
00185 }
00186 
00187 // Set exposure
00188 Renderer.riExposure( nGain, nGamma );
00189 
00190 
00191 // Start with the default
00192 var nRate = RenderOptions.shadingRate;
00193 // Find the "Shading Rate" property
00194 oProperty = oOWNER.findProperty( "Shading Rate" );
00195 // If the property was found and its a float property
00196 if( oProperty && oProperty.className() == "DzFloatProperty" )
00197 {
00198     nRate = oProperty.getValue();
00199 }
00200 // Set shading rate
00201 Renderer.riShadingRate( nRate );
00202 
00203 
00204 // Start with the default
00205 var nSamplesX = RenderOptions.xPixelSamples;
00206 // Find the "Pixel Samples X" property
00207 oProperty = oOWNER.findProperty( "Pixel Samples X" );
00208 // If the property was found and its a int property
00209 if( oProperty && oProperty.className() == "DzIntProperty" )
00210 {
00211     nSamplesX = oProperty.getValue();
00212 }
00213 
00214 // Start with the default
00215 var nSamplesY = RenderOptions.yPixelSamples;
00216 // Find the "Pixel Samples Y" property
00217 oProperty = oOWNER.findProperty( "Pixel Samples Y" );
00218 // If the property was found and its a int property
00219 if( oProperty && oProperty.className() == "DzIntProperty" )
00220 {
00221     nSamplesY = oProperty.getValue();
00222 }
00223 
00224 // Set pixel samples
00225 Renderer.riPixelSamples( nSamplesX, nSamplesY );
00226 
00227 
00228 // Set number of sides
00229 Renderer.riSides( 2 );
00230 
00231 // Set up the camera
00232 Renderer.cameraProject( Camera, sizeRender.width, sizeRender.height );
00233 
00234 // Set up crop window
00235 Renderer.setCropWindow(Renderer.getHandler());
00236 
00237 // Set up the display(s)
00238 Renderer.doDefaultDisplay();
00239 
00240 // Set the background color; from the active viewport
00241 if( BackDrop && BackDrop.getTexture()  )
00242 {
00243     Renderer.renderBackDrop( BackDrop, sizeRender.width, sizeRender.height );
00244 }
00245 else // TODO: Check for DzShaderCamera & DzBrickCamera with Imager
00246 {
00247     var oVIEWPORT_MANAGER = MainWindow.getViewportMgr();
00248     var oVIEWPORT = oVIEWPORT_MANAGER.getActiveViewport();
00249     var o3DVIEWPORT = oVIEWPORT.get3DViewport();
00250     
00251     aTokens = ["color bgcolor"];
00252     //aParams = [[o3DVIEWPORT.background.red, o3DVIEWPORT.background.green, o3DVIEWPORT.background.blue]];
00253     aParams = [o3DVIEWPORT.background];
00254     Renderer.riImager ("background", aTokens, aParams);
00255 }
00256 
00257 // Begin describing the scene
00258 Renderer.riWorldBegin();
00259 
00260 // Render each light
00261 var nCount = Renderer.getLightCount();
00262 // TODO: Check for only Area Light(s) in the scene
00263 // Use the headlamp if there are no lights
00264 if( nCount < 1 )
00265 {
00266     Renderer.createLight( Camera.getHeadlight(), "" );
00267 }
00268 else
00269 {
00270     var sShadow = "";
00271     for( i = 0; i < nCount; i += 1 ){
00272         if( aShadows.length > i )
00273         {
00274             sShadow = aShadows[i];
00275         }
00276         Renderer.createLight( Renderer.getLight(i), sShadow );
00277     }
00278 }
00279 
00280 // Render each node
00281 for( i = 0; i < Renderer.getNodeCount(); i += 1 )
00282 {
00283     Renderer.renderNode( Renderer.getNode( i ) );
00284 }
00285 
00286 // Start rendering; the string argument is shown in the progress dialog
00287 Renderer.riEndWorld( "Rendering: Scripted Render Example..." );
00288 
00289 // Clean up shadows, if desired
00290 //Renderer.deleteFiles( aShadows );
00291 
00292 // OTHER PASSES
00293 /**********************************************************************/
00294 // Add other passes as desired. 
00295 // Passes start with Renderer.riBegin() and end with Renderer.EndWorld();
00296 //..........

Generated on Thu Sep 24 12:21:07 2009

Copyright © 2002 - 2009 DAZ 3D, Inc.