- Home /
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
Did you ever figure this out? I don't have the answer, but I really appreciate you posting this.
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.
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"
}
Thanks again for this. I really appreciate you posting it.
Your answer
Follow this Question
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