Sign in to follow this  
Timbab

.vsh / .psh - HLSL/ASM Shaders - Star Wars Galaxies - Urgent help needed!

Recommended Posts

Timbab    113
Hi,

I hope this is the right section...

I've been working on a mod for SWGEmu, but I'm having extreme problems with the shaders. I'm totally inexperienced when it comes to HLSL and some of it seems to be in ASM.

What I mainly want to do is add depth of field if possible (It should be, a guy on an old mod forum said it was possible by modding the psh/vsh files), probably in the fog .vsh, but I'm not sure. Another thing is understanding the possibilities with the given files.

If anyone could take a few moments and look at it, I would be extremely grateful, I've been trying to figure this stuff out for hours and been researching, but with not too much progress. I've uploaded all of the psh/vsh and their .inc files, including 3 pastebin samples of it.

2d_blur.psh - [url="http://pastebin.com/0g9NcTPx"]http://pastebin.com/0g9NcTPx[/url]

fog.inc (Vertex) - [url="http://pastebin.com/9F9MpQeZ"]http://pastebin.com/9F9MpQeZ[/url]

skybox.vsh - [url="http://pastebin.com/AazHRpdg"]http://pastebin.com/AazHRpdg[/url]

The zip - [url="http://www.putlocker.com/file/A9C28E8269766107"]http://www.putlocker.com/file/A9C28E8269766107[/url]

Thanks in advance!


[url="http://forum.xentax.com/report.php?f=13&p=74400"][img]http://forum.xentax.com/styles/subsilver2/imageset/en/icon_post_report.gif[/img][/url]

Share this post


Link to post
Share on other sites
Nik02    4348
Depth of field requires a separate rendering pass or two to implement the blurring. You can't invoke extra rendering passes from within the shader code.

Share this post


Link to post
Share on other sites
Timbab    113
So it's not possible unless you'd fake it somehow, like a blur effect on fog, right? And, DoF would be done in the source code then? Or where?

Sorry, complete lack of knowledge, lol.

Share this post


Link to post
Share on other sites
Nik02    4348
The blur (which is an essential part of common DoF effect) requires that the scene color and depth are first rendered to textures. Then, the screen is filled with a pixel shader that takes several weighted and offset samples from the color texture (the act of blurring), varying the offset range by the values from the depth texture. If Gaussian blur is used, it is often separated to discrete horizontal and vertical passes since the end result is identical to single blur pass, but you save a lot of total computation cycles if the blur kernel is larger than a few texels.

The reason why you can't do this in single pass (especially on older hardware) is that you don't have write access to pixels other than the currently processed one. You do have almost random read access, which is why the weighed sampling is used to reverse the scattered write (which would be forward blurring) to a gathered read.

The common fog effect has nothing to do with blurring; it is just a color mix function that is parametrized by the distance of the geometry from the "camera".

Multiple passes requires that the rendering engine participates in the process. If you only have access to one pixel shader that is designed to render things in single pass, there is no practical way to modify it so that you get blur. The vertex shader is largely irrelevant here, though it could participate in offsetting of the samples on older hardware in order to gain a little performance boost. Edited by Nik02

Share this post


Link to post
Share on other sites
Timbab    113
I see, that makes sense. So in order to implement actual real DoF, you'd need access to the engine?

Could you take a look at this:

[url="http://forum.modsource.org/index.php?action=dlattach;topic=948.0;attach=925;image"]http://forum.modsour...ttach=925;image[/url]
[url="http://forum.modsource.org/index.php?action=dlattach;topic=948.0;attach=929;image"]http://forum.modsour...ttach=929;image[/url]

Those are two screenshots from a guy who modded a newer version of the game about a year or two ago. He never said how he did it, the only thing he mentioned was how he modified some .psh/.vsh files. What he did say about it though, was that some users crashed while using it.

I'm almost certain he put a blur effect on the fog the game uses to 'mask' the render distance, but I still haven't found the right shader for it, here is how it looks normally, at minimum render distance, 50% and 100%. I know it's not real DoF, but it's an interesting effect and I'd really like to replicate it, perhaps enhance it down the road.

[url="http://img528.imageshack.us/img528/7042/screenshot0447.jpg"]http://img528.images...eenshot0447.jpg[/url]
[url="http://img526.imageshack.us/img526/4430/screenshot0448.jpg"]http://img526.images...eenshot0448.jpg[/url]
[url="http://img194.imageshack.us/img194/1082/screenshot0449.jpg"]http://img194.images...eenshot0449.jpg[/url]

I also found the following pdf, it's from the GDC way back which talks about SWG and how it uses shaders and does the rendering, in case it gives any usable info.
[url="http://developer.amd.com/media/gpu_assets/D3DTutorial06_jgrills.pdf"]http://developer.amd...l06_jgrills.pdf[/url]

Another thing if you don't mind, I talked to a guy who said it might be possible to add better shadows to the game with "dx10 you have a slope dependent texture sample function". Again, I'm pretty inexperienced at the moment with this stuff, but do you think it's possible? The current shadow shader (I believe) is shadowvolume:

vsh:
[code]//asm
TARGET

#include "vertex_program/modules/registers.inc"
dcl_position0 vPosition

m4x4 oPos, vPosition, cObjectWorldCameraProjectionMatrix[/code]

psh:
[code]
ps.1.0

