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
1
Question by kmozuna · Sep 10, 2012 at 07:15 PM · shadermodelvertexdisplacement3.0

Vertex Displacement Shader Problems

Hi all, I've been working back and forth trying to solve this issue, but haven't yet been able to prevail. I've created a Vertex Displacement Shader from research many examples and it works for my computer. But it doesn't work on macs. The idea is that the character can get fat or skinny through the combination of weight/depth texture as a control and a float for intensity. It works when I use #pragma target 3.0 but this from my understanding restricts it to shader 3, but the instant I remove the line I get errors saying tex2dlod not supported. I've tried using texture2d and tex2d but I still get the same results.

So my question is, is it even possible to fetch textures through a vertex shader for anything other than shader model 3.0, and it so how? But if it's not possible is they're any workarounds? By the way this shader needs to work on both Mac & Pc and iOS

 Shader "Custom/Fat" {
     Properties {
       _MainTex ("Texture", 2D) = "white" {}
       _Amount ("Extrusion Amount", Range(-0.6,1.5)) = 0
       _BumpMap ("Bumpmap", 2D) = "bump" {}
       _DepthTex ("DepthTex", 2D) = "white" {}
     }
     SubShader {
       Tags { "RenderType" = "Opaque" }
       CGPROGRAM
       #pragma target 3.0
       #pragma glsl
       #pragma surface surf Lambert vertex:vert addshadow
       struct Input {
           float2 uv_MainTex;
           float2 uv_DepthTex;
           float2 uv_BumpMap;
       };
       float _Amount;
       sampler2D _DepthTex;
       void vert (inout appdata_full v) {
          float4 tex = tex2Dlod (_DepthTex, float4(v.texcoord.xy,0,0));
          v.vertex.xyz += v.normal * tex.b * _Amount;
       }
       
       sampler2D _MainTex;
       sampler2D _BumpMap;
       void surf (Input IN, inout SurfaceOutput o) {
           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
           o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
       }
       ENDCG
     } 
     Fallback "Diffuse"
 }

Thank you for your time

Comment
Add comment · Show 2
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 slgooding · Nov 20, 2012 at 07:31 PM 0
Share

Did you ever figure this out? I don't have the answer, but I really appreciate you posting this.

avatar image kmozuna · Nov 28, 2012 at 05:12 PM 0
Share

Hey yes and no. I'll chuck it in answers so I can close this question cause I don't know any other way to do it, lol.

1 Reply

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

Answer by kmozuna · Nov 28, 2012 at 09:31 PM

The fix is not great because it's not dynamic, what I had to is bake in the texture to vertex. I used Maya for this through the mentalray bake settings, I believe most 3D packages have this ability. Once I baked it in, I made the shader grab the color of the vertex to control the percentage. This meant it's static but for my game it's not a big deal, it'll be nice to have a dynamic solution for this but I guess we just have to wait for all technology to catch up or for someone to find a better answer. This has only been tested on Mac and PC, so I'm hoping it works for iOS and Android but I'll get to that later.

 Shader "Custom/Fat" {
     Properties {
       _MainTex ("Texture", 2D) = "white" {}
       _Amount ("Extrusion Amount", Range(-0.6,1.5)) = 0
       _BumpMap ("Bumpmap", 2D) = "bump" {}
     }
     SubShader {
       Tags { "RenderType" = "Opaque" }
       CGPROGRAM
       
       #pragma surface surf Lambert vertex:vert addshadow
       #include "UnityCG.cginc"
       struct Input {
           float2 uv_MainTex;
           float2 uv_BumpMap;
       };
       float _Amount;
       struct v2f {
             float4 position : POSITION;
     };
       void vert (inout appdata_full v) {
           v2f o;
           o.position = mul(UNITY_MATRIX_MVP, v.vertex);
           float4 depth = v.color * _Amount;
           v.vertex.xyz += v.normal * depth;
       }
       
       sampler2D _MainTex;
       sampler2D _BumpMap;
       void surf (Input IN, inout SurfaceOutput o) {
           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
           o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
       }
       ENDCG
     } 
     Fallback "Diffuse"
 }
Comment
Add comment · Show 1 · 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
avatar image slgooding · Nov 29, 2012 at 03:21 AM 0
Share

Thanks again for this. I really appreciate you posting it.

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

9 People are following this question.

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

Related Questions

Vertex Displacement in Forward Rendering Shader 2 Answers

Unity shader vertex displace doesn't work 0 Answers

How do I alter vertex displacement based on UV coordinates? 0 Answers

Is it possible to get back data for a specific vertex from a shader ? 0 Answers

Modify vertex position using shaders on Windows Phone 8 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