## ReplaceShader

### Introduced

v1.0

### Description

Disconnects a shader and connects another shader in its place.
Note: Both parameters are required, and you cannot use a preset path for the Target parameter ("Shaders/Material/Lambert.Preset" does not work), so if you need to specify a shader that has not been introduced to the scene yet, you get it with the CreateShaderFromPreset command, which returns the newly created (but disconnected) Shader object for the Target parameter (see the example for details) or use the ReplaceShaderWithPreset command.

### Scripting Syntax

    ReplaceShader( Source, Target );

### Parameters

Parameter | Type | Description
--- | --- | ---
Source | String | Shaders to disconnect (eg., "sphere.Material.Phong").
Target | String | Shader to connect. Only a shader that is already in the scene is accepted, so if you are using a shader from disk, you need to add it with the CreateShaderFromPreset command first.

### Examples

#### VBScript Example

    '

    ' 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

### See Also

ApplyShader CreateShaderFromPreset ReplaceShaderWithPreset ReplaceShaderWithProgID RemoveShaderFromCnxPoint SIConnectShaderToCnxPoint