Unity issues

Home Forums Syphon Syphon Implementations – User Unity issues

Viewing 20 posts - 1 through 20 (of 24 total)
  • Author
    Posts
  • #4495
    SteveElbows
    Participant

    From the readme I am not expecting Unity apps to work with syphon in client mode if they are compiled, but should they be working within the Unity editor?

    I am getting strange behaviour. If I start a Syphon server and load the Example Client scene into Unity 3, and then press play, I can see the moving texture properly in the Unity scene view, but not in the Game view, where I can only see a static frame from Syphon, and I only get that by switching to scene view tab and then back to game tab! Ive tried 3 different syphon servers (sample syphon client app, QC example, QC server within VDMX) with the same result. Ive tried on a Macbook Pro with GeForce 9600M GT and with a 2008 Mac Pro with GTX285 graphics.

    Do you know of any issues with using Unity as a Syphon server? The first things I tried worked pretty well, but Ive now got some scenes which Syphon does not like at all, I need to do some more testing to see if I can work out what is different about these scenes, eg is it some camera setting that Syphon doesnt like, will report back here with more info tomorrow. One of the last scenes I tried I get some output via Syphon, but its not at all the same as the camera I can see and that I attached the script to, it looks like a zoomed & distorted version. Eg there are some red and blue point lights that are moving around the edges of a circular room, and whats coming out via syphon does flicker red and blue as the light move round, but its just a mess. I know this is not useful detail so like I said I will post more tomorrow and will share some sample scenes if it seems necessary/you dont already know of certaain problems/settings in unity that are known to cause issues.

    When I have been doing stuff thats worked Syphon is an absolute joy, cheers, and I will be making a donation soon.

    #4496
    vade
    Keymaster

    There are some issues with Syphon for Unity we are looking at currently. Some of the rendering issues in the server are partially because Unity has various render passes and rendering stages, deferred, back to front and front to back rendering, and depending on lighting render ‘happens’ in different places. Its also a total black box (unless you pay for the source), so that makes it a bit more difficult to deduce the optimal “one size fits all’ solution on where codewise to place servers and clients.

    One of the people who has helped with the Unity Syphon port (Brian Chasalow) is going to the Unity conference inMontreal and will be trying to get some more concrete examples. However last night Brian had some issues and has a new script that might be of use client wise, and ill see if we can get it and a clean sample scene committed to SVN soon.

    Try this out:

    using UnityEngine;
    using System.Collections;
    
     public class makeSyphonClientWork : MonoBehaviour {
     	//ridiculously dumb fix courtesy of brian [at] chasalow [dot] c o m
     	//attach this script to the main camera.
     	//then attach your SyphonClientBridge to whatever objects (plane, etc) you want to receive the texture on.
     	public string infos = "attachToMainCameraPlz!";
    	void Start () {
    	}
    
    	static Material lineMaterial;
    static void CreateLineMaterial() {
        if( !lineMaterial ) {
            lineMaterial = new Material( "Shader "Lines/Colored Blended" {" +
                "SubShader { Pass { " +
                "    Blend SrcAlpha OneMinusSrcAlpha " +
                "    ZWrite Off Cull Off Fog { Mode Off } " +
                "    BindChannels {" +
                "      Bind "vertex", vertex Bind "color", color }" +
                "} } }" );
            lineMaterial.hideFlags = HideFlags.HideAndDontSave;
            lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
        }
    }
    
    void OnPostRender() {
        CreateLineMaterial();
        // set the current material
        lineMaterial.SetPass( 0 );
    	//    GL.Begin( GL.LINES );
        //GL.Color( new Color(1,1,1,0.5f) );
       // GL.Vertex3( 0, 0, 0 );
      //  GL.End();
    } 
    
    }

    As for Server issues, ill see if Brian can chime in, I am admittedly a bit out of my element with the nuances of Unity

    Server wise

    #4497
    Brian Chasalow
    Participant

    Hey there- Brian here. There are definitely still some remaining issues we hope to get ironed out soon. That last script, if you simply attach it to a camera, is a hack that should make builds work on the Unity syphon client side.

    <EDIT: FIXED>However, there are issues where if you say, rotate an object real fast, you might get some texture tearing while Syphon does its thing. As Anton mentioned we’re trying to reach out to Unity to get that sort of issue solved.</EDIT>

    On the unity syphon server side, some remaining issues are focused around alpha channels, due to Unity’s various rendering stages and sometimes Unity not writing the proper alpha channel into the texture. On the Server side, either use a skybox and/or keep your scene’s background color cranked up high regarding the alpha channel value, and in your own Client side, if you can ignore the alpha channel, things tend to work better.
    As another temporary workaround, if you never use transparent/particle shaders, It should ‘just work’, for now.

    #4498
    vade
    Keymaster

    Brian, is the texture tearing a VBL sync issue? Unity has VBL disabled by default.

    #4499
    Brian Chasalow
    Participant

    nah its something else. VBL sync is more uniform than the glitchiness I’m seeing.

    #4500
    Brian Chasalow
    Participant

    Here is an updated script to solve that issue:


    using UnityEngine;
    using System.Collections;

    public class makeSyphonClientWork : MonoBehaviour {
    //ridiculously dumb fix courtesy of brian [at] chasalow [dot] c o m
    //attach this script to the main camera.
    //then attach your SyphonClientBridge to whatever objects (plane, etc) you want to receive the texture on.
    public string infos = "attachToMainCameraPlz!";
    void Start () {
    }

    static Material lineMaterial;
    static void CreateLineMaterial() {
    if( !lineMaterial ) {
    lineMaterial = new Material( "Shader "Lines/Colored Blended" {" +
    "SubShader { Pass { " +
    " Blend SrcAlpha OneMinusSrcAlpha " +
    " ZWrite Off Cull Off Fog { Mode Off } " +
    " BindChannels {" +
    " Bind "vertex", vertex Bind "color", color }" +
    "} } }" );
    lineMaterial.hideFlags = HideFlags.HideAndDontSave;
    lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
    }
    }

    void OnPostRender() {
    CreateLineMaterial();
    lineMaterial.SetPass( 0 );
    }

    void OnRenderObject() {
    CreateLineMaterial();
    lineMaterial.SetPass( 0 );

    }

    }

    #4501
    haye
    Participant

    very nice.
    successfully sending from quartz composer to unity.

    #4502
    SteveElbows
    Participant

    Excellent, thanks very much for the client fix, only had a chance to test it briefly but it seems to do the job nicely 🙂

    Yes Im pretty sure some of my issues with server are alpha-related, will have another go tomorrow and see if I can work out more about what the other issue is.

    #4503
    Brian Chasalow
    Participant

    glad it worked for you- keep me posted with how it goes!
    Brian

    #4504
    SteveElbows
    Participant

    Thanks again, had another play with Client textures in unity today and it was working just great.

    I have started thinking about whether there will be more functionality in future, eg the ability to specify in the scripts which server to listen to, and whether in theory it would then support textures from more than one source at once. Also wondering whether it is at all possible to support shaders that have more than one texture, eg could I send normal maps to unity?

    On the server side of things, Ive stripped down a project that demonstrates the strange distortion I get, you can download the Unity project files here:

    http://www.mutantquartz.com/SyphonServerTestElbows.zip

    Cheers

    #4505
    haye
    Participant

    would be really cool, if you could assign a syphon texture to a projector inside unity, just trying..

    🙂

    #4506
    Brian Chasalow
    Participant

    SteveElbows: that’s definitely on our radar, the multiple server support thing for Unity as client.

    I checked out your demo- those are certainly similar issues to what we’re experiencing. For now, do four things:
    1)go to file/build settings/player settings, and check ‘run in background’
    2) go to edit/render settings, and drag a global skybox there to where it says ‘skybox’ from your project window.
    3) replace the SyphonServerBridge with this script:

    using UnityEngine;
    using System.Collections;
    using System.Runtime.InteropServices;

    public class SyphonServerBridge : MonoBehaviour {

    //1)go to file/build settings/player settings, and check 'run in background'
    //2) go to edit/render settings, and drag a global skybox there to where it says 'skybox' from your project window.

    private GameObject _RTCameraObject;
    private Camera _RTCamera;
    private RenderTexture _rTexture = null;
    public int desiredWidth = 1024;
    public int desiredHeight = 768;
    [DllImport ("SyphonUnityPlugin")]
    private static extern void syphonServerPublishTexture(int nativeTexture, int width, int height);
    [DllImport ("SyphonUnityPlugin")]
    private static extern void syphonServerDestroyResources();

    // Use this for initialization
    void Start ()
    {
    _rTexture = new RenderTexture(desiredWidth, desiredHeight, 24);
    _rTexture.format = RenderTextureFormat.ARGB32;
    _rTexture.isPowerOfTwo = false;
    _rTexture.isCubemap = false;
    _rTexture.Create();
    //create a new render texture camera object, parent it to this object
    _RTCameraObject = new GameObject();
    _RTCameraObject.transform.parent = transform;
    _RTCameraObject.name = "RTCamera";
    _RTCameraObject.AddComponent("Camera");
    _RTCameraObject.AddComponent("makeSyphonServerWork");
    //clone the current camera's settings to the RT Camera
    _RTCameraObject.camera.CopyFrom(camera);
    //add the render texture target to the RTCamera object
    _RTCameraObject.camera.targetTexture = _rTexture;
    //<edit nov 7 2010 - bc>
    RenderTexture.active = _rTexture;
    //</edit>
    }
    public void callFromRTCamera(){
    syphonServerPublishTexture(_rTexture.GetNativeTextureID(), _rTexture.width, _rTexture.height);
    }
    // Also called in the editor when play is stopped
    void OnApplicationQuit ()
    {
    syphonServerDestroyResources();
    }

    }

    4) then create a new file, call it makeSyphonServerWork.cs, and write this to it:


    using UnityEngine;
    using System.Collections;

    public class makeSyphonServerWork : MonoBehaviour {
    private SyphonServerBridge myScript;
    // Use this for initialization
    void Start () {
    myScript = transform.parent.GetComponent<SyphonServerBridge>();
    }
    static Material lineMaterial;
    static void CreateLineMaterial() {
    if( !lineMaterial ) {
    lineMaterial = new Material( "Shader "Lines/Colored Blended" {" +
    "SubShader { Pass { " +
    " Blend SrcAlpha OneMinusSrcAlpha " +
    " ZWrite Off Cull Off Fog { Mode Off } " +
    " BindChannels {" +
    " Bind "vertex", vertex Bind "color", color }" +
    "} } }" );
    lineMaterial.hideFlags = HideFlags.HideAndDontSave;
    lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
    }
    }
    void OnPostRender() {
    CreateLineMaterial();
    lineMaterial.SetPass( 0 );
    }
    void OnRenderObject() {
    CreateLineMaterial();
    lineMaterial.SetPass( 0 );
    myScript.callFromRTCamera();

    }

    }

    #4507
    Brian Chasalow
    Participant

    just as another note-using these 2 scripts appears to allow you to use unity as a syphon server WITH transparent shaders on your objects, as long as you have a skybox, and as long as you’re ignoring alpha channels in your client.

    It was definitely unhappy when trying to combine server + client re-routing in and out, though…

    #4508
    SteveElbows
    Participant

    Cheers for the server fixes, had a little go and all seems to be working now, think most of my issues were to do with a lack of skybox. Using a cube skybox with black tint and alpha turned down should probably do the job for a lot my scenarios.

    The updated scripts you posted caused me a few script error problems, perhaps because my camera is not a child of anything, but by attaching the makeSyphonServerWork script to an empty game object that is a child of the camera I get rid of the errors.

    #4509
    SteveElbows
    Participant

    Actually scratch what I just said – I just figured out that I wasnt supposed to be attaching the server fix script to anything.

    However with my test composition and the updated scripts Im not getting proper output, I get the background/skybox coming through Syphon but my model isnt shown. When it worked I was using a skybox with the older script, will do some more investigation as it could be something stupid Im doing?

    #4510
    SteveElbows
    Participant

    OK ignore me, my latest problem with the new scripts was nothing to do with the scripts, it was my bad idea to use Skybox Cubed. I was tired when messing with this stuff yesterday and thought that skybox cubed was working better if I just wanted to alpha-out the background, but I was totally wrong and skybox cubed shader breaks syphon server (or at least it does when used with no texture in the skybox, havent tried with).

    #4511
    pymenvert
    Participant

    Hello all.

    Thank you for this amazing software.

    I’m getting strange crash when I build and run in web player.

    1)I downloaded “ExempleScene” project.
    2)Add “makeSyphonServerWork.cs” on the plugins folders.
    3)Edited “SyphonServerBridge” like briangibson’s explain.
    4)Edited “SyphonClientBridge” like r.38 (10/01/2011 syphon implementations)
    4)go to file/build settings/player settings, and check ‘run in background’
    5)go to edit/render settings, and drag a global skybox there to where it says ‘skybox’ from your project window.

    I put “SyphonClientBridge” in the Plane and “SyphonServerBridge” in Main Camera.

    But when I build and run, it doesn’t work.
    Web player run and crash.

    I have try lot of configuration but no way…
    I don’t know where is my error.

    If anyone ca be help me or explain me how can I do for working Syphon Server with Unity, it would be fantastic…

    Thank you in advance

    #4512
    Brian Chasalow
    Participant

    hey there. please see the google code implementation site as it has an updated version that does not require any of the ‘makesyphonclientwork’ band-aid fixes.
    there are a few more updates i need to commit but I am out of town on a job right now, will get to it when i get back. cheers,
    brian

    #4513
    pymenvert
    Participant

    thanks for your response,

    Now, I have the last version of implementation and Syphon Framework.
    Syphon is working correctly with Unity.

    But web player continue to getting strange crash when I build and run…
    Actually, I have to use the QC’s output.
    Is it normal ?

    Is it possible to use the output of Unity ? (standalone or web player)

    #4514
    Brian Chasalow
    Participant

    you cannot use the web player. try standalone osx build.
    you should be seeing unity as a server after you build/run.

Viewing 20 posts - 1 through 20 (of 24 total)
  • You must be logged in to reply to this topic.