Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 merpnderp · Sep 16, 2013 at 09:32 PM · shadercgvertex shader

Swizzling cube face to other faces in the cube

This is a shader which take the front face of a cube and swizzles it to the other faces of the cube, or at least is supposed to. But no matter which directions I input for _WidthDir and _HeightDir it just shows the front face of the cube.

Anyone have any ideas?

 Shader "Custom/PlanetShader" {
 Properties {
 _Position ("Position", Vector) = (0,0,0,0)
 _WidthDir ("WidthDir", Vector) = (1,0,0,0)
 _HeightDir ("HeightDir", Vector) = (0,1,0,0)
 _Width ("Width", Float) = 1
 }
 SubShader {
 Pass{
 CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 #include "UnityCG.cginc"
  
 uniform float4 _Position;
 uniform float4 _WidthDir;
 uniform float4 _HeightDir;
 uniform float _Width;
  
 struct v2f{
 float4 pos : SV_POSITION;
 float2 uv : TEXCOORD0;
 };
  
 v2f vert(appdata_base v){
 v2f o;
 v.vertex = float4((_Position.xyz + ( (_WidthDir.xyz * v.vertex.x + _HeightDir.xyz * v.vertex.y) * _Width)).xyz, 1);
 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
 return o;
 }
  
 half4 frag(v2f i) : COLOR{
 return half4(.1,.1,1,.9);
 }
  
 ENDCG
 }
 }
 }
Comment
Add comment · Show 6
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 tanoshimi · Sep 17, 2013 at 12:33 PM 0
Share

Did you really mean "swizzle" (which has a particular meaning in computer graphics), or did you mean "blend", or "rotate", or perhaps something else?! Note that a shader applies to a material which is assigned to an entire object, not just one face of it, so I'm not quite sure how you're defining what the "front" face of your cube is and how you're going to "swizzle" that separately from the other faces?

I think both your problem description and code are confusing - perhaps you could draw a picture to illustrate what you'd like to see happen, and then it would be easier to help?

avatar image merpnderp · Sep 17, 2013 at 01:14 PM 0
Share

$$anonymous$$y mesh is just the front square face of the cube. I then assign this mesh to other mesh renderers and in the shader give each mesh renderer its own parameters to move the vertices to the correct location on the cube. $$anonymous$$y goal is to make a cube out of a single square mesh. This is the beginnings of a shader for a quadtree cubesphere procedural planet. Since I'm just rotating the cube face to a different face I thought the term swizzling applied, but apparently it doesn't since I'm not just rearranging the order of their values.

An update to the problem is when I hardcode the values in my shader I see the correct movement on the screen. It looks like when I call my$$anonymous$$eshRenderer.renderer.material.SetVector/float/whatever nothing actually gets passed to the shader. No idea what I'm doing wrong. Here's an example how I'm doing it:

GameObject prefab = _tree.sphere.GetPrefab();//Returns instantiated prefab with transform and parent set. $$anonymous$$eshRenderer mr =($$anonymous$$eshRenderer)prefab.GetComponent("$$anonymous$$eshRenderer"); mr.renderer.material.SetVector("HeightDir", _tree.heightDir);

avatar image tanoshimi · Sep 17, 2013 at 01:18 PM 0
Share

The problem with mr.renderer.material.SetVector("HeightDir", _tree.heightDir); is that your Shaderlab property is called _HeightDir, not HeightDir.

avatar image merpnderp · Sep 17, 2013 at 01:25 PM 0
Share

I thought that was supposed to match the string..... bummer. Thanks again.

If you cut and paste your comment as an answer I'll mark it as correct for the karma if you want.

avatar image tanoshimi · Sep 17, 2013 at 01:27 PM 0
Share

Ok, cheers - glad it helped ;)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Sep 17, 2013 at 01:27 PM

The problem with mr.renderer.material.SetVector("HeightDir", _tree.heightDir); is that your Shaderlab property is called _HeightDir, not HeightDir.

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

16 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

Related Questions

Where is model space origin in shaderlab? 1 Answer

UnityPixelSnap in custom vertex shader behaves differently to implementation in default sprite shader. 0 Answers

Parsing values in multipass cg shader 0 Answers

Vertex Shader Properties Issu 1 Answer

How to access other vertices in vertex shader? 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