• 15
• 15
• 11
• 9
• 10

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

This topic is 2104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 - http://pastebin.com/0g9NcTPx

fog.inc (Vertex) - http://pastebin.com/9F9MpQeZ

skybox.vsh - http://pastebin.com/AazHRpdg

The zip - http://www.putlocker.com/file/A9C28E8269766107

##### Share on other sites
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 on other sites
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 on other sites
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 on other sites
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:

http://forum.modsour...ttach=925;image
http://forum.modsour...ttach=929;image

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.

http://img528.images...eenshot0447.jpg
http://img526.images...eenshot0448.jpg
http://img194.images...eenshot0449.jpg

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.
http://developer.amd...l06_jgrills.pdf

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:
//asm TARGET #include "vertex_program/modules/registers.inc" dcl_position0 vPosition m4x4 oPos, vPosition, cObjectWorldCameraProjectionMatrix

psh:
 ps.1.0 def c0, 0.0, 0.0, 0.0, 1.0 mov r0, c0 

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:

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); }

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 on other sites

[background=rgb(250, 251, 252)]2d_blur.psh[/background]

" 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.

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 on other sites

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

FORM..._EFCTFORM...S0001DATA......FORM...#IMPLFORM....0005SCAP............DATA.....RTAW..FORM...ÖPASSFORM...Ê0008DATA...3..........................NIAM.................NIAMFORM...+PVSH0000....vertex_program/water_pass1.vsh.FORM...PPPSHFORM...D0001DATA.....pixel_program/water_pass1.psh.FORM....PTXM0002.....NIAMFORM....PASSFORM....0008DATA...3..........................NIAM.................NIAMFORM....PVSH0000..."vertex_program/water_pass2_25.vsh.FORM....PPSHFORM...y0001DATA...".pixel_program/water_pass2_25.psh.FORM....PTXM0002.....LMRNFORM....PTXM0002.....LMRNFORM....PTXM0002.....MVNEFORM...8IMPLFORM...,0005SCAP........DATA.....RTAW..FORM...ÖPASSFORM...Ê0008DATA...3..........................NIAM.................NIAMFORM...+PVSH0000....vertex_program/water_pass1.vsh.FORM...PPPSHFORM...D0001DATA.....pixel_program/water_pass1.psh.FORM....PTXM0002.....NIAMFORM...'PASSFORM....0008DATA...3..........................NIAM.................NIAMFORM....PVSH0000..."vertex_program/water_pass2_20.vsh.FORM....PPSHFORM....0001DATA...".pixel_program/water_pass2_20.psh.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