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 Adam2Marsh · Mar 20, 2017 at 01:24 AM · shaderverticesblendingvertex shadervertex color

Painted Vertices are Blockly, Looking to smooth them Out

Hey Everyone,

Having some issues with the which i hope the attached image will explain.

In my game I'm painting the vertices at runtime and have a simple shader to display the vertex colours:

 Shader "Vertex Color Lit" {
     Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader {
        Pass {
            Lighting On
            ColorMaterial AmbientAndDiffuse
            SetTexture [_MainTex] {
               combine texture * primary DOUBLE
            }
        }
     }
 }

The problem is I liked the colours to blend more naturally and not look so blocky, I'm under the impression this is something I can do with the shader but not having any luck. Tried some of the blend options and they did nothing.

Can anyone point me in the right direction?

Thanks, Adam

screen-shot-2017-03-19-at-234541.png (7.1 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
1
Best Answer

Answer by Bunny83 · Mar 20, 2017 at 03:35 AM

A shader can't do much here. The GPU generally interpolates all vertex attributes linearly across the rasterized triangles. So if one vertex is white and the other blue the fragments in between will have a linear mix between them. This behaviour can't be changed. Also it wouldn't make much sense. A mesh could have any arrangement of triangles. You just have a special case where you use a regular rectangular grid.

Your problem is simply that you only paint two colors. This of course creates a high contrast between two vertices of different colors. If you want a smoother result you basically have to allow painting with an "opacity" setting and a gradient around your brush which you use to paint. If the painting should be that "sharp" (so one could paint a single vertex with a highly different color) the result will look that "sharp".

If you want a better result you may want to use a single quad mesh and paint on a texture instead of doing vertex painting. Unlike vertex colors, texture color interpolation uses bilinear interpolation and takes the closest 4 texels into account. A slightly better result would be achieved by using a bicubic interpolation (which takes the 16 neighbor texels into account). However the hardware doesn't really support bicubic filtering. You would need to do that yourself in the shader. However a high contrast blocky image will always be "kind of" blocky since your vertex arrangement is rectangular. Bicubic makes each texel appear a bit more "round". Note that bicubic requires 4 times as many texture lookups per fragment as bilinear filtering. In most realtime application bicubic isn't used. It's commonly used in image processing when you resample an image (up or down scale). (numberphile on bicubic).

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 Adam2Marsh · Mar 21, 2017 at 08:35 AM 1
Share

Thanks for the quick and detailed response, I think for now I will go for painting with some opacity around the edges so it doesn't look as edgey.

It's for a nice paint splash effect for a game I'm working, originally did look at a shader/texture solution but I require 5 colours and most solutions you could only run with 4 which is why I'm using the vertex approach which works great expect for the blocky nature.

Another thanks for the detail, still new with shaders and I've got a lot to learn so appreciate the time you took to provide some explanation!

Thanks, Adam

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Changes to Mesh Vertex Colors Reset on Build 1 Answer

real time vertex shading / color or transparency by vertex height 2 Answers

Vertex Shader problem with _WorldSpaceCameraPos 1 Answer

How do I adapt this vertex manipulation shader so that my object (point cloud) keeps its original colouring? 0 Answers

shader for light replacement blending, instead of additive blending? 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