GL issue in webplayer

This really bugs me.

I draw shapes using the GL class with no problem, but when I export to webplayer the shapes are gone(!).

This might be an issue with the shader I use. By experimenting I found that changing the Pixel Light Count in the Quality Setting has an influence. Also whether I use my own shader using GL.SetPass() or use the default (no SetPass) makes a difference.

Any quick fixes to this issue?
Any help is greatly appreciated!

~ce

(the circle is made of GL lines)

private Vector2[] lines;
private Material material = null;

void Start(){
	InitLines();
	material = new Material( Shader.Find( "ce/Draw" ) );
}

void OnRenderObject(){	
	material.SetPass( 0 );
	GL.LoadPixelMatrix();
	
	GL.Begin( GL.LINES );
	GL.Color( Color.white );
	for( int i=0; i<lines.Length; i++ ) GL.Vertex3( lines[i].x, lines[i].y, 0 );
	GL.End();
}


void InitLines(){
	// instantiating an array of Vector2D's in the shape of a circle
}

The shader I use:

Shader "ce/Draw" {
	Properties {
		_MainTex ("Font Texture", 2D) = "white" {}
		_Color ("Text Color", Color) = (1,1,1,1)
	}

	SubShader {
		Tags {"Queue" = "Overlay"}
		Lighting Off ZTest Always ZWrite Off Fog { Mode Off }
		Blend SrcAlpha OneMinusSrcAlpha
		Pass {
			Color [_Color]
			SetTexture [_MainTex] {
				combine primary, texture * primary
			}
		}
	}
}

The project can be downloaded here:
http://sixthsensor.dk/temp/unityforum/GLPixellights.zip

The reason it does not work in web player is because the shader is not included in the build (there’s a null reference exception in the player output log).

The reason shader is not included in the build is because there are no assets or references that use it, so when Unity builds the game it does not include the shader. If I change

material = new Material( Shader.Find( "ce/Draw" ) );

to

public Shader shader;
// ...
material = new Material( shader );

and assign the shader in Inspector, then it all works. The alternative would be to place shader in Assets/Resources folder (everything in Resources is included in the build).

My guess is that the reason why it worked with no SetPass is that whatever previously set shader just happened to work correctly for your lines. But that is very unpredictable; what happens to be previous shader can change depending on other objects, lights and whatnot.

Thank you so much! I’ll use the Resources folder since I instantiate everything in runtime.

I didn’t know about the Player log, very useful!

~ce

I found another solution to the problem:
– Create a new Material.
– Use the shader you want to be included in the build on that material.
– Create a new Prefab and attatch the new material.

EDIT:
Argh man! I got carried away an oversaw something. This trick didn’t work =(
The player builder does it’s cleaning well.