Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 476 characters in body
Source Link
user29244
  • 327
  • 2
  • 12

I rendered some UV unwrapped raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

world normal output

  • Left is a vanilla unlit shader modified to output the world normal from the game objects, normals align to the unity basis show in the upper right corner.
  • Right is the target complex shader that use raw mesh with custom matrix, uv unwrap rendered to texture and read back as texture on the gameobject by another shader (the working is out of scope, context is roughly lightmap as a G buffer)

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have faulty matrix. Therefore, I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate further, as I suspect that raw mesh is the imported data before Unity applies its import settings, I created a little program that I attached to the game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshVsObjectNormalTest : MonoBehaviour
{
    //public GameObject normalObject;
    Mesh[] rawMesh;
    Matrix4x4 objectMatrix;
    Camera cam;
    Material mat;

    // Start is called before the first frame update
    void Start()
    {
        rawMesh = new Mesh[1];
        rawMesh[0] = this.GetComponent<MeshFilter>().mesh;
        objectMatrix = Matrix4x4.identity;
        cam = Camera.main;
        mat = this.GetComponent<Renderer>().material;
        
    }

    // Update is called once per frame
    //void Update()
    void LateUpdate()
    //void OnPostRender()
    {
        //Graphics.DrawMesh(rawMesh[0], objectMatrix, mat,0, cam);
        //Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0, cam);
        Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0);
        
        //mat.SetPass(0);
        //Graphics.DrawMeshNow(rawMesh[0], objectMatrix);
        
        Debug.Log(cam);
    }
    
}

Nothing shows up, but it's how every example I can find when I search does it, and I'm already using that command successfully to render to texture ...

nothing shows up

Is there something I'm missing?

I rendered some UV unwrapped raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have faulty matrix. Therefore, I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate further, as I suspect that raw mesh is the imported data before Unity applies its import settings, I created a little program that I attached to the game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshVsObjectNormalTest : MonoBehaviour
{
    //public GameObject normalObject;
    Mesh[] rawMesh;
    Matrix4x4 objectMatrix;
    Camera cam;
    Material mat;

    // Start is called before the first frame update
    void Start()
    {
        rawMesh = new Mesh[1];
        rawMesh[0] = this.GetComponent<MeshFilter>().mesh;
        objectMatrix = Matrix4x4.identity;
        cam = Camera.main;
        mat = this.GetComponent<Renderer>().material;
        
    }

    // Update is called once per frame
    //void Update()
    void LateUpdate()
    //void OnPostRender()
    {
        //Graphics.DrawMesh(rawMesh[0], objectMatrix, mat,0, cam);
        //Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0, cam);
        Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0);
        
        //mat.SetPass(0);
        //Graphics.DrawMeshNow(rawMesh[0], objectMatrix);
        
        Debug.Log(cam);
    }
    
}

Nothing shows up, but it's how every example I can find when I search does it, and I'm already using that command successfully to render to texture ...

nothing shows up

Is there something I'm missing?

I rendered some UV unwrapped raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

world normal output

  • Left is a vanilla unlit shader modified to output the world normal from the game objects, normals align to the unity basis show in the upper right corner.
  • Right is the target complex shader that use raw mesh with custom matrix, uv unwrap rendered to texture and read back as texture on the gameobject by another shader (the working is out of scope, context is roughly lightmap as a G buffer)

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have faulty matrix. Therefore, I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate further, as I suspect that raw mesh is the imported data before Unity applies its import settings, I created a little program that I attached to the game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshVsObjectNormalTest : MonoBehaviour
{
    //public GameObject normalObject;
    Mesh[] rawMesh;
    Matrix4x4 objectMatrix;
    Camera cam;
    Material mat;

    // Start is called before the first frame update
    void Start()
    {
        rawMesh = new Mesh[1];
        rawMesh[0] = this.GetComponent<MeshFilter>().mesh;
        objectMatrix = Matrix4x4.identity;
        cam = Camera.main;
        mat = this.GetComponent<Renderer>().material;
        
    }

    // Update is called once per frame
    //void Update()
    void LateUpdate()
    //void OnPostRender()
    {
        //Graphics.DrawMesh(rawMesh[0], objectMatrix, mat,0, cam);
        //Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0, cam);
        Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0);
        
        //mat.SetPass(0);
        //Graphics.DrawMeshNow(rawMesh[0], objectMatrix);
        
        Debug.Log(cam);
    }
    
}

Nothing shows up, but it's how every example I can find when I search does it, and I'm already using that command successfully to render to texture ...

nothing shows up

Is there something I'm missing?

added 79 characters in body
Source Link
user29244
  • 327
  • 2
  • 12

I rendered some UV unwrapped raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have faulty matrix. Therefore, I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate further, as I suspect that raw mesh is the imported data before Unity applies its import settings, I created a little program that I attached to the game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshVsObjectNormalTest : MonoBehaviour
{
    //public GameObject normalObject;
    Mesh[] rawMesh;
    Matrix4x4 objectMatrix;
    Camera cam;
    Material mat;

    // Start is called before the first frame update
    void Start()
    {
        rawMesh = new Mesh[1];
        rawMesh[0] = this.GetComponent<MeshFilter>().mesh;
        objectMatrix = Matrix4x4.identity;
        cam = Camera.main;
        mat = this.GetComponent<Renderer>().material;
        
    }

    // Update is called once per frame
    //void Update()
    void LateUpdate()
    //void OnPostRender()
    {
        //Graphics.DrawMesh(rawMesh[0], objectMatrix, mat,0, cam);
        //Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0, cam);
        Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0);
        
        //mat.SetPass(0);
        //Graphics.DrawMeshNow(rawMesh[0], objectMatrix);
        
        Debug.Log(cam);
    }
    
}

