public void ReadTextureParams(byte[] raw)
 {
     int count = BitConverter.ToInt32(raw, 24);            
     int pos = 28;
     for (int i = 0; i < count; i++)
     {
         List<PropertyReader.Property> tp = PropertyReader.ReadProp(pcc, raw, pos);
         string name = pcc.getNameEntry(tp[1].Value.IntValue);
         int Idx = tp[2].Value.IntValue;
         TextureParam t = new TextureParam();
         t.Desc = name;
         t.TexIndex = Idx;
         if (name.ToLower().Contains("diffuse") && Idx >0)
         {
             Texture2D tex = new Texture2D(pcc, Idx - 1);
             string loc = Path.GetDirectoryName(Application.ExecutablePath);
             Texture2D.ImageInfo inf = new Texture2D.ImageInfo();
             for (int j = 0; j < tex.imgList.Count(); j++)
                 if (tex.imgList[j].storageType != Texture2D.storage.empty)
                 {
                     inf = tex.imgList[j];
                     break;
                 }
             if (File.Exists(loc + "\\exec\\TempTex.dds"))
                 File.Delete(loc + "\\exec\\TempTex.dds");
             tex.extractImage(inf, ME3Directory.cookedPath, loc + "\\exec\\TempTex.dds");
             if (File.Exists(loc + "\\exec\\TempTex.dds"))
                 try
                 {
                     t.Texture = TextureLoader.FromFile(Meshplorer.Preview3D.device, loc + "\\exec\\TempTex.dds");
                 }
                 catch (Direct3DXException e)
                 {
                 }
             else
                 t.Texture = null;
         }
         else
             t.Texture = null;
         Textures.Add(t);
         pos = tp[tp.Count -1].offend;
     }
 }
Esempio n. 2
0
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            // Debug.LogError(" input no ready");
            return(false);
        }
        TextureParam input  = null;
        TextureParam input2 = null;

        if (Inputs[0].connection != null)
        {
            input = Inputs[0].connection.GetValue <TextureParam>();
        }
        if (Inputs[1].connection != null)
        {
            input2 = Inputs[1].connection.GetValue <TextureParam>();
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(m_TexWidth, m_TexHeight);
        }
        if (input == null || input2 == null)
        {
            return(false);
        }

        if (m_Param != null)
        {
            switch (m_OpType)
            {
            case TexOp.Distort:
                Distort(input, input2, m_Param);
                break;

            case TexOp.Blend:
            {
                Material mat = GetMaterial("TextureOps");
                mat.SetVector("_Multiply", new Vector4(m_Value, m_Value, m_Value, 0));
                General(input, input2, m_Param, ShaderOp.Blend2);
            }


            break;

            case TexOp.EdgeDistDir:
            {
                Material mat = GetMaterial("TextureOps");
                mat.SetVector("_Multiply", new Vector4(m_Value, m_Value2, m_Value, 0));
                General(input, input2, m_Param, ShaderOp.EdgeDistDir);
            }
            break;

            case TexOp.Gradient:
                Gradient(input, input2, m_Param);
                break;

            case TexOp.Add:
                General(input, input2, m_Param, ShaderOp.Add2);
                break;

            case TexOp.Min:
                General(input, input2, m_Param, ShaderOp.Min);
                //Add(input, input2, m_Param);
                break;

            case TexOp.Max:
                General(input, input2, m_Param, ShaderOp.Max);
                //Add(input, input2, m_Param);
                break;

            case TexOp.Multiply:
                General(input, input2, m_Param, ShaderOp.Mult2);
                break;

            case TexOp.Power:
                General(input, input2, m_Param, ShaderOp.Pow2);
                break;

            case TexOp.Sub:
                General(input, input2, m_Param, ShaderOp.Sub2);
                //Add(input, input2, m_Param);
                break;

            case TexOp.DirectionalWarp:
            {
                Material mat = GetMaterial("TextureOps");
                mat.SetVector("_Multiply", new Vector4(m_Value, 0, m_Value2, 0));
                General(input, input2, m_Param, ShaderOp.DirectionWarp);
            }
            break;

            case TexOp.SrcBlend:
            {
                Material mat = GetMaterial("TextureOps");
                mat.SetVector("_Multiply", new Vector4(m_Value, m_Value, m_Value, 0));
                General(input, input2, m_Param, ShaderOp.SrcBlend);
            }
            break;

            default:
                Debug.LogError(" un defined texture 2 base op");
                break;
            }
            //m_Cached = m_Param.GetHWSourceTexture();
            CreateCachedTextureIcon();
        }

        //m_Cached = m_Param.CreateTexture();
        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }
