Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
avatar image
0
Question by Rizzutp · Jan 21, 2020 at 12:18 PM · shaderrendertexturedepthhlsl

sampler2d object has no methods

Hello there. I'm trying to write my shader, in order to get a depth texture that has to be assigned to the camera, in order to get a black-and-white description of the distance of the objects within the scene from the rendering camera.

This is the code ( from https://forum.unity.com/threads/camera-depth-texture-sampling-with-2018-3-and-hdrp-4-x-mip-map-issue.594160/ ):

     Shader "Unlit/DepthShade"
     {
         Properties
         {
             _MainTex ("Decal Texture", 2D) = "white" {}
         }
      
         HLSLINCLUDE
         #include "UnityCG.cginc"
         #include "HLSLSupport.cginc"
          
         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/API/D3D11.hlsl"
         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/API/GLCore.hlsl"
         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Macros.hlsl"
         #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
         #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
         ENDHLSL
          
         CGINCLUDE
         #include "UnityCG.cginc"
         #include "HLSLSupport.cginc"
         ENDCG
          
         SubShader
         {
             Tags{ "Queue"="Geometry+1" }
          
             Pass
             {
                 ZWrite Off
                 Blend SrcAlpha OneMinusSrcAlpha
          
                 HLSLPROGRAM
                 #pragma target 3.0
                 #pragma vertex vert
                 #pragma fragment frag
          
                 struct v2f
                 {
                     float4 pos : SV_POSITION;
                     float4 screenUV : TEXCOORD0;
                     float3 ray : TEXCOORD1;
                 };
                    
                 v2f vert (appdata_base v)
                 {
                     v2f o;
                     o.pos = UnityObjectToClipPos (v.vertex);
                     o.screenUV = ComputeScreenPos (o.pos);
                     o.ray = UnityObjectToViewPos(v.vertex).xyz * float3(-1,-1,1);
                     return o;
                 }
          
                 sampler2D _MainTex;
                 sampler2D _CameraDepthTexture;
                 float4 frag(v2f i) : SV_Target
                 {
                     i.ray = i.ray * (_ProjectionParams.z / i.ray.z);
                     float2 uv = i.screenUV.xy / i.screenUV.w;
                        
                     float depth = LOAD_TEXTURE2D(_CameraDepthTexture, uv);
                        
                     depth = Linear01Depth (depth);
                        
                     float4 vpos = float4(i.ray * depth,1);
                     float3 wpos = mul (unity_CameraToWorld, vpos).xyz;
                     float3 opos = mul (unity_WorldToObject, float4(wpos,1)).xyz;
                     clip (float3(0.5,0.5,0.5) - abs(opos.xyz));
                        
                     float2 texUV = opos.xz + 0.5;
          
                     float4 col = tex2D (_MainTex, texUV);
                     return col;
                 }
                 ENDHLSL
             }
         }
          
         Fallback Off
     }

However, the compiler gives the following error: sampler2d object has no methods. alt text

Any ideas?

sampler2derror.jpg (95.1 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

Answer by AkilliMum · Sep 22, 2020 at 11:28 AM

Hi, not sure about the problem but i suppose LOAD_TEXTURE2D wants a Texture2D not a sampler2D, because you defined the depth texture like "sampler2D _CameraDepthTexture;" the LOAD_TEXTURE2D related error happens. Maybe defining the depth like "Texture2D (_CameraDepthTexture);" may resolve your problem. Not an hdrp guru though :)

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

185 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

Related Questions

Render scene depth to a texture 4 Answers

Multiple RenderTexture and depth buffer 1 Answer

Compositing two RenderTextures based on depth 1 Answer

How to get the depth values of the camera view? 1 Answer

Normals from Depth texture distorted 2 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