'
' This example demonstrates how to replace one shader with another one
' on scene objects. It also shows how you can use the scripting
' equivalent of Drag & Drop (CreateShaderFromPreset) which is required
' by the ReplaceShader command.
'
NewScene , false
' Get the default pass
Set oDefPass = GetValue( "Passes.Default_Pass" )
' Create a sphere and apply a default shader to it (since the sphere
' is already selected we don't need to specify it as an input object)
Set oSphere = CreatePrim( "Sphere", "MeshSurface" )
ApplyShader
' Tweak the color values on the sphere's material using the Shader
' parameter shortcuts "diffuse" and "ambient"
Set oPhong = oSphere.Material.Shaders( "Phong" )
oPhong.diffuse.Parameters( "red" ).Value = 0.9
oPhong.diffuse.Parameters( "green" ).Value = 0.5
oPhong.ambient.Parameters( "green" ).Value = 0.7
' View the results in a rendered frame. (You can see the sphere now has the
' default image wrapped around it with a specular highlight)
RenderPasses oDefPass, 1, 1
' Now, replace the Phong shader on the sphere by a Lambert preset shader which
' we access through the CreateShaderFromPreset command (the scripting equivalent
' of Drag & Drop), which handily returns a pointer to the unconnected shader
set oLambert = CreateShaderFromPreset( "Shaders\Material\Lambert.Preset", _
"Sources.Materials.DefaultLib.Material" )
oLambert.diffuse.Parameters( "red" ).Value = 0.9
oLambert.diffuse.Parameters( "green" ).Value = 0.5
oLambert.ambient.Parameters( "green" ).Value = 0.7
ReplaceShader "sphere.Material.Phong", oLambert
' View the results in a rendered frame. (Now the image is still on the sphere,
' but it appears with a matte surface and no specular highlight)
RenderPasses oDefPass, 1, 1 |