Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by ProfessorQu · Sep 27, 2021 at 08:36 AM · camerashadermovementrenderingrendertexture

PC blackscreens when "Failed to create RenderTexture",PC screen goes black when "Failed to create rendertexture"

I have tried to create a sort of Mandelbrot set explorer, however I can't find the solution to my problem. I have seen a few other questions where people told them to update their drivers, so I did but it didn't work.

The full error is D3D11: Failed to create RenderTexture (1104 x 585 fmt 19 aa 1), error 0x8007000e

The code I've been using is using a master script for the camera and a compute shader to generate the texture.

Master script to render to the camera (Camera component attached to object):

 // Set camera
 public Camera cam;
 // Set shader and kernel
 public ComputeShader shader;

 // Set groups
 int xGroups;
 int yGroups;

 // Set width and height
 int width;
 int height;

 // Set aspect ratio and minimum zoom
 public float aspectRatio = -1;
 public float minZoom = 5e-5f;

 // Set rendertexture
 RenderTexture tex;

 // Set max iterations
 public int maxIterations = 200;

 // Set the area, the x and y positions and x and y zooms
 public Vector4 area = new Vector4(0, 0, 1, 1);


 void Start()
 {
     Init();
 }

 private void Init()
 {
     // Setting width and height
     Debug.Log("Setting width and height...");
     width = cam.pixelWidth;
     height = cam.pixelHeight;

     // Calculating thread groups
     Debug.Log("Calculating thread groups...");
     // Calculate kernel groups
     xGroups = Mathf.CeilToInt(width / 8f);
     yGroups = Mathf.CeilToInt(height / 8f);

     // Calculate aspect ratio
     if (aspectRatio == -1)
     {
         Debug.Log("Setting aspect ratio...");

         aspectRatio = (float)width / (float)height;

         if (aspectRatio > 0)
         {
             area.z *= aspectRatio;
         }
         else
         {
             area.w *= aspectRatio;
         }
     }

     // Create render texture
     if (tex == null || tex.width != width || tex.height == height)
     {
         Debug.Log("Creating texture...");

         tex = new RenderTexture(width, height, 24);
         tex.enableRandomWrite = true;
         tex.Create();
     }

     // Set shader parameters
     SetShaderParameters();
 }

 void SetShaderParameters()
 {
     Debug.Log("Setting shader parameters...");
     // Set width and height
     shader.SetInt("_Width", width);
     shader.SetInt("_Height", height);

     // Set max iterations
     shader.SetInt("_MaxIterations", maxIterations);

     // Set area
     shader.SetVector("_Area", area);

     // Set result
     shader.SetTexture(0, "Result", tex);
 }

 void HandleInputs()
 {
     // Checking for inputs
     Debug.Log("Checking for inputs...");

     // Zoom in
     if (area.z * 0.99f > minZoom || area.w * 0.99f > minZoom)
     {
         if (Input.GetKey(KeyCode.LeftBracket))
         {
             area.z *= 0.99f;
             area.w *= 0.99f;
         }
     }

     // Zoom out
     if (Input.GetKey(KeyCode.RightBracket))
     {
         area.z *= 1.01f;
         area.w *= 1.01f;
     }

     // Move to the left
     if (Input.GetKey(KeyCode.A)){
         area.x -= 0.01f * area.z;
     }
     // Move to the right
     if (Input.GetKey(KeyCode.D))
     {
         area.x += 0.01f * area.z;
     }
     // Move to the top
     if (Input.GetKey(KeyCode.W))
     {
         area.y += 0.01f * area.z;
     }
     // Move to the bottom
     if (Input.GetKey(KeyCode.S))
     {
         area.y -= 0.01f * area.z;
     }
 }

 private void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     Debug.Log("Rendering texture...");
     Init();

     Debug.Log("Dispatching shader...");
     shader.Dispatch(0, xGroups, yGroups, 1);

     // Rendering texture
     Graphics.Blit(tex, destination);

 }

 private void Update()
 {
     // Handle inputs
     HandleInputs();
 }

 private void OnDestroy()
 {
     // Release textures
     tex.Release();
 }

The compute shader I use to create the Mandelbrot set:

 #pragma kernel CSMain

 RWTexture2D<float4> Result;

 unsigned int _Width, _Height;

 uniform int _MaxIterations;

 uniform float4 _Area;

 float map(float value, float istart, float istop,
             float ostart, float ostop)
 {
     return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
 }

 float rgb(float v)
 {
     return sin(v) * 0.5 + 0.5;
 }

 [numthreads(8, 8, 1)]
 void CSMain(uint3 id : SV_DispatchThreadID)
 {   
     Result[id.xy] = float4(0, 0, 0, 0);
 
     float halfWidth = _Width / 2;
     float halfHeight = _Height / 2;
 
     float a = map(id.x, 0, _Width, -1, 1);
     float b = map(id.y, 0, _Height, -1, 1);
 
     float2 ab = float2(a, b);
 
     //float ca = -0.8;
     //float cb = 0.156;
     float2 c = _Area.xy + ab * _Area.zw;
 
     float2 z;
 
     int n = 0;
 
     for (n = 0; n < _MaxIterations; n++)
     {
         float aa = z.x * z.x - z.y * z.y;
         float bb = 2 * z.x * z.y;
     
         z.x = aa + c.x;
         z.y = bb + c.y;
     
         if (length(z) > 2)
             break;
     }
 
     if (n == _MaxIterations)
     {
         Result[id.xy] = float4(0, 0, 0, 1.0);
     }
     else
     {
         float v = sqrt((float) n / _MaxIterations);
     
         Result[id.xy] = float4(rgb(v * 2), rgb(v * 5), rgb(v * 10), 1.0);
     }
     //float v = sqrt((float) n / _MaxIterations);
     //float bright = (float) n / _MaxIterations;
     //Result[id.xy] = float4(bright, bright, bright, 1.0);
 }
Comment
Add comment
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

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

335 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 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

How to get Post Processing in Unity 5.6.7f1 1 Answer

Cut through camera render and display LITERALLY NOTHINGNESS 0 Answers

Render texture not rendering 0 Answers

(HDRP) Camera.Render() renders black, but only if Scene View is not visible 0 Answers

How to hide light from second camera 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