Graphics

 View Only
  • 1.  Changing shader on material via script in SceneDirector

    Posted 10-17-2018 01:38
    I have built a billboard like the rotating ones of our childhood. It is built from 18 rotating primitive cubes (doubled to eliminate problems in z space and to ease mapping of material). The opposing faces have a material applied with a base color and a second layer with a shader which holds a sponsor logo. As of right now, I can display a total of 2 logos, one on one side and one on the other after a 180 degree rotation.

    If you are still with me: I want to add a script to the scene director that triggers the rotation of the cubes. This script, placed after the first rotation would change the shader on the material of the face that is now facing away from the "camera". The rotation would continue and the new logo would emerge from the back side. I haven't even begun dealing with aspect ratios of various logos. I will drive off that bridge when I get there. For right now I am content to alter the script but will eventually rely on a text field, or perhaps a dashboard to drive the variable of the logo that will be placed. Hopefully this is simple to someone with many more brain cells that I.


    Thanks in advance.


  • 2.  RE: Changing shader on material via script in SceneDirector

    Posted 10-17-2018 04:26
    Wouldn't it be simpler to just set up some transition logic for this? Have your cubes rotate 90 degrees and at the 90th degree, the new billboard rotates in from -90. A simple back-to-back condition that verifies the scene is the same would make it work and you could just place it in a looping group. Plus you wouldn't have to worry about scripting anything and would have a lot of flexibility in altering timelines of what needs to run when. Don't know if this is the exact function you want, but it makes sense from what you are describing.
    #XPression


  • 3.  RE: Changing shader on material via script in SceneDirector

    Posted 10-17-2018 15:39
    Thanks Drew. I thought that too. But there is a continuous camera move from left to right. Be careful what you show your boss because they will take it one step too far. 2 years ago someone gave me a script that would change the shader material for referee head shots. I have been trying to modify this but no luck so far.
    #XPression


  • 4.  RE: Changing shader on material via script in SceneDirector

    Posted 10-18-2018 14:57

    Hi,

    Little bit complicate for me to understand all you said :)
    But if your target is to change the material of a face of a cube here is a script who can help you :

    dim cube1 as xpBaseObject
    self.getObjectByName("Cube1", cube1)

    dim materialFront as xpmaterial
    engine.getMaterialByName("MyMaterial1", materialFront)

    cube1.setMaterial(0, materialFront)



    ;)

    Some precision...,
    0 = Front , you can change this number to access to the other face
    1=back
    2=left
    3=right
    4=Top
    5=bottom



    if you want to put this script in sceneDirector you must change self by scene


    I hope that is what you expect ;)




    #XPression


  • 5.  RE: Changing shader on material via script in SceneDirector

    Posted 10-18-2018 21:34

    Hello malthepal,

    With your setup, you can change the image attached to the shader with this kind of script :

    dim m as xpMaterial
    dim sh as xpBaseShader
    if Engine.GetMaterialByName("MyMaterial", m) then
    if m.GetShaderByName("Texture", sh) then
    sh.SetFileName(imageFilePath)
    end if
    end if


    where :
    - "MyMaterial" is the name of the material assigned to the cube face (you should have one material for the front face, and another for the back face of your cube)
    - "Texture" is the name of the shader in your material that contains your texture's file
    - imageFilePath is the path and name of your image


    With this method , on my laptop, the rendering hangs for one or two frames when the script is applied.


    With the method described by kml92 he rendering is good (no hanging frame ) .



    See project attached : [ATTACH]n17449[/ATTACH]
    Each two scene use the different methods.
    the project use global methods scripts.

    Regards (and sorry for the ugly logos :P )


    #XPression


  • 6.  RE: Changing shader on material via script in SceneDirector

    Posted 10-19-2018 00:17
    When the rendering hangs for a frame or two; what file format and resolution are the images? JPG's can be very slow to decode, especially large ones.
    TGA files are the quickest to decode and would be the best choice in this situation. (not actually sure if this is the reason or not though, but if you have time to try TGA's let us know).

    #XPression


  • 7.  RE: Changing shader on material via script in SceneDirector

    Posted 10-19-2018 05:40
    it's PNG file with resolution 256*256 pixel .
    They are included in the sample project.
    #XPression


  • 8.  RE: Changing shader on material via script in SceneDirector

    Posted 10-19-2018 15:12
    I want to replace a SHADER on a material. I have a blue bg with a sponsor logo on a different shader. The blue provides the bg for the rotators. I suppose I could just build the logos over the blue in photoshop then just run the script to replace the entire material. I think I will probably go that way.
    #XPression