Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by sparkkhuang · Feb 22 at 10:47 AM · rendergameplay

unrecognized identifier 'INVALID_UTF8_STRING' at kernel xx?

Why does my code always report such an error under URP?

unrecognized identifier 'INVALID_UTF8_STRING' at kernel xx (:

================================

WaterSplashTest.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class WaterSplashTest : MonoBehaviour
 {
     private struct Particle
     {
         public Vector3 position;
         public float lifetime;
         public float showScale;
     }
 
     private struct Result
     {
         public float ScreenUVx;
         public float ScreenUVy;
         public Vector3 WorldPos;
         public float Deep;
     }
 
     private Dictionary<Vector2,GameObject> objects = new Dictionary<Vector2,GameObject>();
     public GameObject debugPrefab;
     public GameObject prefabRoot;
 
     public RenderTexture DepthRT;
 
     //public RenderTexture DepthRT;
 
     public Camera Camera;
 
 
     private int particleCount;
 
     public ComputeShader computeShader;
 
     private const int SIZE_PARTICLE = 20;
     private const int SIZE_DEBUG = 24;
 
     //kernel ID
     private int mComputeShaderKernelID;
 
     //buffer,
     ComputeBuffer particleBuffer;
     ComputeBuffer resultBuffer;
 
     private Particle[] particleResult;
     private Result[] debugResult;
 
     private const int WARP_SIZE = 256;
 
     int width;
     int height;
 
     void Start()
     {
         width = Screen.width;
         height = Screen.height;
 
         DepthRT = new RenderTexture(width, height, 0, RenderTextureFormat.RHalf)
         {
             autoGenerateMips = false,
             enableRandomWrite = true,
             useMipMap = true,
             filterMode = FilterMode.Point
         };
         DepthRT.Create();
 
 
         particleCount = width * height / 10 /10 ;
 
         objects = new Dictionary<Vector2, GameObject>();
 
         Debug.LogError(height);
         Debug.LogError(width);
 
         //初始化粒子数据
         Particle[] particleArray = new Particle[particleCount];
         particleResult = new Particle[particleCount];
 
         Result[] resultArray = new Result[particleCount];
         debugResult = new Result[particleCount];
 
         int index = 0;
 
         for (int i = 0; i < width; i++)
         {
             if (i % 10 == 0)
             {
                 for (int j = 0; j < height; j++)
                 {
                     if (j % 10 == 0)
                     {
                         GameObject go = GameObject.Instantiate(debugPrefab, prefabRoot.transform);
                         go.transform.position = Vector3.zero;
 
                         objects.Add(new Vector2(i, j), go);
 
                         particleArray[index].position.x = i;
                         particleArray[index].position.y = j;
 
                         particleArray[index].lifetime = Random.Range(0f, 25f);
 
                         index += 1;
                     }
                 }
             }
         }
 
         particleBuffer = new ComputeBuffer(particleCount, SIZE_PARTICLE);
         particleBuffer.SetData(particleArray);
 
         resultBuffer = new ComputeBuffer(particleCount, SIZE_DEBUG);
         resultBuffer.SetData(resultArray);
 
         mComputeShaderKernelID = computeShader.FindKernel("WaterSplash");
 
         computeShader.SetBuffer(mComputeShaderKernelID, "particleBuffer", particleBuffer);
 
         computeShader.SetBuffer(mComputeShaderKernelID, "resultBuffer", resultBuffer);
 
         computeShader.SetFloat("width", width);
     }
 
     void OnDestroy()
     {
         if (particleBuffer != null)
         {
             particleBuffer.Release();
             particleBuffer.Dispose();
         }
 
         if(resultBuffer!= null)
         {
             resultBuffer.Release();
             resultBuffer.Dispose();
         }
     }
 
 #if UNITY_EDITOR
     void Update()
     {
 #else
     void OnPreRender()
     {
 #endif
         DepthMake();
 
         computeShader.SetMatrix("vpMatrixInv", vpMatrixMake());
         computeShader.SetTexture(mComputeShaderKernelID, "DeptTex", DepthRT);
         computeShader.SetFloat("deltaTime", Time.deltaTime);
 
         computeShader.Dispatch(mComputeShaderKernelID, 8, 8, 1);
 
         particleBuffer.GetData(particleResult);
         resultBuffer.GetData(debugResult);
 
         DebugTest();
     }
 
     private Matrix4x4 vpMatrixMake()
     {
         Matrix4x4 projMat = GL.GetGPUProjectionMatrix(Camera.projectionMatrix, false);
         var vpMatrix = projMat * Camera.worldToCameraMatrix;
 
         return vpMatrix.inverse;
     }
 
     void DebugTest()
     {
         if(debugResult == null || debugResult.Length == 0 || objects == null || objects.Count == 0)
         {
             return;
         }
 
         GameObject result;
         Result temp;
 
         for (int i = 0; i < debugResult.Length; i++)
         {
             temp = debugResult[i];
 
             objects.TryGetValue(new Vector2(temp.ScreenUVx, temp.ScreenUVy), out result);
 
             if(result == null)
             {
                 continue;
             }
 
             result.transform.position = temp.WorldPos;
             //result.GetComponent<Material>().color = Color.red * temp.Deep;
         }
     }
 
     private void DepthMake()
     {
         RenderTexture tempRT;
 
         tempRT = RenderTexture.GetTemporary(width, height, 0, DepthRT.format);
         tempRT.filterMode = FilterMode.Point;
 
         Graphics.Blit(Shader.GetGlobalTexture("_CameraDepthTexture"), tempRT);
 
         Graphics.CopyTexture(tempRT, 0, 0, DepthRT, 0, 0);
     }
 }



============================= WaterSplash.compute

 #pragma kernel WaterSplash
 
 struct Particle
 {
     float3 position;
     float lifetime;
     float showScale;
 };
 
 struct Result
 {
     float ScreenUVx;
     float ScreenUVy;
     float3 WorldPos;
     float Deep;
 };
 
 RWStructuredBuffer<Particle> particleBuffer;
 RWStructuredBuffer<Result> resultBuffer;
 
 RWTexture2D<float4> DeptTex;
 
 float deltaTime;
 float width;
 
 
 float4x4 vpMatrixInv;
 
 [numthreads(8,8,1)]
 void WaterSplash (uint3 id : SV_DispatchThreadID)
 {
 
     float dept = DeptTex[id.xy].r;
 
     //Reverse_Z
 #if defined(UNITY_REVERSED_Z)
     dept = 1 - dept;
 #endif
 
 
     float4 ndc = float4(id.x * 2 - 1, id.y * 2 - 1, dept * 2 - 1, 1);
 
 
     float4 worldPos = mul(vpMatrixInv, ndc);
     worldPos /= worldPos.w;
 
 
     int index = id.x * width + id.y;
 
     resultBuffer[index].WorldPos = float3(1,1,1);
     resultBuffer[index].ScreenUVx = id.x;
     resultBuffer[index].ScreenUVy = id.y;
     resultBuffer[index].Deep = dept;
 
 
     //float3 delta = float3(0, -2, 0);
     particleBuffer[index].position = worldPos;
     particleBuffer[index].lifetime += deltaTime;
 
     if (particleBuffer[index].lifetime > 2)
     {
         particleBuffer[index].lifetime = 0;
     }
 
 
     particleBuffer[index].showScale = dept;
 }
 

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KrzysztofTMu · Feb 23 at 08:25 AM 1
Share

Can you try removing this: //初始化粒子数据

avatar image sparkkhuang KrzysztofTMu · Feb 23 at 09:24 AM 0
Share

Comments don't matter, do they?

avatar image KrzysztofTMu sparkkhuang · Feb 23 at 11:31 AM 0
Share

You won't find out unless you try.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

177 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5.2 does not render texture on android device 1 Answer

Unity UI Problem 0 Answers

Why does VFX Graph work in URP? 0 Answers

How to make it so that when you open a door you enter the room you want to exit? 2 Answers

Rigidbody Jumping issues 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges