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 This-is-Cole · Mar 13, 2016 at 06:23 PM · shadershadersflippingdirectxgraphics card

Am I flipping this shader or is it a GPU problem?

Hi everyone, I have a custom shader here for water distortion but it flips my texture and I do not want it to. I'm not particularly skilled with the shader language as of yet, however I've heard that some GPUs have the tenancy to flip shaders based on where it thinks the origin point should be. I've tried different styles of rendering like with DX9 and 11, but nothing seemed to change. If I am in fact flipping the texture, could you show me where it is happening and how to fix it?

 Shader "Custom/Distort" {
 Properties {
  _Refraction ("Refraction", Range (0.00, 100.0)) = 1.0
  _DistortTex ("Base (RGB)", 2D) = "white" {}
 }
 
 SubShader {
  
  Tags { "RenderType"="Transparent" "Queue"="Overlay" }
  LOD 100
  
  GrabPass
  {
   
  }
  
 CGPROGRAM
 #pragma surface surf NoLighting
 #pragma vertex vert
 
 fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten){
         fixed4 c;
         c.rgb = s.Albedo;
         c.a = s.Alpha;
         return c;
   }
 
 sampler2D _GrabTexture : register(s0);
 sampler2D _DistortTex : register(s2);
 float _Refraction;
 
 float4 _GrabTexture_TexelSize;
 
 struct Input {
  float2 uv_DistortTex;
  float3 color;
  float3 worldRefl;
  float4 screenPos;
  INTERNAL_DATA
 };
 
 void vert (inout appdata_full v, out Input o) {
   UNITY_INITIALIZE_OUTPUT(Input,o);
   o.color = v.color;
 }
 
 void surf (Input IN, inout SurfaceOutput o) {
 
     
     float3 distort = tex2D(_DistortTex, IN.uv_DistortTex) * float3(IN.color.r,IN.color.g,IN.color.b );
     float2 offset = distort * _Refraction * _GrabTexture_TexelSize.xy;
     IN.screenPos.xy = offset * IN.screenPos.z + IN.screenPos.xy; 
     float4 refrColor = tex2Dproj(_GrabTexture, IN.screenPos);
     o.Alpha = refrColor.a;
     o.Emission = refrColor.rgb;
 
 }
 ENDCG
 }
 }
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
2
Best Answer

Answer by tanoshimi · Mar 13, 2016 at 06:45 PM

I'd suggest you use UNITY_UV_STARTS_AT_TOP as described here: http://docs.unity3d.com/Manual/SL-PlatformDifferences.html

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 This-is-Cole · Mar 14, 2016 at 10:56 PM 0
Share

Thanks for the quick response! So upon reading this, I decided to try turning off Unity's antialiasing in the quality settings. This didn't change anything. So I tried adding antialiasing from the camera (which I was likely going to do at some point anyway,) and this fixed it! I don't know if this solves the problems across all GPUs running OpenGL and DX, and I can't figure out where to put the logic to flip it automatically in my code. Regardless it fixed what I was looking to fix for now, I'll read further into it if I find it doesn't work across different GPUs.

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

55 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

Related Questions

How to use mesh data in shader 0 Answers

Change shader properties during rungtime 1 Answer

How to detect DirectX 12? 0 Answers

Shader Programming Course 2 Answers

Is it possible to avoid writing to certain g-buffers? 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