Author Topic: [UPDATE-10.12.2013]Kobrars shaders & stuff  (Read 10362 times)

0 Members and 1 Guest are viewing this topic.

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
[UPDATE-10.12.2013]Kobrars shaders & stuff
CEL SHADING outdated, contact me if you need this

AndrewofDoom asked me to work on some cel shading. In its curretn state, it's not perfect, but it works. Kinda. That Ravana has modified textures, so dont expect anything except Rynex to look like that without some work.

Be aware that edge detection is currently part of the existing post-processing pass, which means it is drawn over all the particles and stuff, including weappons, explosions, thrusters etc. It also doesn't seem to be distorted by thrusters. I will attempt to adress these issues at some point, but right now, the effect is mostly right there. There is also a known issue with lab. Gonna deal with it someday too.

Requirements: at least r10027 build.

DL Shaders
DL Ravana skin

Screeens






PARALLAX STUFF outdated, contact me if you need this

Parallax mapping

DL SHADERS

DL MOD


Parallax occlusion mapping

DL SHADERS

DL MOD


Mod packages contain fixed Karnak heights[which isn't a good example anyway because uv layout].
Both of them require height maps to function[ green channel of -height map ], but they are not compatible[ height map for PM won't work properly with POM].
The reason for that is because PM[in its current implementation] assumes everything of height 0.5 sits exactly where it is, while everything of higher height is higher and everything of lower height is lower [ :D ], while POM assumes 1.0 is the normal height and visually insets everything of lower height. There is no proper conversion between the two. I tried to make POM work a bit like PM, but I think I failed[also no one does that really]. It may be reasonable to sample the HEIGHT_SCALE from other channel in the height map instead of using a single macro for everything.





The per pixel gloss shader is now probably obsolete since Swifty's PBR stuff.

Feel free to comment or advise!
« Last Edit: July 09, 2015, 12:47:12 pm by Kobrar44 »
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline Raven2001

  • Machina Terra Reborn
  • 211
  • Im not the droid your looking for, move along
Re: Per-pixel gloss shader
Haven't tried it myself, but I think it would be helpful in terms of exposition, to have some comparison pics in real scenarios :)
Yeah, I know you were waiting for a very nice sig, in which I was quoting some very famous scientist or philosopher... guess what?!? I wont indulge you...

Why, you ask? What, do I look like a Shivan to you?!?


Raven is a god.

 
Re: Per-pixel gloss shader
wait, does this mean we can get rid of "that ****ing plastic specular look" more effectively? because if so: you have my utmost support
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: Per-pixel gloss shader
Thanks to help from The_E,


DIFFUSED ENV REFLECTIONS![the grey sphere the most apparent one]

Coming soon. I still need to figure out the mipmap level choice etc. sometime, then I'll update the shaders.
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline Herra Tohtori

  • The Academic
  • 211
  • Bad command or file name
Re: Per-pixel gloss shader
yesssssssss
There are three things that last forever: Abort, Retry, Fail - and the greatest of these is Fail.

 

Offline An4ximandros

  • 210
  • Transabyssal metastatic event
Re: Per-pixel gloss shader

Yes, Yes, Yes, Yes, Yes, Yes!

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: [UPDATE-09.11.2013]Kobrars shaders & stuff
 :bump: A little cel shading release.
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline AndrewofDoom

  • In A.D. 2366 war was beginning
  • 29
  • Permanent yuri goggles.
    • Skype
    • Steam
    • Twitter
Re: Kobrars shaders & stuff
This is awesome fyi. Just to note that Kobrar didn't mention, you'll need an FSO build r10027 or newer (the newest nightly for Windows and Mac as of this post are just that).
My Efforts:
SF Knight

20:08:19   AndrewofDoom: Though I find it mildly disturbing that a loli is giggling to mass destruction.
20:10:01   Spoon: I find it mildly arrousing
20:10:07   AndrewofDoom: Woah
20:10:15   Spoon: sound like my kind of loli
20:10:21   Spoon: and im not even a lolicon

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: [UPDATE-09.11.2013]Kobrars shaders & stuff
Advice neeeded
The current edge detection algorithm works, but is not perfect, as the detail is lost at larger distances. I used a hack to help that matters, the hack being amplifying the edge detection as the distance grows, but it also fades at some point and is hackish. And so I decided to resolve to maths and normalize the results somehow to get a consistent detail amount. Current algorithm works with default depth buffer space, which is non linear. The new algorithm works in linear space and is as follows:

[Note that Laplacian edge detection is in use]
1.Get 5 samples from the depth buffer: depthm, depthn, depths, depthw, depthe, where depthm is exactly where the processed fragment is, depthn is slightly to the top, depths is slightly to the bottom etc.
2.Calculate their real coordinates in camera space[as well as convert to linear].
3.Compare the side samples to the middle sample by substracting and then normalize each difference by dividing by difference in distance between two camera-space points and add all four results. This should in theory help with situation, where at large distances from the camera two fragments are very close on the screen but very far in camera space, which is fatal for linear depth testing.

where:
2.a convert the non linear depth to linear using an algorithm from http://stackoverflow.com/questions/6652253/getting-the-true-z-value-from-the-depth-buffer
exact code:
Code: [Select]
uniform sampler2D depthBuffTex;
uniform float zNear;
uniform float zFar;
varying vec2 vTexCoord;
void main(void)
{
    float z_b = texture2D(depthBuffTex, vTexCoord).x;
    float z_n = 2.0 * z_b - 1.0;
    float z_e = 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear));
}
2.b convert the screen coordinates to be [tan a, tan b], where a is horizontal angle and b i vertical. There probably is a better terminology with some spherical coordinates but I don't know these yet.
2.c create a 3d vector ( converted screen coordinates, 1.0 ) and scale it by linear depth. I assume this is estimated camera space coordinates of the fragment. It looks like it.

