Loading an OBJ coming out black

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi Cutealien,

Thanks for the help. I only used directional lights because it was one of your suggestions. I was quite happy with the point light.
So for this project I am just going change it back to a point light and put a few point lights at the sides to light up the sides of my models.

I do want to learn HLSL shaders. Have downloaded FX Composer but haven't found a decent tutorial on making a shader yet.
At the moment shaders seem like rocket science heh heh.

I also have to work out how to get coordinates from a mouse click on my board as well next, so that the player can buy streets.
I don't think I have picked the easest game to start with LOL.
CuteAlien
Admin
Posts: 9645
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

About those "few" lights - the limit in this case (with those materials and without writing your own shader) - is 2 lights.

As for shader tutorials - I think the easiest is really to look at a shader first. I'll give a tiny intro just to show it's not that scary:
Start with media/d3d9.hlsl which doesn't do much besides rendering the model + texture and adding a tiny color manipulation. If you take a look - it's not much code. It has a vertex shader (vertexMain) which will run for every vertex send to the card and a pixel shader (pixelMain) which will run for every pixel on your screen (or every pixel on your target-texture when not rendering to screen but to rendertargettextures). All global variables (called uniforms in opengl) are send each frame from the cpu to gpu with some c++ code (Irrlicht example shows how to send variables from c++ to shader). Vertex shader can use those globals (globals are constant and have the same values for every vertex in a meshbuffer in a single frame). The input to vertex shaders is defined by the vertex-format (it's the vertex-buffer arrays). You can just copy-paste that part, but when using another vertex-format do ask (there's only 3 formats in Irrlicht so we should add examples for all 3 maybe...) . VS_OUTPUT is vertex shader results which are send to pixel-shader (called fragment shader in opengl) - and there used as pixel-shader input. It's the input-vertex transformed into screen-space + some texture coordinates and often additional color informations. The graphic card does the clipping/depth-tests automatically for your transformed vertices so the pixel shaders only receive those pixels which need rendering. For triangles pixel has 3 vertex inputs - those are automatically interpolated, so you get a single input (which messes up normals so they need to be normalized again). And pixel-shader return then a color (for that pixel). Samplers are used to access textures. The rest is math (the hard part really - but lots of help for that on the web, thought if you are not very familiar with coordinate-space transformations it's going to be hard). Once you need certain typical math functions you might take a look the hlsl/glsl documentation if those functions are there already - sometimes it is.

Some additional variable-types compared to c and you shouldn't use much code (especially be careful not to use many loops and if's as they are expensive). But basically it looks the same as c code.

Can't help with rocket science - still struggling with that one :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi CuteAlien,
It would be a shame to have to use another engine when I have learnt so much about this one.
In fact I came to irrlicht after trying many engines and not getting on with them.
I did quite well with unity, but I prefer C++ to C#;

I have started reading about HLSL but it is hard to find good tutorials on it.
I have created a very simple shader, and got it to work in max, but it is a lot to learn LOL, and I have no idea if it will work in irrlicht yet.

I understand how to make the structs, and stuff to set up the shader, but get a bit foggy on the vertex function.
Hopefully I can learn this soon because I need normalmaps and more lights LOL
CuteAlien
Admin
Posts: 9645
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

Sorry, I hope I can add better shader examples soon (please don't wait for that, I'm not sure if it will work out as it's also not exactly my speciality and our project's needs are also somewhat different. Plus I'm still busy with a non-Irrlicht project for a little while).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi CuteAlien,

Just a thought. Wouldn't it be a good idea to have a shader library on the irrlicht site. I am sure a lot of people have already written nice shaders, which of course could be modified, and shader text files don't take a lot of room. I have been playing with fx composer, but haven't got very far. I am messing with an HLSL shader which has only one light source at the moment, unfortunately the tutorial I have been following is a little thin on knowledge and I am not sure how to add extra lights as of yet. Also I am not sure if a point light is the same as an omni light in max either.

If anyone else is reading this and can point me in the right direction for some decent tutorials I would be very happy.
I am afraid my game is on hold until I can learn how to do shaders. I think I will need a metal shader as well, because my pieces will be like a dull chrome material as well.
As soon as I have got the shaders licked I have to build all the pieces in max, which should be fun.

PS. The only good tutorial I have found so far is for XNA and it don't quite work very well in fx composer grr. Will carry on looking

PPS. Just found a tool in 3ds Max called shaderFX which is a node based shader creator for games. It does export to hlsl3 or hlsl5. I am not sure if these are compatible with irrlicht yet. Going to have to try the irrlicht shader tutorial and see if it works.
Post Reply