Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Def · Aug 27, 2011 at 11:28 AM · vertexshader

Sampling Texture in Vertex Shader?

Hi, I'm trying to sample a texture in a vertex shader, but for some reason I'm always getting 0,0,0,0 back from tex2D.

For debug purposes I'm just forwarding the sampled data through to the pixel shader for display. The input texture is solid light green and can be sampled fine in the pixel shader. For some reason it's not working from the vertex shader.

My graphics card is an nVidia Quadro FX1500, which claims to support shader model 3.0 (which, I believe, is the minimum version for texture sampling from a vertex shader).

 Shader "VSTex"
 {
     Properties
     {
         _Tex( "Tex", 2D ) = "white" {}
     }
 
     SubShader
     {
         Tags
         {
             "Queue"="Transparent"
             "RenderType"="Transparent"
         }
 
         Pass
         {
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
                 #pragma target 3.0
                 #pragma glsl
                 #pragma vertex VS
                 #pragma fragment PS
 
                 sampler2D _Tex;
 
                 struct SVSInput
                 {
                     float4    vertex : POSITION;
                 };
 
                 struct SVSToPS
                 {
                     float4    pos : POSITION;
                     float4    color : COLOR;
                 };
 
                 SVSToPS VS( SVSInput input )
                 {
                     SVSToPS     output;
 
                     output.pos = mul( UNITY_MATRIX_MVP, float4( input.vertex.xyz, 1.0f ));
                     output.color = tex2D( _Tex, float2( 0.0f, 0.0f ));
 
                     return output;
                 }
 
                 float4 PS( SVSToPS input ) : COLOR
                 {
                     return float4( input.color.xyz, 0.5f );
                 }
             ENDCG
         }
     }
     Fallback Off
 }
Comment
Add comment · Show 1
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 Def · Aug 29, 2011 at 05:35 AM 0
Share

$$anonymous$$inor update: tex2D is never supported in vertex shaders. The correct function to use is tex2Dlod. So I'm not sure why Unity allows the former to compile. It's still not working though.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Nodin · Jun 14, 2012 at 09:16 AM

Just use tex2Dlod to sample vertex texture.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Vertex shader does not receive vertex coordinates as I expected. Why? 2 Answers

Getting model bounds in vertex shader 0 Answers

Shader: Add Refraction to Surface shader? 0 Answers

using two shaders together 1 Answer

custom vertex shader that works with skinned mesh 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