3.a each difference is as follows: (depthm - sidedepth)/lenght( positionm - sideposition)

And I may have screwed something at any point. Code looks fine, but the algorithm may not be, as I made it up myself.

My code:
Code: [Select]
float znear = 1.0;
float zfar = 10000000000.0;

float depthm = texture2D(depth_tex, gl_TexCoord[0].xy + distort ).r;
depthm = 2.0 * zfar * znear / (zfar + znear - ( 2.0 * depthm - 1.0 ) * (zfar - znear) );        //convert to linear
vec2 scorm = (gl_TexCoord[0].xy + distort) -0.5;           //conversion to desired coordinates space. This line returns value from range (-0.5,0.5)
scorm = scorm * 2.0 * 0.5;                                                // normalize to (-1, 1) and multiply by tan FOV/2, and default fov is IIRC 60 degrees
scorm.x = scorm.x * 1.6;                                                    //1.6 is aspect ratio 16/10
vec3 posm = vec3( scorm, 1.0 );
posm = posm * depthm;                                                      //scale by linearized depth
 


float depthn = texture2D(depth_tex, gl_TexCoord[0].xy + distort + vec2( 0.002*0.625  , 0.0) ).r;          //0.625 is aspect ratio 10/16
depthn = 2.0 * zfar * znear / (zfar + znear - ( 2.0 * depthn - 1.0 ) * (zfar - znear) );
vec2 scorn = (gl_TexCoord[0].xy + distort + vec2( 0.002*0.625, 0.0) ) -0.5;
scorn = scorn * 2.0 * 0.5;
scorn.x = scorn.x * 1.6;
vec3 posn = vec3( scorn, 1.0 );
posn = posn * depthn;

float depths = texture2D(depth_tex, gl_TexCoord[0].xy + distort - vec2( 0.002*0.625 , 0.0) ).r;
depths = 2.0 * zfar * znear / (zfar + znear - ( 2.0 * depths - 1.0 ) * (zfar - znear) );
vec2 scors = (gl_TexCoord[0].xy + distort - vec2( 0.002*0.625, 0.0) ) -0.5;
scors = scors * 2.0 * 0.5;
scors.x = scors.x * 1.6;
vec3 poss = vec3( scors, 1.0 );
poss = poss * depths;

float depthw = texture2D(depth_tex, gl_TexCoord[0].xy + distort + vec2(0.0 , 0.002) ).r;
depthw = 2.0 * zfar * znear / (zfar + znear - ( 2.0 * depthw - 1.0 ) * (zfar - znear) );
vec2 scorw = ( gl_TexCoord[0].xy + distort + vec2( 0.0 , 0.002) ) -0.5;
scorw = scorw * 2.0 * 0.5;
scorw.x = scorw.x * 1.6;
vec3 posw = vec3( scorw, 1.0 );
posw = posw * depthw;

