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
0
Question by ZoeZoePixel · Feb 18, 2018 at 03:21 PM · not workingshader programmingnormalsvertex color

a shader i am using that uses vertex colors for normals renders differently when used on a skinned mesh renderer

ok.... i am using a toon shader by DominoM, which he posted https://forum.unity.com/threads/dd-standard-toon.496744/page-2 i then edit the toon shader to be used in MMD4MECHENIM's shaders which is posted http://stereoarts.jp/ they are toon shaders... i really liked what DominoM did with the outlines in his shader and really like the actual toon ramped shading tht MMD4MECHENIM does.... heres the partial shader


// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) // Modifed to use David Leon's toon BRDF by Domino Marama // Not for redistribution without the author's express written permission //credites DominoM, https://forum.unity.com/threads/dd-standard-toon.496744/page-2 // MMD4MECHENIMhttp://stereoarts.jp/ //hacked together by ... me

Pass { Name "Outline" Tags { "LightMode" = "Always" }

         Cull Front
         Zwrite On ZTest Less

         Blend SrcAlpha OneMinusSrcAlpha

         CGPROGRAM
         #include "HLSLSupport.cginc"
         #include "UnityShaderVariables.cginc"
         #include "Lighting.cginc"
         #include "MMD4Mecanim-MMDLit-AutoLight.cginc"
         #include "MMD4Mecanim-MMDLit-Lighting.cginc"
         #include "MMD4Mecanim-MMDLit-Compatible.cginc"
         #include "UnityCG.cginc"
         #pragma target 2.0
         #pragma exclude_renderers flash
         #pragma vertex vert_surf
         #pragma fragment frag_surf
         #pragma fragmentoption ARB_precision_hint_fastest
         #pragma multi_compile_fwdbase nolightmap nodirlightmap novertexlight
         #pragma multi_compile _ AMB2DIFF_ON
         // make fog work
         #pragma multi_compile_fog
         #pragma shader_feature _ _ALPHABLEND_ON _ALPHATEST_ON
         #pragma shader_feature _ _DD_USE_TOON_DATA

         float _OutlineEnabled;
         float _Outline;
         float4 _OutlineColor;
         float _OutlineColorMix;
         float _OutlineFade;
         float _Mode;
         float4 _Color;
         #if defined(_ALPHATEST_ON)
             float _Cutoff;
         #endif
         sampler2D _MainTex;
         float4 _MainTex_ST;
         #define MMDLIT_EDGE_ZOFST (0.00001)

         struct appdata
         {
             float4 vertex : POSITION;
             float3 normal : NORMAL;
             float2 uv : TEXCOORD0;
             #if defined(_DD_USE_TOON_DATA)
                 float4 color : COLOR;
             #endif
         };

         struct v2f_surf
         {
             float4 pos : POSITION;
             float3 normal : NORMAL;
             UNITY_FOG_COORDS( 2 )
             float4 color : COLOR;
             float2 uv : TEXCOORD0;
             float3 worldPos : TEXCOORD1;
         };

         v2f_surf vert_surf (appdata v)
         {
             v2f_surf o;
             UNITY_INITIALIZE_OUTPUT(v2f_surf, o);
             #if 0
               o.pos   = _UnityObjectToClipPos(v.vertex);
               o.pos.z += MMDLIT_EDGE_ZOFST * v.vertex.w;
             #else
                 o.pos = _UnityObjectToClipPos(v.vertex);
             #endif
             o.worldPos = mul(_UNITY_OBJECT_TO_WORLD, v.vertex);
             #if defined(_DD_USE_TOON_DATA)
                 float3 norm = v.color.rgb;
                 norm = mul( ( float3x3 )MMDLit_GetMatrixMV(), norm );
             #else
                 float3 norm = mul( ( float3x3 )MMDLit_GetMatrixMV(), v.normal );
             #endif
             float2 offset = TransformViewToProjection( norm.xy );
             float viewDistance = -(_UnityObjectToViewPos( v.vertex ).z);
             viewDistance = _ProjectionParams.z * _OutlineFade / viewDistance;

             #if defined(_DD_USE_TOON_DATA)
                 //o.pos.y += (min(_Outline, _Outline * viewDistance) * v.color.a) * offset;
                 //o.pos.y += (min(_Outline, _Outline * viewDistance) * v.color.a) * offset;
                 o.pos.xy += (min(_Outline, _Outline * viewDistance) * v.color.a) * offset;
             #else
                 o.pos.xy += min(_Outline, _Outline * viewDistance) * offset;
             #endif
             #if defined(UNITY_REVERSED_Z)
                 o.pos.z -= 0.00015;
             #else
                 o.pos.z += 0.00015;
             #endif
             o.uv = TRANSFORM_TEX( v.uv, _MainTex );
             o.color.rgb = _OutlineColor.rgb;
             o.color.a = saturate(_OutlineColor.a * viewDistance);
             #ifdef _ALPHABLEND_ON
                 o.color.a *= _Color.a;
             #endif
             return o;
         }

         fixed4 frag_surf (v2f_surf IN) : MMDLIT_SV_TARGET
         {
             half4 texColor = tex2D( _MainTex, IN.uv );
             #if defined(_ALPHATEST_ON)
                   clip((_Color.a * texColor.a) - _Cutoff);
             #endif
             IN.color.rgb = lerp(IN.color.rgb, _Color.rgb * texColor.rgb, _OutlineColorMix);
             UNITY_APPLY_FOG( IN.fogCoord, IN.color );
             return IN.color;
         }
         ENDCG

now with a wholes days worth of trying to figure out why this is happing alt text

i figured out these 2 lines of the shader code which are these

#if defined(_DD_USE_TOON_DATA) float3 norm = v.color.rgb; norm = mul( ( float3x3 )MMDLit_GetMatrixMV(), norm); #else float3 norm = mul( ( float3x3 )MMDLit_GetMatrixMV(), v.normal ); #endif now when i change norm = mul( ( float3x3 )MMDLit_GetMatrixMV(), norm); to use the meshes v.normals they do this... alt text however when using the norm var which is the vertex colors of the mesh it does 1st image above this one...

what i am asking is...

why is it with a mesh filter (on the right) has diferent vertex colors than the skinned mesh renederer (on the left) when they use the same exact mesh!!!!!

they are the same materials and meshes.... so the only difence between these 2 game objects ... are tht

  1. 1 of the uses a skinned mesh reneder while the other uses a mesh filter

  2. one of them has bones while the other is static

which for some odd reason results in the above image.... i also want to note tht i am using the forward renedered with no posteffects and the mesh with the vertex colors was geneated by DominosM's shaders generate vertex colors option which then save a new mesh in the assets folder which i then set as both of the above game objects mesh meaning these SHOULD have the same vertex colors.... however something is changing the skinned mesh renderes mesh on reneder......

so.... i know that the reason why this is happing is the fact tht the mesh has the same vertex colors as the skinned mesh renederer however the skinned mesh rendnerer is somehow editing them.. but how do i fix it????

capture.png (323.7 kB)
capture.png (163.5 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
Best Answer

Answer by ZoeZoePixel · Feb 19, 2018 at 07:34 PM

Appartently what happened was tht my normals werent converted to worldspace! heres the code to fix tht

 v.color.rgb = UnityObjectToWorldNormal(v.color.rgb);
 float3 norm = v.color.rgb;

@DominoM finally got it working!!! it also looks the same for a mesh renderer AND a skinned mesh renderer!!!!

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

78 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

Related Questions

Displace and show normals in fragment shader 1 Answer

How to blend color when using shadergraph wich uses normals? 0 Answers

Vertex Color Shader 0 Answers

How to mask textures by vertex color? 0 Answers

Persistent data values in shaders 3 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