Esempio n. 3
0
    protected Texture2D gradientX;// = new Texture2D(256, 1, TextureFormat.ARGB32, false);
    public void ExecuteRemapCurve(float _size, TextureParam _output)
    {
        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
        timer.Start();
        Material mat = GetMaterial("TextureOps");

        mat.SetInt("_MainIsGrey", m_TexMode == TexMode.Greyscale ? 1 : 0);
        mat.SetInt("_TextureBIsGrey", 1);
        mat.SetVector("_Multiply", new Vector4(1, 1, 0, 0));

        AnimCurveToTexture(ref gradientX, m_Gradient);

//        m_TexMode=TexMode.Greyscale;
        RenderTexture destination = _output.CreateRenderDestination(m_TexWidth, m_TexHeight, TextureParam.GetRTFormat(m_TexMode == TexMode.Greyscale));

        SetCommonVars(mat);
        Graphics.Blit(gradientX, destination, mat, (int)ShaderOp.CopyRGBA);


//        Debug.LogError(" multiply in Final" + timer.ElapsedMilliseconds + " ms");
    }
Esempio n. 4
0
 void SetParam(TextureParam p, int val)
 {
     MakeCurrent();
     GL.TexParameterI(BindTarget, p, val);
 }
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            return(false);
        }

        if (m_Output == null)
        {
            return(false);
        }
        TextureParam input = null;

        if (Inputs[0].connection != null)
        {
            input = Inputs[0].connection.GetValue <TextureParam>();
        }
        if (input == null)
        {
            return(false);
        }
        TextureParam input2 = null;
        int          index2 = 1;

        if (Inputs.Count < 2)
        {
            index2 = 0;
        }

        if (Inputs[index2].connection != null)
        {
            input2 = Inputs[index2].connection.GetValue <TextureParam>();
        }
        if (input2 == null)
        {
            return(false);
        }
        //input.DestinationToTexture(m_Output);



        if (m_Output.width != input.m_Width)
        {
            Texture2D texture = new Texture2D(input.m_Width, input.m_Height, TextureFormat.ARGB32, false);
            EditorUtility.CopySerialized(texture, m_Output);
            AssetDatabase.SaveAssets();
        }

        //m_Output.width = 256;
        //m_Output.height = 256;
        //int x = 0, y = 0;
        if (m_Output.format != TextureFormat.ARGB32 && m_Output.format != TextureFormat.RGBA32 && m_Output.format != TextureFormat.RGB24)
        {
            Debug.LogError(" Ouput Texture " + m_Output + "wrong Format " + m_Output.format);
        }
        else
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();

            /*
             *          float minred=float.MaxValue, maxred=float.MinValue;
             *          float minalpha = float.MaxValue, maxalpha = float.MinValue;
             *          for (int x = 0; x < input.m_Width; x++)
             *          {
             *              for (int y = 0; y < input.m_Height; y++)
             *              {
             *                  Color col = input.GetCol(x, y);
             *                  col.a = col.r;
             *                  minred = Mathf.Min(minred, col.r);
             *                  maxred = Mathf.Max(maxred, col.r);
             *                  minalpha = Mathf.Min(minalpha, col.a);
             *                  maxalpha = Mathf.Max(maxalpha, col.a);
             *                  m_Output.SetPixel((int)(((float)x / (float)input.m_Width) * m_Output.width), (int)(((float)y / (float)input.m_Height) * m_Output.height), col);
             *                  //m_Param.Set(x, y, col.r, col.g, col.b, 1.0f);
             *              }
             *          }
             */
            RenderTexture rt = new RenderTexture(m_Output.width, m_Output.height, 0, RenderTextureFormat.ARGB32);

            Material m = GetMaterial("TextureOps");
            m.SetInt("_MainIsGrey", input.IsGrey() ? 1 : 0);
            m.SetInt("_TextureBIsGrey", input2.IsGrey() ? 1 : 0);
            m.SetTexture("_GradientTex", input2.GetHWSourceTexture());
            string          path     = AssetDatabase.GetAssetPath(m_Output);
            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(path);
            if (importer.textureType == TextureImporterType.NormalMap)
            {
                Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyNormalMap);
            }
            else
            {
                Graphics.Blit(input.GetHWSourceTexture(), rt, m, (int)ShaderOp.CopyColorAndAlpha);
            }


            RenderTexture.active = rt;
            m_Output.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
            //input.DestinationToTexture(m_Output);
            m_Output.Apply();
            RenderTexture.active = null;
            rt.DiscardContents();
            rt.Release();
            rt = null;



