• 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 Lasseastrup3 · May 01, 2014 at 09:26 PM · graphicsrendertexturematerial colorgl

GL.Quads not correctly displaying color. It's all black

Hey I'm currently in a situation where I have several cameras in my scene, each with the TestClass script (se below) attached. Each of their textures (_texture) is being draw correctly on screen, but when I start adding elements in the Splatter dictionary the quads added are all black, regardless of what color I pass along. Why is that? I'm using a simple VertexLit shader.

What am I missing?

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using System.Diagnostics;
 
 [RequireComponent(typeof(Camera))]
 public class TestClass : MonoBehaviour
 {
     private Texture2D _texture;
     private Material _mat;
     private RenderTexture _renderTexture;
     public Dictionary<Vector2,Color> Splatter;
 
     void Awake()
     {
         Splatter = new Dictionary<Vector2, Color>();
     }
 
     public RenderTexture SetTexture(Texture2D tex, Material mat)
     {
         _mat = mat;
         _texture = tex;
         _renderTexture = new RenderTexture(tex.width,tex.height, 0);
         _renderTexture.generateMips = false;
         _renderTexture.filterMode = FilterMode.Point;
         _renderTexture.Create();
         Graphics.Blit(tex, _renderTexture);
         GetComponent<Camera>().targetTexture = _renderTexture;
         
         return _renderTexture;
     }
 
     public void OnPostRender()
     {
         Graphics.Blit(_texture, _renderTexture);
 
         GL.PushMatrix();
         
         GL.LoadPixelMatrix(0, _texture.width, _texture.height, 0);
 
         GL.Begin(GL.QUADS);
 
         foreach (var pos in Splatter)
         {
             GL.Color(pos.Value);
             GL.Vertex3(pos.Key.x, -pos.Key.y + _texture.height, 0);
             GL.Vertex3(pos.Key.x + 1, -pos.Key.y + _texture.height, 0);
             GL.Vertex3(pos.Key.x + 1, -pos.Key.y - 1 + _texture.height, 0);
             GL.Vertex3(pos.Key.x, -pos.Key.y - 1 + _texture.height, 0);
 
         } 
         GL.End();
         GL.PopMatrix();
     }
 }

I've done all of this as a way of manipulating a texture without using Texture2D.Apply().

Hope someone out there can help :)

Kind Regards Lasse

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

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

Graphics.DrawTexture vs GUI.DrawTexture vs Graphics.Blit 0 Answers

Shading with GL.TRIANGLE_STRIP 2 Answers

Alternative for Graphics.CopyTexture() ? 1 Answer

Rendering a screen aligned quad with Graphics.blit - not working? 0 Answers

Detect if cursor is over image.,How can I tell if I'm over a visible pixel on a RenderTexture? 0 Answers

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