float depthe = texture2D(depth_tex, gl_TexCoord[0].xy + distort - vec2(0.0 , 0.002) ).r;
depthe = 2.0 * zfar * znear / (zfar + znear - ( 2.0 * depthe - 1.0 ) * (zfar - znear) );
vec2 score = ( gl_TexCoord[0].xy + distort - vec2( 0.0 , 0.002) ) -0.5;
score = score * 2.0 * 0.5;
score.x = score.x * 1.6;
vec3 pose = vec3( score, 1.0 );
pose = pose * depthe;

float Contour = ( depthn - depthm )/length(posm - posn) + ( depths - depthm )/length(posm - poss) + ( depthw - depthm )/length(posm - posw) + ( depthe - depthm )/length(posm - pose);
Contour = 0.25 * Contour;

color_out.rgb = vec3( Contour, Contour, Contour );
        color_out.a = 1.0;
        gl_FragColor = color_out;

Results are as follows:



In other words, it doesn't detect the silhouette and it shows some heavy artifacts. As well as it detects some things it shouldn't. This may be due to the fact that I need to type things like fov by hand, so the values may not be correct, but it doesn't mean the algorithm itself is correct. In the end, it may be just the nature of discrete depth buffer.

Any thoughts?
« Last Edit: November 10, 2013, 03:34:49 pm by Kobrar44 »
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline MatthTheGeek

  • Captain Obvious
  • 212
  • Frenchie McFrenchface
Re: [UPDATE-09.11.2013]Kobrars shaders & stuff
This may be due to the fact that I need to type things like fov by hand, so the values may not be correct, but it doesn't mean the algorithm itself is correct.
If you're only testing in the tech room, since the zoom in tech room is a change of fov, then your hardcoded fov is very most certainly wrong.
People are stupid, therefore anything popular is at best suspicious.

Mod management tools     -     Wiki stuff!     -     Help us help you

666maslo666: Releasing a finished product is not a good thing! It is a modern fad.

SpardaSon21: it seems like you exist in a permanent state of half-joking misanthropy

Axem: when you put it like that, i sound like an insane person

bigchunk1: it's not retarded it's american!
bigchunk1: ...

batwota: steele's maneuvering for the coup de gras
MatthTheGeek: you mispelled grâce
Awaesaar: grace
batwota: oh right :P
Darius: ah!
Darius: yes, i like that
MatthTheGeek: the way you just spelled it it means fat
Awaesaar: +accent I forgot how to keyboard
MatthTheGeek: or grease
Darius: the killing fat!
Axem: jabba does the coup de gras
MatthTheGeek: XD
Axem: bring me solo and a cookie

 

Offline MatthTheGeek

  • Captain Obvious
  • 212
  • Frenchie McFrenchface
Re: [UPDATE-09.11.2013]Kobrars shaders & stuff
Doublepostedness



I am not sure this outline colour on the debris is intended. It's a bit jarring.



It doesn't look like it likes transparency very much. Otherwise, it works quite well on those ships with no texture changes :)
People are stupid, therefore anything popular is at best suspicious.

Mod management tools     -     Wiki stuff!     -     Help us help you

666maslo666: Releasing a finished product is not a good thing! It is a modern fad.

SpardaSon21: it seems like you exist in a permanent state of half-joking misanthropy

Axem: when you put it like that, i sound like an insane person

bigchunk1: it's not retarded it's american!
bigchunk1: ...

batwota: steele's maneuvering for the coup de gras
MatthTheGeek: you mispelled grâce
Awaesaar: grace
batwota: oh right :P
Darius: ah!
Darius: yes, i like that
MatthTheGeek: the way you just spelled it it means fat
Awaesaar: +accent I forgot how to keyboard
MatthTheGeek: or grease
Darius: the killing fat!
Axem: jabba does the coup de gras
MatthTheGeek: XD
Axem: bring me solo and a cookie

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: [UPDATE-09.11.2013]Kobrars shaders & stuff
New MVPS exhibit this behaviour[weird outlines]. I don't know why yet. 3612 were fine.
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline MatthTheGeek

  • Captain Obvious
  • 212
  • Frenchie McFrenchface
Re: [UPDATE-09.11.2013]Kobrars shaders & stuff
Question, when you're testing, are you testing with a populated post_processing.tbl table ? The 2014 MVPs come with one. It might be that other PP settings are interfering with the cel shading.
People are stupid, therefore anything popular is at best suspicious.

Mod management tools     -     Wiki stuff!     -     Help us help you

666maslo666: Releasing a finished product is not a good thing! It is a modern fad.

SpardaSon21: it seems like you exist in a permanent state of half-joking misanthropy

Axem: when you put it like that, i sound like an insane person

