Results 1 to 3 of 3

Thread: replace shader via geometry shader

  1. #1
    Join Date
    May 2011
    Posts
    23

    Default replace shader via geometry shader

    Hi
    I'll try to be as clear as possible because this is not a common situation...
    In my geo shader i replace a material->shader (A) with a custom one (B) able to emulate the first (A), leaving untouched the material result in this way:
    1) find the material where I will change the material->shader(A)
    2) define a new shader(B) and fill all its attributes by re-linking or getting values from shader(A) attributes, also connected attributes
    3) assign shader (B) to material->shader.

    Shadow, photon or displacement shader in the material remain unchanged during the process, I don't need to replace them.
    Point 2 works for both connected and unconnected attributes and I have no problems on single frame render.

    The problem comes up on sequence, because frame 2 starts with shader(B) already assigned to material and no replacement occurs.
    Mental ray after maya translation doesn't recognize as connection a link from a shader input to another shader input and just solves it by setting the shader(X) color value to shader(A) color value. Since shader(A) does not exist in frame 2 I lose the value that remains the same as first frame.

    Is there a way to force the replacement for every frame (maya should forget the replacement done in prevoius frame). I just need to set all shader(B) attribtes properly by getting them from (A) for all frames.

    Thanks
    Last edited by maradona; July 28th, 2013 at 20:59.

  2. #2
    Join Date
    May 2011
    Posts
    23

    Default

    I tried to do an other test with puppet shader_replacer and the result is still wrong.

    I have a simple cube in the scene with assigned a shader(A). A different shader(B) assigned to the geometry shader to replace (A). Everything works but if shader (B) have different diffuse value in the sequence, this information is lost. Maya and mental ray for maya replace the shader properly in first frame, and when frame two starts the diffuse change on shader (B) is lost and not passed to incremental.
    Otherwise, If i assign the (B) shader to the cube and delete the geometry shader, maya is able to see the diffuse change in all frames...

    Why?? During the first frame translation mental ray for maya see the geometry shader and its incremental, so the shader(B) is exported because linked to the geometry shader and the replacement works. At frame 2 the translation doesn't see the change on diffuse shader. The reason may be that changes are considered on assigned shader only, or that the shader(B) is already assigned in first frame. but in this case maya should see the change of diffuse...

    This is the export to MI file from maya. As you can see the first frame is translated properly, frame 2 and 3 have a single incremental to change camera

    Code:
    # Mayatomr 2012.0m
    # Maya 2012 x64
    
    
    
    min version "3.9"
    link "AdskShaderSDK.dll"
    link "MayaShaders.dll"
    link "mayabase.dll"
    link "shaders_p.dll"
    $include "AdskShaderSDK.mi"
    $include "MayaShaders.mi"
    $include "mayabase.mi"
    $include <shaders_p.mi>
    
    options "miDefaultOptions"
        object space
    	
    	....cut....
    	
        "maya shadow limit" 2
        state [
    	"maya_state" (
    	    )
    	,
    	"adskFrameBufferState" (
    	    )
    	]
    end options
    
    light "defaultLightShape"
        "adskMayaDirectionalLight" (
    	
    	....cut....
    	
    	)
        direction 0. 0. -1.
    end light
    
    instance "defaultLight" "defaultLightShape"
    	
    	....cut....
    	
    end instance
    
    shader "shaderGlow1:perspShape"
        "maya_shaderglow" (
    	
    	....cut....
    	
    	)
    
    shader "volumeEngine1"
        "adskMayaVolumeEngine" (
    	)
    
    data "perspShape:fbdata"
        "adskFrameBufferData" (
    	"magic" 1178760550,
    	"nonMaterialPassFrameBufferNames" [],
    	"frameBufferInfo" [],
    	"frameBufferTypeCounts" [
    	    0,
    	    0,
    	
    	....cut....
    	
    	    0,
    	    0
    	    ]
    	)
    
    camera "perspShape"
    	
    	....cut....
    	
    end camera
    
    instance "persp" "perspShape"
    	
    	....cut....
    	
    end instance
    
    data "pCubeShape1:vxdata"
        "maya_vertexdata" (
    	
    	....cut....
    	
    	)
    
    shader "lambert1"
    	
    	....cut....
    	
    	)
    
    shader "lambert1:shadow"
        "adskMayaFastShadow" (
    	)
    
    material "initialShadingGroup"
    	"adskMayaShadingEngine" (
    	    "surfaceShader" = "lambert1.outColor",
    	    "cutAwayOpacity" 0.,
    	    "customShader" off
    	    )
        shadow = "lambert1:shadow"
    end material
    
    shader "p_shader_replacer1"
        "p_shader_replacer" (
    	)
    
    instance "pCube1"
        geometry = "p_shader_replacer1"
        light "exclusive" []
        material ["initialShadingGroup"]
        caustic on
        caustic 3
        globillum on
        globillum 3
        transform
    	1. -0. 0. -0.
    	-0. 1. -0. 0.
    	0. -0. 1. -0.
    	-0. -2.78525 -0. 1.
    end instance
    
    data "pCubeShape2:vxdata"
        "maya_vertexdata" (
    	"magic" 1298749048,
    	"uvs" [{
    		"name" "map1",
    		"type" 2,
    		"size" 3,
    		"offset" 0
    		}
    	    ]
    	)
    
    shader "lambert2"
        "adskMayaLambert" (
    	"color" 1. 0. 0.,
    	"refractionLimit" 6,
    	"refractiveIndex" 1.,
    	"refractions" off,
    	"diffuse" 0.8,
    	"ambientColor" 0. 0. 0.,
    	"transparency" 0. 0. 0.,
    	"incandescence" 0. 0. 0.,
    	"translucence" 0.,
    	"translucenceFocus" 0.5,
    	"translucenceDepth" 0.5,
    	"opacityGain" 0.,
    	"glowIntensity" 0.,
    	"hideSource" off,
    	"surfaceThickness" 0.,
    	"shadowAttenuation" 0.5,
    	"transparencyDepth" 0.,
    	"lightAbsorbance" 0.,
    	"chromaticAberration" off,
    	"normalCamera" 1. 1. 1.,
    	"irradiance" 0. 0. 0.,
    	"irradianceColor" 1. 1. 1.,
    	"refractionBlur" 0.,
    	"refractionBlurLimit" 1,
    	"refractionRays" 1,
    	"scatterColor" 0.5 0.5 0.5,
    	"scatterRadius" 0.,
    	"scatterAccuracy" 97,
    	"scatterFalloff" 0,
    	"scatterLimit" 1,
    	"scatterCache" 0,
    	"matteOpacityMode" 2,
    	"matteOpacity" 1.,
    	"FrameBufferWriteOperation" 1,
    	"FrameBufferWriteFlags" 0,
    	"FrameBufferWriteFactor" 1.
    	)
    
    shader "lambert2:shadow"
        "adskMayaFastShadow" (
    	)
    
    material "lambert2SG"
    	"adskMayaShadingEngine" (
    	    "surfaceShader" = "lambert2.outColor",
    	    "cutAwayOpacity" 0.,
    	    "customShader" off
    	    )
        shadow = "lambert2:shadow"
    end material
    
    object "pCubeShape2"
        visible on
        shadow 3
    	
    	....cut....
    	
    	]
        end trilist
    end object
    
    instance "pCube2" "pCubeShape2"
        light "exclusive" []
        material ["lambert2SG"]
        caustic on
        caustic 3
        globillum on
        globillum 3
    end instance
    
    instgroup ":MayaTranslatedWorld"
        "defaultLight"
        "pCube1"
        "pCube2"
        "persp"
    end instgroup
    
    shader "lambert3"
        "adskMayaLambert" (
    	"color" 0. 0. 1.,
    	"refractionLimit" 6,
    	"refractiveIndex" 1.,
    	"refractions" off,
    	"diffuse" 0.1,
    	"ambientColor" 0. 0. 0.,
    	"transparency" 0. 0. 0.,
    	"incandescence" 0. 0. 0.,
    	"translucence" 0.,
    	"translucenceFocus" 0.5,
    	"translucenceDepth" 0.5,
    	"opacityGain" 0.,
    	"glowIntensity" 0.,
    	"hideSource" off,
    	"surfaceThickness" 0.,
    	"shadowAttenuation" 0.5,
    	"transparencyDepth" 0.,
    	"lightAbsorbance" 0.,
    	"chromaticAberration" off,
    	"normalCamera" 1. 1. 1.,
    	"irradiance" 0. 0. 0.,
    	"irradianceColor" 1. 1. 1.,
    	"refractionBlur" 0.,
    	"refractionBlurLimit" 1,
    	"refractionRays" 1,
    	"scatterColor" 0.5 0.5 0.5,
    	"scatterRadius" 0.,
    	"scatterAccuracy" 97,
    	"scatterFalloff" 0,
    	"scatterLimit" 1,
    	"scatterCache" 0,
    	"matteOpacityMode" 2,
    	"matteOpacity" 1.,
    	"FrameBufferWriteOperation" 1,
    	"FrameBufferWriteFlags" 0,
    	"FrameBufferWriteFactor" 1.
    	)
    
    shader "lambert3:shadow"
        "adskMayaFastShadow" (
    	)
    
    material "lambert3SG"
    	"adskMayaShadingEngine" (
    	    "surfaceShader" = "lambert3.outColor",
    	    "cutAwayOpacity" 0.,
    	    "customShader" off
    	    )
        shadow = "lambert3:shadow"
    end material
    
    incremental shader "p_shader_replacer1"
        "p_shader_replacer" (
    	"enable" on,
    	"verbose" on,
    	"material" "lambert3SG",
    	"object" []
    	)
    
    incremental shader "volumeEngine1"
        "adskMayaVolumeEngine" (
    	"instances" []
    	)
    
    render ":MayaTranslatedWorld" "persp" "miDefaultOptions"
    
    incremental camera "perspShape"
        data "perspShape:fbdata"
        framebuffer "mayaGlow"
    	datatype "rgba"
    	filtering on
    	user on
        output = "shaderGlow1:perspShape"
        framebuffer "mayaColor"
    	datatype "rgba"
    	filtering on
    	primary on
    	filetype "iff"
    	compression "none"
    	filename "images/testReplace/testReplace.0002.iff"
        resolution 1920 1080
        aspect 1.7777
        aperture 1.41732
        frame 2 2.
        clip 0.1 10000.
        focal 1.37795
        volume = "volumeEngine1"
    end camera
    
    render ":MayaTranslatedWorld" "persp" "miDefaultOptions"
    
    incremental camera "perspShape"
        data "perspShape:fbdata"
        framebuffer "mayaGlow"
    	datatype "rgba"
    	filtering on
    	user on
        output = "shaderGlow1:perspShape"
        framebuffer "mayaColor"
    	datatype "rgba"
    	filtering on
    	primary on
    	filetype "iff"
    	compression "none"
    	filename "images/testReplace/testReplace.0003.iff"
        resolution 1920 1080
        aspect 1.7777
        aperture 1.41732
        frame 3 3.
        clip 0.1 10000.
        focal 1.37795
        volume = "volumeEngine1"
    end camera
    
    render ":MayaTranslatedWorld" "persp" "miDefaultOptions"

    EDIT: yes the problem is exactly that maya consider only "assigned" shader for incremental and not "assigned after geometry shader". So a change in unassigned shader is lost. I tried to force the export of shader(B) by connect its output the shader(A) and in this way maya read the change and export it properly.
    For what I need in post #1, I might create a dummy link from the shader(A) to (B) during the (B) creation in geometry shader to force the export of (A)... not elegant. is there a way to force the export of unused shader without link them to an instance or geometry shader directly? marking them as dirty?

    Suggestions?
    Last edited by maradona; July 29th, 2013 at 16:16.

  3. #3
    Join Date
    May 2011
    Posts
    23

    Default

    Solved.

    The problem was that I deleted the shader(A) from the material->shader before add the new one (B) causing the elimination from the DB.

    There is a way to list all materials or tags from the database? like a "ls" maya command? Now I start from the main instgroup and then getting a query from each instance(inst->material). But in this way I can not find an unassigned material that still exist in the database. I don't know its name to use one of the common mi_api calls, just the main instgroup...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •