Exemplo n.º 1
0
    public static void RebuildMeshObjectBuffers()
    {
        if (!NeedRebuilding)
        {
            return;
        }
        RayTracingMaster.Rerender();


        _meshObjects.Clear();
        _vertices.Clear();
        _normals.Clear();
        _indices.Clear();
        foreach (var obj in _rayTracingObjects)
        {
            int firstVertex       = _vertices.Count;
            UnityEngine.Mesh mesh = obj.GetComponent <MeshFilter>().mesh;
            _vertices.AddRange(mesh.vertices);
            _normals.AddRange(mesh.normals);
            //注意当前模型的第一个顶点并不是所有模型中的第一个顶点
            int firstIndex = _indices.Count;
            var indices    = mesh.GetIndices(0);
            _indices.AddRange(indices.Select(index => index + firstVertex));
            _meshObjects.Add(new Mesh()
            {
                localToWorldMatrix       = obj.transform.localToWorldMatrix,
                localNormalToWorldMatrix = obj.transform.localToWorldMatrix.inverse.transpose,
                indices_offset           = firstIndex,
                indices_count            = indices.Length
            });
        }
        NeedRebuilding = false;
    }
Exemplo n.º 2
0
 public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
 {
     if (rayTracingMaster == null)
     {
         rayTracingMaster = FindObjectOfType <RayTracingMaster>();
     }
 }
 private void Update()
 {
     if (beforeTransform != this.transform)
     {
         RayTracingMaster.UnregisterObject(this);
         RayTracingMaster.RegisterObject(this);
     }
 }
 private void OnEnable()
 {
     if (RandomMaterial)
     {
         this.SetRandom();
     }
     RayTracingMaster.RegisterObject(this);
 }
Exemplo n.º 5
0
    void Awake()
    {
        if (string.IsNullOrWhiteSpace(objectName))
        {
            objectName = gameObject.name;
        }

        RayTracingMaster.RegisterObject(this);
    }
Exemplo n.º 6
0
 void Update()
 {
     if (transform.hasChanged)
     {
         RayTracingMaster.UpdateObject(transform);
         //print("The transform has changed!");
         transform.hasChanged = false;
     }
 }
Exemplo n.º 7
0
    public void SetSceneData()
    {
        _SceneData = new SceneData();

        _SceneData._MaxRecursionDepth = maxRecursionDepth;

        SetBackgroundColor();
        ParseSceneCameras();
        SetRenderCameraData();
        ParseSceneLights();
        ParseSceneObjects();

        Transform[] cameraTransforms = GameObject.Find("SceneCameras").GetComponentsInChildren <Transform>();
        if (cameraNo <= _SceneData._CameraDatas.Count)
        {
            rayTracingMaster = cameraTransforms[cameraNo].GetComponent <RayTracingMaster>();
        }
    }
Exemplo n.º 8
0
    private void OnEnable()
    {
        //MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
        //CombineInstance[] combine = new CombineInstance[10];

        //int i = 0;
        //while (i < 10)
        //{
        //    combine[i].mesh = meshFilters[i].sharedMesh;
        //    combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
        //    meshFilters[i].gameObject.SetActive(false);

        //    i++;
        //}
        //transform.GetComponent<MeshFilter>().mesh = new Mesh();
        //transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
        //transform.gameObject.SetActive(true);
        RayTracingMaster.RegisterObject(this);
    }