bigchunk1: it's not retarded it's american!
bigchunk1: ...

batwota: steele's maneuvering for the coup de gras
MatthTheGeek: you mispelled grâce
Awaesaar: grace
batwota: oh right :P
Darius: ah!
Darius: yes, i like that
MatthTheGeek: the way you just spelled it it means fat
Awaesaar: +accent I forgot how to keyboard
MatthTheGeek: or grease
Darius: the killing fat!
Axem: jabba does the coup de gras
MatthTheGeek: XD
Axem: bring me solo and a cookie

  

Offline MatthTheGeek

  • Captain Obvious
  • 212
  • Frenchie McFrenchface
Re: [UPDATE-09.11.2013]Kobrars shaders & stuff
UPDATE:

Testing showed that the contrast post-proc setting in particular is ****ing up the cel outlines. Disabling it while keeping the rest of the post proc settings fixes the issue.


In unrelated news, the shaders involved seem to override something in built-in shaders of shadow builds so I can't get both cel shading and shadows even on shadow builds. Not sure what you can do about that, but I thought I should report it nonetheless.





EDIT: Pretty neat when you disable textures that weren't intended for it.



« Last Edit: December 09, 2013, 02:23:20 pm by MatthTheGeek »
People are stupid, therefore anything popular is at best suspicious.

Mod management tools     -     Wiki stuff!     -     Help us help you

666maslo666: Releasing a finished product is not a good thing! It is a modern fad.

SpardaSon21: it seems like you exist in a permanent state of half-joking misanthropy

Axem: when you put it like that, i sound like an insane person

bigchunk1: it's not retarded it's american!
bigchunk1: ...

batwota: steele's maneuvering for the coup de gras
MatthTheGeek: you mispelled grâce
Awaesaar: grace
batwota: oh right :P
Darius: ah!
Darius: yes, i like that
MatthTheGeek: the way you just spelled it it means fat
Awaesaar: +accent I forgot how to keyboard
MatthTheGeek: or grease
Darius: the killing fat!
Axem: jabba does the coup de gras
MatthTheGeek: XD
Axem: bring me solo and a cookie

 

Offline Kobrar44

  • On Suspended Sentence
  • 29
  • Let me tilerape it for you!
    • Steam
Re: [UPDATE-10.12.2013]Kobrars shaders & stuff
Soo I updated that shader and you should be able to get more detail out of that erebus. Detail level should also be more consistent at larger distances. Report me any artifacts though.
Oh guys, use that [ url ][ img ][ /img ][ /url ] :/

 

Offline MatthTheGeek

  • Captain Obvious
  • 212
  • Frenchie McFrenchface
Re: [UPDATE-10.12.2013]Kobrars shaders & stuff
<3





Very yus
« Last Edit: December 10, 2013, 05:08:38 am by MatthTheGeek »
People are stupid, therefore anything popular is at best suspicious.

Mod management tools     -     Wiki stuff!     -     Help us help you

666maslo666: Releasing a finished product is not a good thing! It is a modern fad.

SpardaSon21: it seems like you exist in a permanent state of half-joking misanthropy

Axem: when you put it like that, i sound like an insane person

bigchunk1: it's not retarded it's american!
bigchunk1: ...

batwota: steele's maneuvering for the coup de gras
MatthTheGeek: you mispelled grâce
Awaesaar: grace
batwota: oh right :P
Darius: ah!
Darius: yes, i like that
MatthTheGeek: the way you just spelled it it means fat
Awaesaar: +accent I forgot how to keyboard
MatthTheGeek: or grease
Darius: the killing fat!
Axem: jabba does the coup de gras
MatthTheGeek: XD
Axem: bring me solo and a cookie

 

Offline Luis Dias

  • 211
Re: [UPDATE-10.12.2013]Kobrars shaders & stuff
omg this is awsum I luv it :yes: :yes:

 

Offline Darius

  • 211
Re: [UPDATE-10.12.2013]Kobrars shaders & stuff
wow

such anime

very outline

detail detail. wow.

 

Offline BritishShivans

  • Jolly good supernova
  • 29
Re: [UPDATE-10.12.2013]Kobrars shaders & stuff
oh goddamnit

the doge meme has spread here

why

 

Offline Darius

  • 211
Re: [UPDATE-10.12.2013]Kobrars shaders & stuff
Playing around with it in Diaspora, getting some spectacular results.

Kobrar, letting you know how the effect looks with regards to cockpits. You can see the outline poking through in the first image.