//            Debug.Log("applied output to "+ m_Output+" time: "+timer.ElapsedMilliseconds+" ms res: "+input.m_Width+" minred "+minred+" max red "+maxred + " minalpha " + minalpha + " max alpha " + maxalpha);
        }


        //Outputs[0].SetValue<TextureParam> (m_Param);
        return(true);
    }
Esempio n. 6
0
    private static void SetPixels(int x, int y, Params param, TextureParam tParam, SliceType type)
    {
        switch (type)
        {
        case SliceType.Slice9:

            if (IsBottomLeft(x, y, param))
            {
                SetPixelsBL(x, y, tParam);
            }
            else if (IsLeft(x, y, param))
            {
                SetPixelsLeft(x, y, param, tParam);
            }
            else if (IsTopLeft(x, y, param))
            {
                SetPixelsTL(x, y, param, tParam);
            }
            else if (IsBottom(x, y, param))
            {
                SetPixelsBottom(x, y, param, tParam);
            }
            else if (IsBottomRight(x, y, param))
            {
                SetPixelsBR(x, y, param, tParam);
            }
            else if (IsRight(x, y, param))
            {
                SetPixelsRight(x, y, param, tParam);
            }
            else if (IsTopRight(x, y, param))
            {
                SetPixelsTR(x, y, param, tParam);
            }
            else if (IsTop(x, y, param))
            {
                SetPixelsTop(x, y, param, tParam);
            }
            else
            {
                SetPixelsCenter(x, y, param, tParam);
            }
            break;

        case SliceType.SliceLR:
            if (IsLeft(x, y, param))
            {
                SetPixelsBL(x, y, tParam);
            }
            else if (IsRight(x, y, param))
            {
                SetPixelsBR(x, y, param, tParam);
            }
            else
            {
                SetPixelsBottom(x, y, param, tParam);
            }
            break;

        case SliceType.SliceTB:
            if (IsTop(x, y, param))
            {
                SetPixelsTL(x, y, param, tParam);
            }
            else if (IsBottom(x, y, param))
            {
                SetPixelsBL(x, y, tParam);
            }
            else
            {
                SetPixelsLeft(x, y, param, tParam);
            }
            break;

        default:
            break;
        }
    }
Esempio n. 7
0
 protected RenderTexture CreateRenderDestination(TextureParam _output)
 {
     return(_output.CreateRenderDestination(m_TexWidth, m_TexHeight, TextureParam.GetRTFormat(m_TexMode == TexMode.Greyscale)));
 }
Esempio n. 8
0
    private static void SetPixelsBR(int x, int y, Params param, TextureParam tParam)
    {
        int sourceX = x + tParam.sourceTex.width - param.destWidth;

        tParam.destPix[y * tParam.destTex.width + x] = tParam.sourceTex.GetPixel(sourceX, y);
    }
Esempio n. 9
0
    private static void SetPixelsTL(int x, int y, Params param, TextureParam tParam)
    {
        int sourceY = y + tParam.sourceTex.height - param.destHeight;

        tParam.destPix[y * tParam.destTex.width + x] = tParam.sourceTex.GetPixel(x, sourceY);
    }
