DELETED

Форум для самых маленьких, а так же тех, кому недосуг читать справку самостоятельно.

Re: Skydome Проблема с новым эффектом плавного перехода

Сообщение waruiyume 15 май 2013, 21:43

Залип и сделал примерно то же, но с 2 текстурами.
Синтаксис:
Используется glsl
Shader "Custom/SkyDome"
{
        Properties
        {
                _CurrentTex ("Current (RGB)", 2D) = "white" {}
                _BlendTex ("BlendT (RGB)", 2D) = "white" {}
                _BlendPos ("Blend pos", float) = 0
                _Dir("Dir", float) = 1
        }
        SubShader
        {
                Tags { "RenderType"="Background" "IgnoreProjector"="True" }
               
                pass
                {
         CGPROGRAM
                 #pragma only_renderers d3d9 opengl
         #pragma vertex vert  
         #pragma fragment frag
 
         uniform sampler2D _CurrentTex;    
                 uniform sampler2D _BlendTex;
                 uniform fixed _BlendPos;
                 uniform fixed _Dir;

 
         struct vertexInput
                 {
            float4 vertex : POSITION;
            half4 texcoord : TEXCOORD0;
         };


         struct vertexOutput
                 {
            float4 pos : SV_POSITION;
            half4 tex : TEXCOORD0;
                        fixed texMulDir : TEXCOORD1;
         };
 
         vertexOutput vert(vertexInput input)
         {
            vertexOutput output;
            output.tex = input.texcoord;
            output.pos = mul(UNITY_MATRIX_MVP, input.vertex);

                        fixed2 texcoordFlipped = input.texcoord.xy;
                        if (_Dir<0)
                        {
                                texcoordFlipped = half2(1.0h, 1.0h) - texcoordFlipped;
                        }

                        output.texMulDir = (texcoordFlipped.x*texcoordFlipped.y*texcoordFlipped.y);

            return output;
         }


         float4 frag(vertexOutput input) : COLOR
         {
                        fixed4 cur = tex2D(_CurrentTex, input.tex.xy);
                        fixed4 blend = tex2D(_BlendTex, input.tex.xy);

            return
                                lerp
                                (
                                        cur, blend,      saturate(_BlendPos * (input.texMulDir*5.0h+1.0h) )
                                );
         }
 
         ENDCG
                }

        }
}

 


Синтаксис:
Используется csharp
using UnityEngine;

public class SkyController : MonoBehaviour
{

    public Texture2D[] skyTextures;

    private float t;

    public float speed = 0.5f;

    private int blendTexIndex;

    private Material mat;

    private int dir = 1;

    void Start()
    {
        blendTexIndex = 1;

        mat = renderer.sharedMaterial;

        mat.SetTexture("_CurrentTex", skyTextures[0]);
        mat.SetTexture("_BlendTex", skyTextures[1]);
        mat.SetFloat("_Dir", dir);
    }
       
        void Update ()
        {
            t += Time.deltaTime*speed;

        if (t >= 1f)
        {
            t = 0f;

            int newTexIndex = blendTexIndex == skyTextures.Length - 1 ? 0 : blendTexIndex + 1;

            mat.SetTexture("_CurrentTex", skyTextures[blendTexIndex]);
            mat.SetTexture("_BlendTex", skyTextures[newTexIndex]);

            dir = -dir;

            mat.SetFloat("_Dir", dir);

            blendTexIndex = newTexIndex;
        }

        mat.SetFloat("_BlendPos", t);
        }
}

 
Аватара пользователя
waruiyume
Адепт
 
Сообщения: 6143
Зарегистрирован: 30 окт 2010, 05:03
Откуда: Ростов на Дону

Re: Skydome Проблема с новым эффектом плавного перехода

Сообщение Woolf 15 май 2013, 21:46

Залип и сделал примерно то же, но с 2 текстурами.

Ну и скрипт и шейдер куда как более вменяемые. Ох уж эти индусские буржуи...

Только одно но..

Синтаксис:
Используется csharp
if (t >= 1f)  {
          t = 0f;
.....
if (t >= 1f)  {
            t =t-1f;


как-то так.
Разработчик theFisherOnline - там, где клюёт
Разработчик Atom Fishing II - Первая 3D MMO про рыбалку
Разработчик Atom Fishing - Рыбалка на поплавок, донку, нахлыст, блесну в постъядерный период.
Аватара пользователя
Woolf
Адепт
 
Сообщения: 7179
Зарегистрирован: 02 мар 2009, 16:59

Пред.

Вернуться в Почемучка

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 22