• 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 Iconic · Mar 11, 2013 at 08:44 PM · projectortilingresizing

Resizing a projector and tiling texture?

I've made a projector for an underwater caustics effect but it only projects on a small portion of the map. It would not tile and if I took it out of orthographic view it would stretch the texture. Ideas?

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

Answer by Ian McCabe · Feb 23, 2014 at 03:41 AM

Hey, try using this

Shader "Projector/Caustics" {

 Properties {
    _Color ("Color", Color) = (1,1,1,0)
    _ShadowTex ("Cookie", 2D) = "black" { TexGen ObjectLinear }
    _Size ("Grid Size", Float) = 1
 }
 
 Subshader {
    Tags { "RenderType"="Transparent" "Queue"="Transparent+100" }
    Pass {
      ZWrite Off
      Offset -1, -1
      Fog { Mode Off }
      //ColorMask RGB
      //Blend SrcAlpha OneMinusSrcAlpha
      Blend DstColor One

 
      CGPROGRAM
      #pragma vertex vert
      #pragma fragment frag
      #pragma fragmentoption ARB_fog_exp2
      #pragma fragmentoption ARB_precision_hint_fastest
      #include "UnityCG.cginc"
 
      struct v2f {
       float4 pos : SV_POSITION;
       float2 uv : TEXCOORD0;
      };
 
      uniform sampler2D _ShadowTex;
      float4 _ShadowTex_ST;
      float4 _Color;
      float4x4 _Projector;
      fixed _Size;
 
      v2f vert (appdata_tan v) {
       v2f o;
       o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
       o.uv = TRANSFORM_TEX (mul (_Projector, v.vertex).xy, _ShadowTex);
       return o;
      }
 
      fixed4 frag (v2f i) : COLOR {
       if (i.uv.x < 1 && i.uv.y < 1)
           return tex2D (_ShadowTex, fmod (i.uv, 1 / _Size) * _Size) * _Color;
       else
           return fixed4 (0,0,0,0);
      }
 
      ENDCG
    }
 }

}

I just modified it slightly from this script developed here on this thread: http://answers.unity3d.com/questions/520207/projector-repeating-texture-using-custom-shader.html

It works fairly well for orthographic caustics.

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.

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

11 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

Related Questions

Change material tiling according to loaded texture size in CS 0 Answers

Projector + custom fragment shader = endless texture draw 2 Answers

Blob Shadow Dynamic FarClipPlane Distance 0 Answers

BlobShadowProjector see nothing . 0 Answers

Projector stops working on Terrain with "Draw Instanced" enabled 5 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges