Shader Programming?

Blitz3D Forums/Blitz3D Programming/Shader Programming?

Caton(Posted 2016) [#1]
Is there some way of using a shader texture with a custom data file format to use on a b3d mesh? like bfx?


Bobysait(Posted 2016) [#2]
with native blitz3d ? no way.
DirectX7 does not support shaders at all, with or without dll.
shaders have been added in DirectX8.


RustyKristi(Posted 2016) [#3]
Irrlicht supports DirectX/OpenGL shaders since it is a multi-renderer engine and fortunately you can use Aqualung's latest B3D wrapper. Irrlicht loads b3d file as well. :)


Caton(Posted 2016) [#4]
if I can't use sharders how can I make it look good like this.

http://www.blitzbasic.com/Community/posts.php?topic=102169


Caton(Posted 2016) [#5]
or do I have to use c++ directx?


Bobysait(Posted 2016) [#6]
The screen on the first post of the linked topic is made with the leadwerks engine, it's not blitz3d at all (and actually, it's not really blitzmax either)


Caton(Posted 2016) [#7]
He said this one was b3d.



Bobysait(Posted 2016) [#8]
This screen does not require shaders.

Water can be made natively with a cubemap texture
And the scene is probably just lightmaped (backed from a modelisation software, or probably lightmaped with Gile[s] Illumination software).

The motion blur/dof applied on the screen is a routine you'll find in code archive section.

And eventually it may use the dot3 bump mapping on some surfaces (the rocks, I think) which is a native blitz blend mode for texture.


RemiD(Posted 2016) [#9]
I only see a reflections effect on water, and a depth of field effect (which is ugly imo), and probably texels lighting/shading (or maybe per pixel lighting/shading), you can achieve a similar render with Blitz3d.

for the reflections effect on water you can use cubemaps :
https://app.box.com/s/8z1ikuyl51hfeg4rjzfk
or the fastext lib or the ashadow lib or the devilshadow lib (which allows you to create similar reflections on water)

for the depth of field effect, there is this code example :
http://www.blitzbasic.com/codearcs/codearcs.php?code=1030
and maybe fastext has this functionality ?
(or you could simply render the shapes in the background and blur the render...)

for texels lighting/shading ("lightmaping"), you can use any "lightmapper"


Caton(Posted 2016) [#10]
then what's the different of a shader?


RustyKristi(Posted 2016) [#11]
Shader makes your graphics card do all the work, less strain on cpu and not using old methods.

Try any b3d shadow demos and compare it to openb3d stencil shadow shaders or irrlicht. You'll see the difference.

That's what graphic cards are supposed to do, handle shaders, shaders and shaders (and instancing and hardware physics on the side). As I have mentioned before, take out all shader capabilities and dx features starting from dx9/opengl on every engine and they will all look the same. :-)


RemiD(Posted 2016) [#12]
There are graphics effects that you can achieve with shaders that you can't achieve (or not as nice or not as fast) with Blitz3d.
For example, you can't have per pixel lighting/shading with Blitz3d, but you can have per texel lighting/shading or per vetex lighting/shading and if your scene is made in a certain way you won't notice the difference between the 3 methods.
for example, an old test that i did using Unity :
per pixel lighting/shading :


per vertex lighting/shading : (the scene is subdivided each 0.5 units)


as you can see, the renders look the same...

and you could also achieve a very similar render using per texel lighting/shading (using the same lighting/shading formula and a small enough texel size)


So, even without shaders you can create nice games, (all games before 2002 (approximately) did not use shaders (or rather custom shaders), but there were still nice graphics effects)


Bobysait(Posted 2016) [#13]
Don't care about RemiD, he's obsessed with vertex lighting ;)

Difference between with or whithout shaders ... well, it's not the same world, and don't listen to people who will tell you "you can still make beautifull things without shaders", that may be true, but it's far to explain what a shader can do.

A shader is not just a way to compute the graphics on the graphics card side, it's essentially a way to control the full pipeline of the rendering.
you can create things you'll never do (in realtime) without shaders
You decide what to do from your triangles, your vertices, and your pixels

There is 3 shader types : Vertex, geometry and Fragment
The first one receive a list of vertices and a "mode" (and absolutely all the extra stuff you want -> like an heightmap texture) to draw stuff with thoose vertices (lines, points, triangles, triangle_strip etc ...)
In this shader, you can modify the coordinates on the fly to apply whatever you want, like a sinusiod movement, or use an heightmap to set the vertices heights (so you can create a terrain and modify it just by moving the texture offset, without performance loss)
You can also compute normals, bones, etc ... and finally, you can (optionnaly) send the result to the geometry shader
The geometry shader will allow you to create extra geometry for each vertex sent.
so, you can send a list of coordinates to the vertex shader and convert them to meshes on the geometry shader, so you 'll have a particle system with fully detailed cloud or else ... or, you can instanciate models so it renders undred of thousands of entities in realtime
Them all the triangles (wether they come from the vertex or the geometry shader) are sent to the fragment shader that "rasterise" the pixels (it takes a triangle and find all the pixels on the screen that this triangle will cover)
And there you have the hand to manipule the pixels the way you want -> modify the color, using normals, textures, etc ...

At last but not least, shaders are often used for screenspace effects.
render passes (depth, normal, color, texture, etc ... anything you want/need) are sent as textures (or more exactly buffers) and processed just like you'd use a convolution matrix on an image
(this is very cpu intensive when you do it without shader, a simple render can take few seconds or more, while a shader will probably take less than 1 ms)
So you can add effects like rain exploding on the screen, efficient and neat realtime shadows (that works with animated mesh as well), fullscreen blur, glow, ambient oclusion and more and more stuff you could imagine.

Actually, it's probably not that far from truth to say : There is nothing you can't do with shaders.

So, just imagine a shader can do the same job as the cpu does, but most of the thing that are computed in several seconds only take less or at most 1-2 ms with a shader.
Realtime image processing is something a cpu can't do -> have a look on modelisation software and their image renderers, it use raycasting/path-tracing etc ... it's intensive and a render can take minutes ... even hours.
This job can be done with shaders in realtime.


RemiD(Posted 2016) [#14]
I found a good explanation (imo) about the differences between fixed pipeline and programmable pipeline :

the fixed function pipeline is a hardwired implementation of a, well, fixed program, through which each piece of data a GPU processes traverses, without the ability to change the details of any step. The only thing you can parameterize are the occasional branch to switch between hardcoded paths in the program (like enabling or disabling lighting, or using a separate specular) or some constants used (light colors and positions, texture environment base color modulation). And each and every step follows a specific formula.

In a programmable pipeline however the GPU is clean slate. It's completely up to the programmer how the various stages of the rendering process (vertex transformation, tesselation, fragment processing) are carried out. And you can use whatever formula you see fit for the task.



But really many effects achieved with shaders can be reproduced using tricks without shaders (but sometimes it is not as precise or not as fast)


Bobysait(Posted 2016) [#15]

But really many effects achieved with shaders can be reproduced using tricks without shaders (but sometimes it is not as precise or not as fast)


I know you like Blitz3D, and I really understand that, but here you're not really relevant : blitz3d is absolutely not capable of doing what shaders can do, no matter you use tricks or not, it won't do the same : if you have the same look, it will be slow or you'll burn the cpu ... just to do something that is not supposed to be done without shaders, or you'll get performance but it will be very far from what it's supposed to look like, so in the end, it's still not what you can do with a shader (and there is no comparison).
So, you're just talking about something you really seem to never have experienced ... so how could you tell what you can't know ?

A shader is a programmable region on the graphics card, you're maybe stuck to the "render 3d" part, but actually, a shader is not a 3d renderer
It's what you want it to be, you are the one who create the program
-> you tell what is going on, and what is output (a color, a vector, a ... whatever you want) then get the data on the fragment and once again you do whatever you want with data you send.
So, you can create a 3d renderer, but it's only one thing you can do with shaders, and even this renderer, you can make it the way you want.
-> you can create your own equation for lighting, you can decide how to displace vertex for each triangles, you can do bone skining with specific rules ... etc ...
You can also make a wrong maths code if you want :)

You can and you have to write everything.
- the way you want to light pixels
- the way you want textures to be applied
- the way bones affect vertex coordinates
- etc ... etc ...

And now, things you'll never get with generic scenes (a scene that does not need tons of restrictive rules to make the engine work, and does work with more than a single cube...) in realtime with blitz3d :
- radiosity
- displacement
- parallax bump
- ambient oclusion
- tesselation
- probably light-scattering / god rays etc ...
- light textures
- and so on ...

Blitz3d only allows to make some fake screen effects that are really far from what you really wanted most of the time, but you go with it because you abandonned the idea of sticking to your original project. And that's what is sad with blitz3d ... you keep on removing stuff you wanted at first, because it's not doable.
And then, you just mae stuff for low-cost machines because in the end, it's what better fit to blitz3d's specs -> static scenes with simple shadows (if any). It can render beautifully, but it won't be what you really wanted.


RemiD(Posted 2016) [#16]

So, you're just talking about something you really seem to never have experienced ... so how could you tell what you can't know ?


you are right, but even if i am a noob with shaders, i can compare the results (the renders with/without shaders) and the the time it takes to render 2 similar scenes (according to the fps) and sometimes using shaders does not make the scene nicer or faster to render.

Personally i don't have the time or motivation to create a demo/game with realistic shapes/colors/effects, so i don't care about the effects you mentioned (except maybe bump mapping)
what i find important to have a scene with a good appearance/ambiance is :
coherent shapes and colors
convincing animations
coherent lighting/shading
flares/glow/bloom (on lightsources)
reflections on metals/gems/glass/marble (with cubemapping)
particles
details on near shapes or bump mapping (Blitz3d can't do it, unfortunately)

But i will probably end up using shaders, maybe with your bigbang engine when you show us some demos, i am not against them, i just don't need them at the moment... (i just create demos/games for fun these days)


Caton(Posted 2016) [#17]
I want to use shades but I guess I will have to use c++ but I don't have and don't know how to write a b3d model loader dx9.


RustyKristi(Posted 2016) [#18]
don't know how to write a b3d model loader dx9.


Use the irrlicht wrapper and blitz3d. Irrlicht fully supports B3D file format, DX9+shaders. Done.

Official Thread and Download
http://www.blitzbasic.com/Community/posts.php?topic=106558


Caton(Posted 2016) [#19]
I guess I will have to write my own b3d model loader

I'm using c++ directx9 no other game engine.

is b3d format copyrighted?


Bobysait(Posted 2016) [#20]
is b3d format copyrighted?

the b3d format is open source from the beginning
-> you'll find the specifications on the top menu bar "Specs and Utils"


RustyKristi(Posted 2016) [#21]
I guess I will have to write my own b3d model loader

I'm using c++ directx9 no other game engine.


You do know when you started using b3d, it's DX7 right?

Irrlicht is C++ DX9 engine, DX11 and OpenGL, software renderer too.


Yue(Posted 2016) [#22]
https://bytecode77.com/coding/devilengines/shaderengine



RustyKristi(Posted 2016) [#23]
It's passable but somehow it looks extreme so it would only work if you have shiny objects like car paint, etc. I'm sure you already know the comparison since you have used Unity.

The sphere on the right works only on spotlights, try simulating a directional light or sun/outdoor lighting and it won't work. I already told the author about that issue.

ShaderEngine still looks good for b3d/Dx7 don't get me wrong. :-)