Exemplo n.º 9
0
    public static void SetRandomSpheres(uint SpheresMax, Vector3 SphereRadius, float SpherePlacementRadius)
    {
        RayTracingMaster.Rerender();
        for (int i = 0; i < SpheresMax; i++)
        {
            Sphere sphere = new Sphere();
            sphere.radius = SphereRadius.x + Random.value * (SphereRadius.y - SphereRadius.x);
            //由单位圆内随机映射为所给半径圆内随机
            Vector2 randomPos = Random.insideUnitCircle * SpherePlacementRadius;
            //与y=0平面相切
            sphere.position = new Vector3(randomPos.x, sphere.radius, randomPos.y);
            //判断是否与已生成球重合
            bool isInOther = false;
            foreach (Sphere other in spheres)
            {
                float minDist = sphere.radius + other.radius;
                if (Vector3.SqrMagnitude(sphere.position - other.position) < minDist * minDist)
                {
                    isInOther = true;
                }
            }
            if (isInOther)
            {
                continue;
            }
            //一半几率生成漫反射,一半几率生成镜面反射
            Color color = Random.ColorHSV();
            bool  metal = Random.value < 0.5f;
            sphere.albedo   = metal ? Vector3.zero : new Vector3(color.r, color.g, color.b);
            sphere.specular = metal ? new Vector3(color.r, color.g, color.b) : Vector3.one * 0.04f;
            Color emissioncolor = Random.ColorHSV();

            sphere.emission = (Random.value > 0.85) ?
                              new Vector3(emissioncolor.r, emissioncolor.g, emissioncolor.b) * Random.Range(3, 40)
                : Vector3.zero;
            sphere.smoothness = Random.Range(0.7f, 1.0f);
            sphere.smoothness = SmoothnessToPhongAlpha(sphere.smoothness);
            spheres.Add(sphere);
        }
    }
Exemplo n.º 10
0
 // Awake() and Start() are called only once per object
 // But OnEnable() can be called everytime  the object is enabled either by another
 // script or Unity; So use Awake() for the absolute initialization purpose
 void OnEnable()
 {
     RayTracingMaster.RegisterParaboloidMirror(this);
 }
Exemplo n.º 11
0
 private void OnDisable()
 {
     RayTracingMaster.UnregisterGeoConeMirror(this);
 }
Exemplo n.º 12
0
 private void OnEnable()
 {
     RayTracingMaster.RegisterGeoConeMirror(this);
 }
 private void OnDisable() => RayTracingMaster.UnregisterObject(this);
Exemplo n.º 14
0
 private void OnDisable()
 {
     RayTracingMaster.UnregisterPyramidMirror(this);
 }
Exemplo n.º 15
0
 void OnDisable()
 {
     RayTracingMaster.UnregisterParaboloidMirror(this);
 }
 private void OnEnable()
 {
     m_rtmScript = (RayTracingMaster)target;
 }
Exemplo n.º 17
0
 private void OnEnable()
 {
     RayTracingMaster.RegisterObject(this);
     rayTracingMaster.transformsToWatch.Add(transform);
 }
Exemplo n.º 18
0
 private void OnDisable()
 {
     RayTracingMaster.UnregisterObj(this);
 }
 void OnDisable()
 {
     RayTracingMaster.UnregisterTriangularConeMirror(this);
 }
 void OnEnable()
 {
     RayTracingMaster.RegisterTriangularConeMirror(this);
 }
Exemplo n.º 21
0
 private void OnEnable()
 {
     RayTracingMaster.RegisterPyramidMirror(this);
 }
 private void OnEnable()
 {
     RayTracingMaster.RegisterObject(this);
     beforeTransform = this.transform;
 }
 private void OnEnable()
 {
     RayTracingMaster.RegisterObject(this);
 }
 void OnBecameInvisible()
 {
     RayTracingMaster.UnregisterSphereObject(this);
 }
Exemplo n.º 25
0
    //void OnEnable() {
    //   RayTracingMaster.RegisterObject(this);
    // }

    void OnDisable()
    {
        RayTracingMaster.UnregisterObject(this);
    }
Exemplo n.º 26
0
 void OnDisable()
 {
     RayTracingMaster.UnregisterHemisphereMirror(this);
 }
 // Start is called before the first frame update
 void OnBecameVisible()
 {
     RayTracingMaster.RegisterSphereObject(this);
 }
Exemplo n.º 28
0
 void OnEnable()
 {
     RayTracingMaster.RegisterHemisphereMirror(this);
 }