Esempio n. 10
0
 /// <summary>
 ///  SetPixes Bottom Left 左下角设置Pixels
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="param"></param>
 private static void SetPixelsBL(int x, int y, TextureParam tParam)
 {
     tParam.destPix[y * tParam.destTex.width + x] = tParam.sourceTex.GetPixel(x, y);
 }
Esempio n. 11
0
    public void Blend(TextureParam _input, TextureParam _inputB, TextureParam _inputC, TextureParam _output)
    {
        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
        timer.Start();

        Material mat = GetMaterial("TextureOps");

        mat.SetInt("_MainIsGrey", _input.IsGrey() ? 1 : 0);
        mat.SetInt("_TextureBIsGrey", _inputB.IsGrey() ? 1 : 0);
        mat.SetTexture("_GradientTex", _inputB.GetHWSourceTexture());
        mat.SetTexture("_GradientTex2", _inputC.GetHWSourceTexture());
        mat.SetVector("_TexSizeRecip", new Vector4(1.0f / (float)_inputB.m_Width, 1.0f / (float)_inputB.m_Height, m_Value, m_Value2));
        mat.SetVector("_Multiply", new Vector4(m_Value, m_Value1, m_Value2, 0.0f));
        SetCommonVars(mat);
        CalcOutputFormat(_input);
        RenderTexture destination = CreateRenderDestination(_input, _output);

        Graphics.Blit(_input.GetHWSourceTexture(), destination, mat, (int)ShaderOp.MaskedBlend);

        //output.TexFromRenderTarget();

        //RenderTexture.ReleaseTemporary(destination);
        //        Debug.LogError(" Distort in Final" + timer.ElapsedMilliseconds + " ms");
    }
Esempio n. 12
0
    public override bool Calculate()
    {
        if (!allInputsReady())
        {
            //Debug.LogError(" input no ready");
            return(false);
        }
        TextureParam input = null;

        if (Inputs[0].connection != null)
        {
            input = Inputs[0].connection.GetValue <TextureParam>();
        }
        if (m_Param == null)
        {
            m_Param = new TextureParam(m_TexWidth, m_TexHeight);
        }
        if (input == null)
        {
            Debug.LogError(" input null");
        }
        float[] values = { m_Value1, m_Value2, m_Value3 };
        float[] gauss  = { 0.0585f, 0.0965f, 0.0585f, 0.0965f, 0.1591f, 0.0965f, 0.0585f, 0.0965f, 0.0585f };

        if (input != null && m_Param != null)
        {
            switch (m_OpType)
            {
            case TexOP.Add:
                General(m_Value1, m_Value2, m_Value3, input, m_Param, ShaderOp.AddRGB);
                break;

            case TexOP.Min:
                General(m_Value1, m_Value2, m_Value3, input, m_Param, ShaderOp.Min1);
                break;

            case TexOP.Max:
                General(m_Value1, m_Value2, m_Value3, input, m_Param, ShaderOp.Max1);
                break;

            case TexOP.ClipMin:
                General(m_Value1, m_Value2, m_Value3, input, m_Param, ShaderOp.clipMin);
                break;

            case TexOP.Multiply:
                General(m_Value1, m_Value2, m_Value3, input, m_Param, ShaderOp.MultRGB);
                break;

            case TexOP.Power:
                General(m_Value1, m_Value2, m_Value3, input, m_Param, ShaderOp.Power);
                break;

            case TexOP.Level1:
                float mult = (m_Value2 - m_Value1);
                float add  = m_Value1;
                General(mult, add, m_Value3, input, m_Param, ShaderOp.Level1);
                break;

            case TexOP.Transform:
                float cos = Mathf.Cos(m_Value1) * m_Value2;
                float sin = Mathf.Sin(m_Value1) * m_Value2;
                General(cos, sin, m_Value3, input, m_Param, ShaderOp.Transform);
                break;

            case TexOP.Gradient:
                Gradient(input, m_Param);
                break;
            }
        }
        CreateCachedTextureIcon();
        //m_Cached = m_Param.GetHWSourceTexture();
        Outputs[0].SetValue <TextureParam> (m_Param);
        return(true);
    }