Пример #1
0
    /// <summary>
    /// Set the Shader parameters into the ray tracer.
    /// </summary>
    void SetShaderParams()
    {
        // Set the maximum count of ray bounces.
        RayTracerShader.SetInt("_MaxBounceCount", MaxBounceCount);
        // Set the pixel offset for screen uv.
        RayTracerShader.SetVector("_PixelOffset", new Vector2(UnityEngine.Random.value, UnityEngine.Random.value));
        // Set the skybox texture.
        // Set the projector texture.
        RayTracerShader.SetTexture(RTshaderKernelIndex, "_ProjectorTexture", ProjectorTexture);
        // Set the Camera to the World matrix.
        RayTracerShader.SetMatrix("_CameraToWorldSpace", MainCamRef.cameraToWorldMatrix);
        // Set the inversed projection matrix.
        RayTracerShader.SetMatrix("_CameraInverseProjection", MainCamRef.projectionMatrix.inverse);

        //RayTracerShader.SetMatrix("_DisplayCameraTRS", DisplayCamera.cameraToWorldMatrix);

        RayTracerShader.SetFloat("_FOV", Mathf.Deg2Rad * MainCamRef.fieldOfView);
        // Set the light attributes.
        //var light_dir = DirLight.transform.forward;
        //RTshader.SetVector("_DirectionalLight",
        //                   new Vector4(light_dir.x, light_dir.y, light_dir.z, DirLight.intensity));

        // Set the mesh objects attributes compute buffers.
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_MeshObjects", computeShaderHelper.MeshObjectsAttrsComputeBuf);
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_Vertices", computeShaderHelper.VerticesComputeBuf);
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_Indices", computeShaderHelper.IndicesComputeBuf);
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_UVs", computeShaderHelper.UVsComputeBuf);

        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_ProjMeshObjects", computeShaderHelper.ProjMeshObjectComputeBuf);
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_ProjVertices", computeShaderHelper.ProjVerticesComputeBuf);
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_ProjIndices", computeShaderHelper.ProjIndicesComputeBuf);
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_ProjUVs", computeShaderHelper.ProjUVsComputeBuf);

        #region Check the projected uv has correct values

        //computeShaderHelper.ProjVerticesComputeBuf.GetData(computeShaderHelper.Dbg_ProjVertices);
        //var res1 = computeShaderHelper.Dbg_ProjVertices;
        //for (int i = 0; i < res1.Length; ++i) {
        //  Debug.Log($"{res1[i]}");
        //}

        //computeShaderHelper.ProjIndicesComputeBuf.GetData(computeShaderHelper.Dbg_ProjIndices);
        //var res1 = computeShaderHelper.Dbg_ProjIndices;
        //for (int i = 0; i < res1.Length; ++i) {
        //  Debug.Log($"{res1[i]}");
        //}

        //computeShaderHelper.ProjUVsComputeBuf.GetData(computeShaderHelper.Dbg_ProjUVs);
        //var res1 = computeShaderHelper.Dbg_ProjUVs;
        //for (int i = 0; i < res1.Length; ++i) {
        //  Debug.Log($"{res1[i]}");
        //}

        //RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_Dbg_QuadUVs", computeShaderHelper.Dbg_ProjectorUVBuf);
        //computeShaderHelper.Dbg_ProjectorUVBuf.GetData(computeShaderHelper.Dbg_ProjectorUVResult);
        //var res = computeShaderHelper.Dbg_ProjectorUVResult;
        //for (int i = 0; i < res.Length; ++i) {
        //  Debug.Log($"{res[i]}");
        //}

        //RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_Dbg_QuadUVs", computeShaderHelper.Dbg_ProjectorUVBuf);
        //computeShaderHelper.Dbg_ProjectorUVBuf.GetData(computeShaderHelper.Dbg_ProjectorUVResult);
        //var res = computeShaderHelper.Dbg_ProjectorUVResult;
        //for (int i = 0; i < res.Length; ++i) {
        //  Debug.Log($"{res[i]}");
        //}
        #endregion
    }
