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 /
avatar image
0
Question by TheLazyEngineer · Sep 01, 2020 at 01:39 AM · shadershadersshader programmingshader writing

Where do I put this shader code? Getting weird error?

I'm trying to test out the DirectX 12 API in a .raytrace shader. Here's the Ray generation and miss shader:


 #pragma max_recursion_depth 1
 
 
 RWTexture2D<float4> Result;
 RaytracingAccelerationStructure sceneAccelStruct;
 float4x4 _CameraToWorld;
 float4x4 _CameraInverseProjection;
 float TMin = 0.0f;
 float TMax = 1e38f;
 
 struct SimpleRayPayload
 {
     float3 color;
 };
 
 RayDesc CreateRay(float2 uv)
 {
     RayDesc ray;
     ray.Origin = mul(_CameraToWorld, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz;
     ray.Direction = normalize(mul(_CameraToWorld, float4(mul(_CameraInverseProjection, float4(uv, 0.0f, 1.0f)).xyz, 0.0f)).xyz);
     ray.TMin = TMin;
     ray.TMax = TMax;
     return ray;
 }
 
 [shader("raygeneration")]
 void RayGenerationShader()
 {
     uint2 curPixel = DispatchRaysIndex().xy;
     uint2 totalPixels = DispatchRaysDimensions().xy;;
     float2 pixelCenter = (curPixel + float2(0.5f, 0.5f)) / totalPixels;
     float2 uv = float2(2, -2) * pixelCenter + float2(-1, 1);
     RayDesc ray = CreateRay(uv);
     SimpleRayPayload payload = { float3(0,0,0) };
     TraceRay(sceneAccelStruct, RAY_FLAG_NONE, 0xFF, 0, 1, 0, ray, payload);
     Result[curPixel] = float4(payload.color, 1.0f);
 }
 
 
 [shader(“miss”)]
 void RayMiss(inout SimpleRayPayload data)
 {
     data.color = float3(0, 0, 1);
 }
 
 [shader(“closesthit”)]
 void RayClosestHit(inout SimpleRayPayload data, BuiltinIntersectionAttribs attribs)
 {
     data.color = float3(1, 0, 0);
 }



which i pieced together using the following links:


https://on-demand.gputechconf.com/siggraph/2019/pdf/sig940-getting-started-with-directx-ray-tracing-in-unity.pdf

http://intro-to-dxr.cwyman.org/presentations/IntroDXR_RaytracingShaders.pdf


My project is setup with the HDRP and the Graphics API is set to use DirectX 12 as the first priority option.


Here's the error i see in the editor:


alt text


Am I supposed to be putting the miss ./ closest hit shaders somewhere else?


shader-error.png (30.4 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TheLazyEngineer · Sep 01, 2020 at 04:37 AM

Ok, so this is funny... the error in the image is actually from copy and pasting code. The quotations in the miss shader attribute (line 40) aren't actually quotation marks!!! hahaha wow!

But anyway.. does anyone have a demo project of writing custom raytracing shaders all the way from raygeneration shader to the intersection, anyhit, closesthit, and miss shaders? Would be very helpful!

Comment
Add comment · Share
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

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

213 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

Related Questions

Making shader not ignore Light on transparent areas ? 0 Answers

Wireframe shader with constant width and no diagonals 1 Answer

Is a water shader with these features possible or easy to make? 1 Answer

Adding a clip() to the default shader? 0 Answers

Shader - What is float3.xy? 1 Answer


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