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 Tristao · Jan 09, 2018 at 05:32 AM · shadershader programming

Trying to make a shader like Theresa Latzko did with her game Porcupine

Hello guys!

I was just watching the Theresa Latzko's class and the "mini tutorial" Unity made about the shader she made, but I'm struggling a bit on trying to replicate it. First of all, she used Vertex Coloring for all the models in her scene, so she didn't need to uv map anything, she just painted everything on the model. Second, she handled light in a very particular way: she ignored the normals directions and only took account the distance of the light source from the objects. I've found a great Vertex Coloring shader and Unity provided the code she used to handle the light, but I'm struggling a bit to put them together. Here is the Vertex Coloring Shader:

 Shader "Custom/NewSurfaceShader" {
       Properties
     {
         _Color ("Color", Color) = (1,1,1,1)
     }
     SubShader
     {
         Tags { "RenderType"="Opaque" }
         LOD 200
        
         CGPROGRAM
 
         // BlinnPhong lighting model, and enable shadows on all light types
         #pragma surface surf BlinnPhong fullforwardshadows
  
         // Use shader model 3.0 target, for no particular reason
         #pragma target 3.0
 
         struct Input
         {
             float4 color : COLOR;
         };
  
         fixed4 _Color;
  
         void surf (Input IN, inout SurfaceOutput o)
         {
             o.Albedo = IN.color.rgb * _Color.rgb;
         }
 
         ENDCG
     }
     FallBack "Diffuse"
 }

And here is the function she made to handle lighting:

 float3 ShadeVertexLightsAtten (
                 float4 lightPosX, float4 lightPosY, float4 lightPosZ,
                 float3 lightColor0, float3 lightColor1, float3 lightColor2, float3 lightColor3,
                 float4 lightAttenSq,
                 float3 pos)
             {
                 // to light vectors
                 float4 toLightX = lightPosX - pos.x;
                 float4 toLightY = lightPosY - pos.y;
                 float4 toLightZ = lightPosZ - pos.z;
                 // squared lengths
                 float4 lengthSq = 0;
                 lengthSq += toLightX * toLightX;
                 lengthSq += toLightY * toLightY;
                 lengthSq += toLightZ * toLightZ;
                 // attenuation
                 float4 atten = 1.0 / (1.0 + lengthSq * lightAttenSq);
                 float4 diff = atten;
                 //light color reverses
                 lightColor0 = (1-lightColor0);
                 lightColor1 = (1-lightColor1);
                 lightColor2 = (1-lightColor2);
                 lightColor3 = (1-lightColor3);
                 // final color
                 float3 col = 0;
                 col += lightColor0 * diff.x;
                 col += lightColor1 * diff.y;
                 col += lightColor2 * diff.z;
                 col += lightColor3 * diff.w;
                 return col;
             }

So, how did she put these two things together? Here is the Unity "mini tutorial" I mentioned".

I would like to have a result similar or equal to the one in the link above... There is also a video about her work in the Unity Youtube Channel.

Sorry if this is too simple, and thanks in advance!

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

Answer by andybak · Jul 16, 2018 at 02:58 PM

I couldn't figure it out either but I tried a different approach - I found a simple shader that handled pixel lights: https://en.wikibooks.org/wiki/Cg_Programming/Unity/Multiple_Lights

and modified it to use vertex colors and ignore normals:

https://gist.github.com/andybak/2cf3965eedaf296437ff9c2c7ca7ca8a

I now need to work out how to handle the shadow pass. :-/

EDIT - I realised the shadow pass works fine as long as I also have a pixel light. However - the pixel light then overwhelms the vertex colours making it hard to have nice, saturated colours.

I might try and implement Theresa's other suggestion - using pixel lights for subtractive darkening of the environment. She's not clear on how she manages this as well as shadow casting on the terrain so I'll need to give it some thought.

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

118 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 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

Unlit Transparent With Color Support 1 Answer

create a texture with shader code? ( without using a texture ) 1 Answer

How to add Emission to my custom shader? 2 Answers

The Best Way To Make Stylised Grass in Unity? 0 Answers

How to get the value of a pixel of a noise node if it's greater than some threshold? 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