Advanced Member arumiat Posted February 1, 2015 Advanced Member Report Share Posted February 1, 2015 (edited) Hi all Was wondering whether any of you had any experience getting vertex painted models working in Unity? I've watched this video but it comes via Blender. So far I've painted some primitives in 3D coat and exported them as both obj and fbx's for testing purposes.I've created a simple vertex shader using Unity's documentation Code (CSharp): Shader "VertexInputSimple" { SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct v2f { float4 pos : SV_POSITION; fixed4 color : COLOR; }; v2f vert (appdata_base v) { v2f o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); o.color.xyz = v.normal * 0.5 + 0.5; o.color.w = 1.0; return o; } fixed4 frag (v2f i) : COLOR0 { return i.color; } ENDCG } } } I've created a new material, set the shader on the material to be VertexInputSimple (ie to use the above shader) and applied this to my objects. However I just am getting rainbow colours on them, rather than the simple vertex painted models I created in 3DC. Is anyone able to enlighten me as to any steps I'm missing? Thanks in advance, T Edited February 1, 2015 by arumiat Quote Link to comment Share on other sites More sharing options...
Contributor ajz3d Posted February 1, 2015 Contributor Report Share Posted February 1, 2015 Hi Arumiat. I never programmed in Unity, so I might be mistaken, but I looked on your shader's code and I can't find where you actually assign the vertex colour. What I see is that you assign normalized normal to X, Y and Z components of vertices' colour instead. o.color.xyz = v.normal * 0.5 + 0.5; So you probably need to replace this assignment with something else. Maybe with: o.color = v.color; Quote Link to comment Share on other sites More sharing options...
Advanced Member arumiat Posted February 2, 2015 Author Advanced Member Report Share Posted February 2, 2015 (edited) Hi ajz3D, that unfortunately didn't fix it but it got me thinking and I started trying different vertex shaders I could find online. This shader Shader "BumpedSpecularVtxCol" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) _Shininess ("Shininess", Range (0.03, 1)) = 0.078125 _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {} _BumpMap ("Normalmap", 2D) = "bump" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 400 CGPROGRAM #pragma surface surf BlinnPhong sampler2D _MainTex; sampler2D _BumpMap; fixed4 _Color; half _Shininess; struct Input { float2 uv_MainTex; float2 uv_BumpMap; half4 color : COLOR0; }; void surf (Input IN, inout SurfaceOutput o) { fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); o.Albedo = tex.rgb * _Color.rgb * IN.color.rgb; o.Gloss = tex.a; o.Alpha = tex.a * _Color.a; o.Specular = _Shininess; o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); } ENDCG } FallBack "Specular" } got me this effect (pretty nasty) This shader Shader "LiveMesh/Simple" { SubShader { Tags {"RenderType"="Transparent" "Queue"="Transparent"} Fog { Mode Off } Lighting On Pass { ZWrite On Cull Back Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag struct VertexInput { fixed4 vertex : POSITION; fixed4 color : COLOR; //fixed3 normal : NORMAL; //fixed4 tangent : TANGENT; //fixed4 texcoord : TEXCOORD; //fixed4 texcoord1 : TEXCOORD1; }; struct VertexOutput { fixed4 pos : SV_POSITION; fixed4 col : COLOR; }; VertexOutput vert (VertexInput v) { VertexOutput o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); o.col = v.color; return o; } fixed4 frag(VertexOutput o) : COLOR { return o.col; } ENDCG } } } got me this effect (it doesn't receive light or cast shadows). Also not ideal but better. I will keep looking for more shaders that will hopefully find one that works in all the ways needed. Thanks for taking a look for me! Edited February 2, 2015 by arumiat Quote Link to comment Share on other sites More sharing options...
Advanced Member Solution arumiat Posted February 9, 2015 Author Advanced Member Solution Report Share Posted February 9, 2015 A vertex shader that does the job I was looking for.. Shader "Custom/VertexColor_Specular" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) _Shininess ("Shininess", Range (0.01, 1)) = 0.078125 } SubShader { Tags { "RenderType"="Opaque" } LOD 300 CGPROGRAM #pragma surface surf BlinnPhong vertex:vert fixed4 _Color; half _Shininess; struct Input { fixed4 vColor; }; void vert( inout appdata_full v, out Input o ) { o.vColor = v.color; } void surf (Input IN, inout SurfaceOutput o) { o.Albedo = IN.vColor.rgb * _Color.rgb; o.Gloss = IN.vColor.a; o.Alpha = IN.vColor.a * _Color.a; o.Specular = _Shininess; } ENDCG } Fallback "VertexLit" } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.