Problem A:
No UV information appears to be sent, or maybe I'm accessing it wrong, I've temporarily got the uv mapping working based on vertex position in the vertex shader. But it's quite hackish.
Problem B:
Parsing textures to the uniforms in the fragment shader. I just can't figure it out. Below I've included my post processing class, and the shader, and anything else you possibly need to give me advice. It looks so simple in the base C++ version, outside of the wrapper, but there appears to be no entry point in IrrlichtLime.
PostProcess class (Puts all the post processing mundane stuff in one place). (Note the SetTexture function, probably wrong)
Code: Select all
/// <summary>
/// PostProcess class is based on QuadRender class, I lost reference to
/// </summary>
class PostProcess
{
IrrlichtDevice dev;
VideoDriver vid;
Material material;
Vertex3D[] vert;
ushort[] index;
ShaderCallBack shader;
public PostProcess(IrrlichtDevice device, string vertShader, string fragShader)
{
dev = device;
vid = device.VideoDriver;
shader = vid.GPUProgrammingServices.AddHighLevelShaderMaterialFromFiles(
vertShader, "main", VertexShaderType.VS_4_0,
fragShader, "main", PixelShaderType.PS_4_0,
MaterialType.DetailMap, 0, GPUShadingLanguage.Default);
if (shader == null) //if we got a shader callback (shader was created successfully)
{
Program.debug.LogText("Failed to load shader: " + vertShader + "/" + fragShader);
throw new Exception("Failed to load shader, check log for details");
} else
{
// material for screen quad
material = new Material();
material.Wireframe = false;
material.Lighting = false;
material.SetFlag(MaterialFlag.ZWrite, false);
material.Type = shader;
}
// screen quad
vert = new Vertex3D[4] {
new Vertex3D(-1, -1, 0, 0, 0, 1f, Color.OpaqueRed , 0, 1),
new Vertex3D(-1, 1, 0, 0, 0, 1, Color.OpaqueGreen, 0, 0),
new Vertex3D(1, 1, 0, 0, 0, 1, Color.OpaqueBlue, 1, 0),
new Vertex3D(1, -1, 0, 0, 0, 1, Color.OpaqueWhite, 1, 1),
};
index = new ushort[6]
{
0,1,2,
0,2,3
};
}
/// <summary>
/// Sets texture in shader
/// </summary>
/// <param name="id">Uniform ID location (I don't see any access to retrieving via name)</param>
/// <param name="tex">Texture to set in shader</param>
public void SetTexture(int id, Texture tex)
{
material.SetTexture(id, tex);
}
/// <summary>
/// Render, called during draw routine
/// </summary>
public void Render()
{
vid.SetMaterial(material);
vid.SetTransform(TransformationState.World, new Matrix());
vid.DrawVertexPrimitiveList(vert, index);
}
}
Code: Select all
while (device.Run())
{
Input.FrameUpdate();
if (device.WindowActive)
mainWorld.Update();
device.SceneManager.VideoDriver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140));
mainWorld.PreRender();
//Draw world to render target
driver.SetRenderTargetEx(worldRT, ClearBufferFlag.All, Color.OpaqueBlack);
mainWorld.physicsWorld.DebugDrawWorld();
device.SceneManager.DrawAll();
//Draw render targets plus post process to screen
driver.SetRenderTarget(null);
pp.SetTexture(0, mainWorld.GetWaterTexture());
pp.SetTexture(1, worldTex);
pp.SetTexture(2, mainWorld.GetWaterDepthTexture());
pp.SetTexture(3, worldDepth);
pp.Render();
device.GUIEnvironment.DrawAll();
driver.Draw2DImage(worldTex,
new Recti(0,0,128,128),new Recti(0,0,driver.ScreenSize.Width,driver.ScreenSize.Height));
driver.Draw2DImage(mainWorld.GetWaterTexture(),
new Recti(128, 0, 256, 128), new Recti(0, 0, driver.ScreenSize.Width, driver.ScreenSize.Height));
driver.Draw2DImage(worldDepth,
new Recti(256, 0, 384, 128), new Recti(0, 0, driver.ScreenSize.Width, driver.ScreenSize.Height));
driver.Draw2DImage(mainWorld.GetWaterDepthTexture(),
new Recti(384, 0, 512, 128), new Recti(0, 0, driver.ScreenSize.Width, driver.ScreenSize.Height));
device.SceneManager.VideoDriver.EndScene();
}
Code: Select all
#version 400
//Note these locations were worked out by trial & error
in layout(location=0) vec3 vp;
in layout(location=3) vec4 col;
in layout(location=2) vec3 nm;
in layout(location=1) vec2 uv;
out vec2 tex_coord;
void main() {
gl_Position = vec4(vp, 1.0);
//tex_coord = vec2((vp.x + 1.0) * 0.5,(vp.y + 1.0) * 0.5);//Works, but should be using line below
tex_coord = uv;//filled with 0,0
}
Code: Select all
#version 400
//Here's what I need to set, how do I go about it?
uniform sampler2D waterRT;
uniform sampler2D worldRT;
uniform sampler2D waterDepth;
uniform sampler2D worldDepth;
in vec2 tex_coord;
out vec4 frag_colour;
void main() {
vec4 water = texture(worldRT, tex_coord).rgba;
vec4 world = texture(waterRT, tex_coord).rgba;
float worD = texture(worldDepth, tex_coord).r;
float watD = texture(waterDepth, tex_coord).r;
frag_colour = world;
}