• 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 LyveIG · Feb 20, 2015 at 01:49 AM · shadercgglslgles

Cg Language incompatibility Desktop VS GLSL Android

Hi there,

today I came across a bug in one of my shaders. The following line caused the problem, but only on Android Mobile device:

 float3 side = step(3.0f, foo.xyz) * 3.0f;

The fix for this was the following:

 float3 side = step(float3(3,3,3), foo.xyz) * float3(3,3,3);

In the Unity3D Editor, even when GLES 2.0 emulation is enabled, the result is what I've expected. Each component of "side" contains 0 or 3 for each component of "foo" that is >= 3.

On mobile, each component of side contains 0 or 3 if foo.x is >= 3.

I do not get any "implicit truncation of vector type" warning in the log and also no warnings at all for any shader language in the shader properties.

I have searched the language specifications and found out that GLSL isn't capable to convert a single component float value to a vector type implicitly, or at least it isn't documented or I didn't find it.

But Cg is, which would mean that the generated code for HLSL/GLSL is wrong, but why only on mobile? According to the Cg spec, the first code portion should be okay, the first parameter of step() should be widened to be a float3 and the last multiplication should become a float3, too.

So who is wrong here? Did I misunderstand something, is there a bug in Cg or in Unity3D? Should I file a bug report with an example project?

Best,

Nils

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

CG shader is treated as GLSL and doesn't compile 0 Answers

Shardelab/CG shaders not working on iOS 1 Answer

How to force the compilation of a shader in Unity? 5 Answers

Grabpass refraction masking 0 Answers

How to prevent shader optimizations? 1 Answer


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