Пример #2
0
    /// <summary>
    /// Set the Shader parameters into the ray tracer.
    /// </summary>
    void SetShaderParams()
    {
        // Set the maximum count of ray bounces.
        RayTracerShader.SetInt("_MaxBounceCount", MaxBounceCount);
        // Set the pixel offset for screen uv.
        RayTracerShader.SetVector("_PixelOffset", new Vector2(UnityEngine.Random.value, UnityEngine.Random.value));
        // Set the room texture.
        RayTracerShader.SetTexture(RTshaderKernelIndex, "_PrewarpingTexture", PrewarpingTexture);
        // Set the Camera to the World matrix.
        RayTracerShader.SetMatrix("_CameraToWorldSpace", MainCamRef.cameraToWorldMatrix);
        // Set the inversed projection matrix.
        RayTracerShader.SetMatrix("_CameraInverseProjection", MainCamRef.projectionMatrix.inverse);

        //RayTracerShader.SetFloat("_FOV", Mathf.Deg2Rad * MainCamRef.fieldOfView);
        // Set the light attributes.


        //RayTracerShader.SetTexture(RTshaderKernelIndex, "_SkyboxTexture", SkyboxTexture);
        // Set the sphere attributes compute buffers.
        // RTcomputeShaderHelper.SetComputeBuffer(ref RTshader, "_Spheres", sphereLocator.SpheresComputeBuf);

        // Set the mesh objects attributes compute buffers.
        RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_MeshObjects", computeShaderHelper.MeshObjectsAttrsComputeBuf);

        // if there's vertices, set the vertices and the indices compute buffers.
        if (computeShaderHelper.VerticesList.Count > 0)
        {
            RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_Vertices", computeShaderHelper.VerticesComputeBuf);
            RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_Indices", computeShaderHelper.IndicesComputeBuf);
            RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_UVs", computeShaderHelper.UVsComputeBuf);
        }

        // if there's vertex color applied, set the vertex color compute buffers.
        //if (computeShaderHelper.VtxColorsList.Count > 0) {
        //  RTcomputeShaderHelper.SetComputeBuffer(ref RTshader, "_VertexColors", computeShaderHelper.VtxColorsComputeBuf);
        //}

        // if there's texture color applied, set the texture color compute buffers.
        //if (computeShaderHelper.UVsList.Count > 0) {
        //  RTcomputeShaderHelper.SetComputeBuffer(ref RTshader, "_TextureColors", computeShaderHelper.TextureColorsComputeBuf);
        //}

        #region
        // 광선 투사시에 -z, +z 가 같은 값인지 확인 (방향이 제대로 진행되나)
        //RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_DirTex1", computeShaderHelper.Dbg_DirectionTexture1Buf);
        //computeShaderHelper.Dbg_DirectionTexture1Buf.GetData(computeShaderHelper.Dbg_DirectionTexture1Result);
        //
        //RTcomputeShaderHelper.SetComputeBuffer(ref RayTracerShader, "_DirTex2", computeShaderHelper.Dbg_DirectionTexture2Buf);
        //computeShaderHelper.Dbg_DirectionTexture2Buf.GetData(computeShaderHelper.Dbg_DirectionTexture2Result);
        //
        //var res1 = computeShaderHelper.Dbg_DirectionTexture1Result;
        //var res2 = computeShaderHelper.Dbg_DirectionTexture2Result;
        //
        //int sameCount = 0, differentCount = 0;
        //
        //for (int y = 0; y < Screen.height; y += 10) {
        //  for (int x = 0; x < Screen.width; x += 10) {
        //    int k = x * Screen.width + y;
        //    //Debug.Log($"Dbg1 (x: {res1[k].x}, y: {res1[k].y}, z: {res1[k].z} || Dbg2 (x: {res2[k].x}, y: {res2[k].y}, z: {res2[k].z})");
        //    if (res1[k] == res2[k]) {
        //      ++sameCount;
        //    }
        //    else {
        //      ++differentCount;
        //    }
        //  }
        //}
        //
        //Debug.Log($"Same Count : {sameCount} || Different Count : {differentCount}");
        #endregion
    }