Nothing shows up, but it's how every example I can find when I search does it, and I'm already using that command successfully to render to texture ...

nothing shows up

Is there something I'm missing?

I rendered some UV unwrapped raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have faulty matrix. Therefore, I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate further, as I suspect that raw mesh is the imported data before Unity applies its import settings, I created a little program that I attached to the game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshVsObjectNormalTest : MonoBehaviour
{
    //public GameObject normalObject;
    Mesh[] rawMesh;
    Matrix4x4 objectMatrix;
    Camera cam;
    Material mat;

    // Start is called before the first frame update
    void Start()
    {
        rawMesh = new Mesh[1];
        rawMesh[0] = this.GetComponent<MeshFilter>().mesh;
        objectMatrix = Matrix4x4.identity;
        cam = Camera.main;
        mat = this.GetComponent<Renderer>().material;
        
    }

    // Update is called once per frame
    //void Update()
    void LateUpdate()
    //void OnPostRender()
    {
        //Graphics.DrawMesh(rawMesh[0], objectMatrix, mat,0, cam);
        //Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0, cam);
        Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0);
        
        //mat.SetPass(0);
        //Graphics.DrawMeshNow(rawMesh[0], objectMatrix);
        
        Debug.Log(cam);
    }
    
}

Nothing shows up, but it's how every example I can find when I search does it, and I'm already using that command successfully to render to texture ...

Is there something I'm missing?

I rendered some UV unwrapped raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have faulty matrix. Therefore, I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate further, as I suspect that raw mesh is the imported data before Unity applies its import settings, I created a little program that I attached to the game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeshVsObjectNormalTest : MonoBehaviour
{
    //public GameObject normalObject;
    Mesh[] rawMesh;
    Matrix4x4 objectMatrix;
    Camera cam;
    Material mat;

    // Start is called before the first frame update
    void Start()
    {
        rawMesh = new Mesh[1];
        rawMesh[0] = this.GetComponent<MeshFilter>().mesh;
        objectMatrix = Matrix4x4.identity;
        cam = Camera.main;
        mat = this.GetComponent<Renderer>().material;
        
    }

    // Update is called once per frame
    //void Update()
    void LateUpdate()
    //void OnPostRender()
    {
        //Graphics.DrawMesh(rawMesh[0], objectMatrix, mat,0, cam);
        //Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0, cam);
        Graphics.DrawMesh(rawMesh[0], Vector3.zero, Quaternion.identity, mat,0);
        
        //mat.SetPass(0);
        //Graphics.DrawMeshNow(rawMesh[0], objectMatrix);
        
        Debug.Log(cam);
    }
    
}

Nothing shows up, but it's how every example I can find when I search does it, and I'm already using that command successfully to render to texture ...

nothing shows up

Is there something I'm missing?

Cleanup
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

DrawMesh() not working as intended in unityUnity

So i have been makingI rendered some UV unwrapped raw mesh data using a little experiment that have me butt head with unity's workingspecial shader, abdand Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have no idea what's going onfaulty matrix. Therefore, soI tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate I started another experiment that isn't working as intendedfurther, as I suspect that raw mesh is not at allthe imported data before Unity applies its import settings, and I'm at lossI created a little program that I attached to know whythe game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

  • I rendered UV unwrap raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).
  • It seems to make sense since I'm bypassing the gameobject construct of unity, therefore I have faulty matrix. Therefore I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix don't seems to do the trick (the standard stuff to transform normal) ...
  • To investigate further, as I suspect that rawmesh is the imported data before unity apply import settings, I create a little program that I attached to the gameobject to compare its render to various DrawMesh() command ... BUT drawmesh don't work as intended ...

Nothing shows up, but it's how every example code do itI can find when I googlesearch does it, and I'm already using that command successfully forto render to texture ...

DrawMesh() not working as intended in unity

So i have been making a little experiment that have me butt head with unity's working, abd I have no idea what's going on, so to investigate I started another experiment that isn't working as intended, that is not at all, and I'm at loss to know why.

  • I rendered UV unwrap raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).
  • It seems to make sense since I'm bypassing the gameobject construct of unity, therefore I have faulty matrix. Therefore I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix don't seems to do the trick (the standard stuff to transform normal) ...
  • To investigate further, as I suspect that rawmesh is the imported data before unity apply import settings, I create a little program that I attached to the gameobject to compare its render to various DrawMesh() command ... BUT drawmesh don't work as intended ...

Nothing shows up, but it's how every example code do it when I google, and I'm already using that command successfully for render to texture ...

DrawMesh() not working as intended in Unity

I rendered some UV unwrapped raw mesh data using a special shader, and Graphics.DrawMesh() to a render texture, but upon inspection the data is wrong (world normal and position).

It seems to make sense since I'm bypassing the gameobject construct of Unity, therefore I have faulty matrix. Therefore, I tried passing my own matrix. But the worldnormal data don't seem to match, and doing the inverse of the transpose of my own matrix doesn't seem to do the trick (the standard stuff to transform normal) ...

To investigate further, as I suspect that raw mesh is the imported data before Unity applies its import settings, I created a little program that I attached to the game object to compare its render to various DrawMesh() commands ... but DrawMesh doesn't work as intended ...

Nothing shows up, but it's how every example I can find when I search does it, and I'm already using that command successfully to render to texture ...

Source Link
user29244
  • 327
  • 2
  • 12
Loading