Custom shaders

mianiak

Is there any info around that I could read to help me get a kick start in making custom shaders? I have tried google but so far I have had no luck in finding anything. I have been spending a bit of time looking through default shaders and getting to know them. I am at the stage where now if I had a little bit of guidance I could nail it.

Cheers!
 
Hmm. Writing custom shaders is not like draw few lines in Photoshop. It is programming.
You have to know language and architecture. It's simply not for everyone job.
After that you have to know what you want to get as a result. If you don't want to draw procedural chequered texture but realize some real-life phenomena using shaders, you should be skilled in mathematics as well as have idea how to represent phenomena using algorithms and available architecture.

Finally rF1, even if using DX9c (DX9c supports Shader model 3.0), makes use of Shader Model 2.0 which is very limited.

If google is not enough for you, I doubt you will be able to write a shader.
Don't make me wrong. I'm trying to be honest.
 
Last edited:
Thanks for replying Maxym, but I think you misunderstood my question, I asked if anyone knew of any information they could share on how to make them. I didn't ask for a lecture on how hard they are to make :)
 
Let me expand a little bit on my question, sorry if it was a bit vague, I was very tired when I posted it.
I searched google for custom shaders for rfactor. I found heaps about shaders and how to write them and I can relate that information to rfactor shaders. But what I'm looking for is like a circuit board diagram on how they work.
 
First question is - are you a shader developer?
If not, then you're in the wrong forum - you should start with DXSDK, probably Render Monkey, and tutorials.

Of course first read full HLSL reference. This is no joke. I've read full GLSL specification before I started to play with samples and tutorials and I had lot of experience with 3D programming on various platforms.
 
Last edited:
There is a lot involved in all that eh, probably a bit too much than what I was looking for. Maybe I used the wrong wording, but what I'm mostly after is to customise existing shaders.
For a start, I want to remove the bump map from this car shader [Bump Cube Specular Map Add Alpha Reflect T1] I want to change it to [Cube Specular Map Add Alpha Reflect T1]
 
There is a lot involved in all that eh, probably a bit too much than what I was looking for. Maybe I used the wrong wording, but what I'm mostly after is to customise existing shaders.
For a start, I want to remove the bump map from this car shader [Bump Cube Specular Map Add Alpha Reflect T1] I want to change it to [Cube Specular Map Add Alpha Reflect T1]

That is not so hard to do. In fact I made this very shader, but if you look for example at the fresnel shader and ISI supplied shaders you can work this out if comfortable with code without too much understanding.

This stuff is not easy mind as said to take it to the next level. If you want to learn an interactive way I found shaderFx to be useful too. In a way these graphical representation programs like render monkey and ShaderFx are very useful, as you can make the basis of any shader, recompile/debug and see the result in a viewport, play around with the lighting formulae and see how it effects the results, so you develop a feel.

If you are math comfy a lot of these things you can almost visualise from the formulae after some time, at least the simpler cases, BUT ultimately these programs are not a replacement in the hope that you can just plug and play shaders, optimisation and efficient shaders are important, and for that learning to code they are not a substitute, well, not for strictly realtime stuff anyway IMHO.

It is also useful to delf in the DX SDK work through the samples and learn HLSL that way, to see how your app calls shaders and its interaction with the application, namely DX in this case.

If you know C anyway as I did already it helps a lot with the learning curve, even with that, personally coming more from a completely non-graphical background from many moons ago, you know, old school text based interfaces with your own makefiles and early versions of UNIX when vi and emacs were the kings of editors :) I find this a lot of work and hefty change with new stuff to learn, perhaps I am getting a bit old and my head is not as quick as it once was ^^

I suspect it will be a few years before I can say I am anyway fluent in this stuff yet, all a learning process, though I find it fascinating. As long as you don't expect immediate results tomorrow and enjoy learning, great stuff :)

I also found this book a very good buy,

Essential Mathematics for Games and Interactive Applications, A Programmers Guide

but that may be my view and background, it may not be the right book for everyone, but I almost always prefers the math algorithm explanation of something as supposed to the programmers explanation that tend to skim the math and theory. Good bedtime reading, though it uses glsl as base but that doesn't change the underlying theory.