def c0, 0.0, 0.0, 0.0, 1.0
mov r0, c0
[/code]

Thank you for taking the time to reply though, you've been really helpful to get me to wrap my head around the subject. I'm looking into loads of resources about HLSL atm to understand it more in depth, but there is nothing like direct answers to questions.


EDIT:


I FINALLY found the fog hiding in the vertex shader function.inc.

Here is the code:

[code]float calculateFog(float4 vertexPosition_o)
{
float4 position_w = mul(vertexPosition_o, objectWorldMatrix);
float3 viewer_w = cameraPosition_w - position_w;
float viewerDistanceSquared = lengthSquared(viewer_w);
return 1.0 / exp(viewerDistanceSquared * fog.w);
}[/code]

I know what it does, I already have toyed around with it, is it possible to add a blur effect to it? For instance like the one in the OP? Or could you use calculateFog in the blur file?

I've checked all the shader files (Used a shader that has certain distinctions, like being pink) and slapped other shader names on it to visualize which file does what, just so I can personally see, because I still suck at HLSL, but none of them has anything to do with the fog.

Edit2: I just talked to someone, he said it's not possible to use the .psh for editing the look of the fog (blur in this case), because none of the .psh files use it. He doesn't know how they do the fog, since it's only in the functions.inc in the .vsh folder.

This is driving me nuts! Edited by Timbab

Share this post


Link to post
Share on other sites
Hodgman    51223
Your "[left][background=rgb(250, 251, 252)]2d_blur.psh[/background][/left][left]" contains the kind of blur code that a DoF routine would use -- it's gathering 16 random samples around each pixel. The game is setting two variables, textureCoordinateOffsets and userConstants, which describe the size/shape of the blur.[/left]
You'd need a way to scale these offsets per-pixel, so focused pixels used small offsets and un-focused pixels used large offsets. In order to do that, you'd need to either be able to sample the depth buffer, or have the game otherwise let you examine the depth of each pixel. Edited by Hodgman

Share this post


Link to post
Share on other sites
Timbab    113
Thanks for the reply.

Can't I use the way the fog gets generated at a player distance, even if I ignore the fog completely, but use the same technique? But I guess this doesn't do what you said with the offsets. Ugh!

And it's so strange, I edited and used the 2d_blur as basis for something I wanted to try out, made my changes, saved it as 2d_bloom (so I can toggle it ingame via options), but it totally skipped the code and went straight for the normal blur effect upclose, then I copied the same code and used the original 2d_bloom, and it skipped the code and used the bloom code still in the .tre (archive) it seemed, or at least, since it's compiled and only editable in hex, the 'PEXE" information at the end of the file.

What the hell...

Edit:

Friend found something about what the guy said how he did it:

"It also allows for camera blurring when focal on "centric" objects. "

"Nothing. Didn't touch sandstorms or fog. The only exception is that the draw distance now has a parameter in the Vertex/Pixel shader files that can force Depth of Field on some cards - but that won't affect sandstorms or natural in-game fog."

Hmm, any ideas?


Edit 2:

I'd edit, but well...

Not sure if anyone is still out there, but I just realized looking at the .eft (Effect files that link/handle the psh/vsh files) makes it possible to have multiple passes.

It's in hex and it's better to view them with the TRE Explorer, but here is one with multiple passes I believe, I'll mark the links to the shaders in bold:

water.eft
[quote]
FORM..._EFCTFORM...S0001DATA......FORM...#IMPLFORM....0005SCAP............DATA.....RTAW..FORM...ÖPASSFORM...Ê0008DATA...3..........................NIAM.................NIAMFORM...+PVSH0000....[b]vertex_program/water_pass1.vsh[/b].FORM...PPPSHFORM...D0001DATA.....[b]pixel_program/water_pass1.psh[/b].FORM....PTXM0002.....NIAMFORM....PASSFORM....0008DATA...3..........................NIAM.................NIAMFORM....PVSH0000..."[b]vertex_program/water_pass2_25.vsh[/b].FORM....PPSHFORM...y0001DATA...".[b]pixel_program/water_pass2_25.psh[/b].FORM....PTXM0002.....LMRNFORM....PTXM0002.....LMRNFORM....PTXM0002.....MVNEFORM...8IMPLFORM...,0005SCAP........DATA.....RTAW..FORM...ÖPASSFORM...Ê0008DATA...3..........................NIAM.................NIAMFORM...+PVSH0000....[b]vertex_program/water_pass1.vsh[/b].FORM...PPPSHFORM...D0001DATA.....[b]pixel_program/water_pass1.psh[/b].FORM....PTXM0002.....NIAMFORM...'PASSFORM....0008DATA...3..........................NIAM.................NIAMFORM....PVSH0000..."[b]vertex_program/water_pass2_20.vsh[/b].FORM....PPSHFORM....0001DATA...".[b]pixel_program/water_pass2_20.psh[/b].FORM....PTXM0002.....LMRNFORM....PTXM0002.....LMRNFORM....PTXM0002.....LMRNFORM....PTXM0002.....MVNEFORM...ÒIMPLFORM...Æ0005SCAP............DATA.....RTAW..FORM....PASSFORM....0008DATA...3..........................NIAM.................NIAMFORM....PFFP0001...........FORM...-STAG0000...!..................NIAMNIAM.......[/quote] Edited by Timbab

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this