Mojo2 properly using new texture in shader

Monkey Forums/Monkey Programming/Mojo2 properly using new texture in shader

Soap(Posted February) [#1]
I was attempting to create a new texture slot in a material, but got a memory access violation. Not sure what was wrong. But if I just change the name to one of the existing slots such as NormalTexture it works fine and the shader works as I want it to. But I don't use the texture I loaded into the NormalTexture slot for normals, something else instead.

M.SetTexture("PixelTexture", P) doesn't work
M.SetTexture("NormalTexture", P) works

uniform sampler2D PixelTexture; doesn't work
uniform sampler2D NormalTexture; works

All I'm doing is changing the names and it suddenly works... what else am I missing? The texture is loading fine. The code is all the same but I assume there's something more needed for other named textures?


Soap(Posted February) [#2]
Found solution. It was missing proper initialization I suppose?

Class PixelShader Extends BumpShader 
	Private
	Global _Instance:PixelShader
	Public

	Function Instance:PixelShader()
		If (_Instance = Null) Then
			_Instance = New PixelShader()
		Endif
		
		Return _Instance
	End
	
	Method New()
		Build(LoadString("monkey://data/pixel.glsl"))
	End
	
	Method OnInitMaterial:Void(M:Material)
		Super.OnInitMaterial(M)
		
		M.SetTexture "PixelTexture", Texture.Flat()

		Return
	End
End


Key is

M.SetTexture "PixelTexture", Texture.Flat()

Then elsewhere

M.SetTexture("PixelTexture", P)

Properly works.