All in all, there is a lot of actual physics & math behind that helps to learn and understand it. Jut for your interest, in my case a long way back I decided that 3D is the area of interest for me in rF over physics, that whilst the car physics ( unfortunately, but understandably ) in the engine is fixed in terms of code ( No, I am not ignoring the plugin interface, but you know what I mean), for the artist there is no such limitation with rF to extend it through code with its shader based approach, and I can't afford rF Pro to play around with :p
 
Last edited:
There is a lot involved in all that eh, probably a bit too much than what I was looking for. Maybe I used the wrong wording, but what I'm mostly after is to customise existing shaders.
For a start, I want to remove the bump map from this car shader [Bump Cube Specular Map Add Alpha Reflect T1] I want to change it to [Cube Specular Map Add Alpha Reflect T1]
Well, removing/adding bumpmapping to a shader is not an easy task, because there is a different math behind these two types of shaders.
It would be better if you try to modify some other non-bumpmap shader.

What you need is to create new .GFX file in GameData/Shared folder and copy one shader definition there.
Then you must copy pixel and vertex shader source code files under new name.
Now you edit .GFX file:
-change main shader name
-change names of main functions in both vertex and fragment shader definitions
-change filenames in both vertex and fragment shader definitions
Now you can edit source code files - start with changing main fnction names according to what you've put in .GFX file.

Thet's more less what needs to be done in rFactor. The rest is C-programming and HLSL programming.
 
Thanks for taking the time to type out that lengthy reply Afborro!
That pretty well sums it all up in one and I can relate to a lot of what you say.
I understand a little bit about coding and I have played with C in the past, but it's not my thing and I'm not a s/w dev, but what I know is enough to get me through most situations that require it and mathematics comes easy to me. So I will see how I go.

I just noticed that fresnel shader in my list so I will go have a look at that and compare it to the isi shaders.

Once again thank you for the reply, it is exactly what I was looking for.

Cheers!
 
Well, removing/adding bumpmapping to a shader is not an easy task, because there is a different math behind these two types of shaders.
It would be better if you try to modify some other non-bumpmap shader.

What you need is to create new .GFX file in GameData/Shared folder and copy one shader definition there.
Then you must copy pixel and vertex shader source code files under new name.
Now you edit .GFX file:
-change main shader name
-change names of main functions in both vertex and fragment shader definitions
-change filenames in both vertex and fragment shader definitions
Now you can edit source code files - start with changing main fnction names according to what you've put in .GFX file.

Thet's more less what needs to be done in rFactor. The rest is C-programming and HLSL programming.

Ahhh, I see what you mean, a shader is not just a few levels put together that can be cut and pasted and swapped around, it's a dedicated shader related to the effect, in this case a bump map shader is based around bump, where a cube map shader would be based around the cube, is that right?

So for what I want to do, I would be best grabbing the [Cube Map Add Alpha Reflect T1] and inserting the specular map part into that one.
 
The key is bumpmapping here.

If you don't need bumpmap, then everything is calculated in coordinates relative to observer or just in world coordinates.
When you use bumpmapping light position and observer position are transformed to become relative to polygon's surface.
This is why math behind bumpmap and non-bumpmap shader is different - because it's done in different coordinate system.

Specular map is much simplier to add - you just add one extra texture stage to shader and multiply specular lighting by value read from that texture.
Adding fresnel effect only means adding one more equation to pixel shader.
Adding cubemap means adding texture stage, calculating reflected vector and adding sampled texel to specular lighting.
And so on...

So, some effects require less changes and some require changing more fragments of code.

So for what I want to do, I would be best grabbing the [Cube Map Add Alpha Reflect T1] and inserting the specular map part into that one.
Yeah, that would be much better than trying to change bumpmap shader into non-bumpmap one :)
 
I'm just thinking out loud here.

In the new rain video thread the comments about the rain coming straight down reminded me of something.
I tried an experiment once with rain by attaching a mesh to the skybox and putting a rain animation texture on it, it looked ok, but the problem was when driving forward, the rain still came straight down when it should be going at an angle due to the car's motion here is a quick video of the results.

Can a shader be told to do certain things in relation to the car's speed? In this case, make the rain tilt as you drive forward and increase angle as you get faster?
 
Can a shader be told to do certain things in relation to the car's speed? In this case, make the rain tilt as you drive forward and increase angle as you get faster?

Depends on gfx engine, if camera (car) speed is provided to shader. I guess, it isn't in rF1
 

Back
Top