ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Cube maps in STALKER

1 2 3
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  04:02:45  19 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
Messages: 130
Cube maps in STALKER

Anyone got insight on how these work? I noticed the #small sky cubes apply a nice cubemap reflection which is what I was after, but the effect doesn't seem to be maskable.

Alternatively, I'd love to apply the cubemap to just, say, the weapon.

http://puu.sh/2kbBX

Left example has a custom #small cubemap.
  05:05:02  19 March 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
 

Message edited by:
Jketiynu
03/19/2013 5:28:14
Messages: 867

---QUOTATION---
Cube maps in STALKER

Anyone got insight on how these work? I noticed the #small sky cubes apply a nice cubemap reflection which is what I was after, but the effect doesn't seem to be maskable.

Alternatively, I'd love to apply the cubemap to just, say, the weapon.

http://puu.sh/2kbBX

Left example has a custom #small cubemap.
---END QUOTATION---



If you tell me how you went about applying the cubemap to the weapon maybe I can help.

Did you use the #small cubemap renamed as weaponname_bump# or did you do something else? Once I understand how you apply it I can experiment in the SDK to see how to make it only happen to the weapon.

Alternatively, you could ask someone such as Meltac to create a new model_shader.s file that does a cubemap reflection and that alone. It shouldn't be too hard to do.
Hell, I may even be able to do it. Then you'd just apply that shader to the weapon skin instead of models_weapons, etc.

*Final edit*
Looks like Call of Pripyat does this already.

You'll need to change the models/weapons in shaders.xr via the Shader editor in the SDK and fill it out with the following info (assuming the SOC SDK has these options):

Environment map:
Name - sky\sky_cube_weapons (here's the texture for it: http://www.sendspace.com/file/3x1ppj )
Transform - Custom

Custom Transform:
Mode - Cube Reflection
Alpha-Blend - Not used

If those options aren't present then I don't know what to say except ask again how you're currently applying the cube map?
  12:53:55  19 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
Messages: 130
I was just using #small maps for the env map which is not a very good solution. Using a models_weapons.s file seems to apply it to the weapon only (it won't apply it at all without this file), but it makes my guns transparent and seems to ignore normal/specular maps. Env/diffuse do appear.

function normal (shader, t_base, t_second, t_detail)
shader:begin ("model_env_lq","model_env_lq"
: fog (true)
: zb (true,false)
: blend (true,blend.srcalpha,blend.invsrcalpha)
: aref (true,0)
: sorting (3,true)
shader:sampler ("s_base" :texture (t_base)
shader:sampler ("s_env" :texture ("sky\\sky_cube_weapons" : clamp()
end
  15:47:04  19 March 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
 

Message edited by:
Jketiynu
03/19/2013 15:57:24
Messages: 867

---QUOTATION---
I was just using #small maps for the env map which is not a very good solution. Using a models_weapons.s file seems to apply it to the weapon only (it won't apply it at all without this file), but it makes my guns transparent and seems to ignore normal/specular maps. Env/diffuse do appear.

function normal (shader, t_base, t_second, t_detail)
shader:begin ("model_env_lq","model_env_lq"
: fog (true)
: zb (true,false)
: blend (true,blend.srcalpha,blend.invsrcalpha)
: aref (true,0)
: sorting (3,true)
shader:sampler ("s_base" :texture (t_base)
shader:sampler ("s_env" :texture ("sky\\sky_cube_weapons" : clamp()
end
---END QUOTATION---



I'm pretty sure I was wrong regarding using a .s file which is why I posted the changes you should make to shaders.xr (I'm positive that you have to do the changes there in the ways I mentioned).
Did you try modifying shaders.xr yet? It should not need a new corresponding .s file.

I'm almost positive that you do not need a new .s file because there are a bunch of shaders in shaders.xr which have no corresponding .s file or anything else in the unpacked shaders yet they're used by the game all the time.

*Edit*
If you don't know how to work with the shaders editor I'll install the SOC SDK real quick and do it for you and test it and make sure it's working.
  20:14:55  19 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
Messages: 130
I've tweaked the shaders in that, yeah. It's just that it doesn't use any cubemaps unless I make an .s file :I
  20:24:46  19 March 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
 

Message edited by:
Jketiynu
03/19/2013 20:25:09
Messages: 867

---QUOTATION---
I've tweaked the shaders in that, yeah. It's just that it doesn't use any cubemaps unless I make an .s file :I
---END QUOTATION---



Oh. That's strange. The commonly used models/weapons doesn't even have a corresponding .s file.

If I were you I'd ask Meltac for help.
  20:28:05  19 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
Messages: 130
Yeah, I sent him a message, hope he's not too busy.
  03:21:26  20 March 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
 

Message edited by:
Jketiynu
03/20/2013 3:21:47
Messages: 867

---QUOTATION---
Yeah, I sent him a message, hope he's not too busy.
---END QUOTATION---



If you do get a response if he helps would you mind sharing it?

I'm trying to add a custom shader into shaders.xr for scope lenses (I figure rather than the current method it would look better if a separate part was made for each scope lens, which would then have a different shader applied to it which would reflect the surrounding environment like what lots of games do) so his advice could be of use to me too, since I'm guessing I'd encounter the same problem you're encountering.
  11:31:32  20 March 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
 

Message edited by:
Meltac
03/20/2013 11:35:32
Messages: 1519
Hey guys, I'd be eager to help here, but in order to do so I first have to fully understand what exactly is going on here.

I know *more or less* , but unfortunately not exactly what function the different "shader" components in X-Ray / SoC have, so if anyone could shed a little more light on how these parts exactly work together it would be very helpful to solve issues such as the above:

1. SDK / Shader Editor
2. shaders.xr
3. cube maps / textures
4. .s files
5. HLSL files (.vs Vertex and .ps Pixel Shaders)

Better knowledge of the function of those components within X-Ray's render pipeline would ultimately be of great help in such cases as yours.

EDIT:
I personally mainly have experiences with parts 4 and 5, so please don't ask me about SDK-related stuff.
  16:54:15  20 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
 

Message edited by:
Millenia
03/20/2013 16:55:49
Messages: 130
Well basically the first three parts work so that you assign a cubemap to a shader (in this case models/weapons), then assign that shader to a model (all vanilla weapons have that shader already). By default, it should call textures/sky/sky_cube_weapons.dds, and this effect is masked with the weapon texture's alpha map (black is full reflection, white is zero reflection).

Unfortunately, in the vanilla game, weapon cubemaps only work in DX8 mode. Making a new .s file and assigning the cubemap there like in my example would fix it, but this (at the moment) seems to make the weapon transparent as well (probably because I have no idea what I'm doing with s/vs/ps files). I think it would only be a case of locating the right functions in said files and assigning those to models_weapons.s.

PS. thanks for your attention Meltac, I'm experienced in 3d stuff but utterly clueless when it comes to shader code
  18:02:33  20 March 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
Messages: 1519
Ok, thanks for the explanation. Not yet sure if I fully understood everything, will try to sort it out. Will report if I manage to figure out what's going wrong here.

Hmm, if this works under DX8 it might be a pure shader issue, not sure about that, though. But if so, I wonder why nobody has ever ported this from DX8 to DX9 before...
  13:25:30  21 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
Messages: 130
Here's a couple of pics because I accidentally removed the one from the first post, heh.

Cubemap effect with a custom cubemap as sky_13_cube#small.dds and a weather to use sky_13_cube.dds, looks okay but the effect is not masked and gets applied to every single object in the world (not good)

http://puu.sh/2llun

With the shader code I posted, applied only to the weapon. Hard to see but there is a masked cubemap effect in there (controlled by diffuse alpha). Also seems to control opacity at the same time.

http://puu.sh/2lluO
  14:14:01  21 March 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
 

Message edited by:
Meltac
03/21/2013 14:15:13
Messages: 1519
Hmm, the second looks really weird. There's definitely something missing.

How did you come to that specific content of the .s file you made? Have there been any special decisions to have it exactly this way? As it's way not the simplest .s file I've come across. Have you tried different settings there (e.g. leave some portions out)?
  14:25:07  21 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
Messages: 130
I have, removing almost everything makes it entirely transparent. I copied that stuff from some vanilla .s model file, models_xmonolith.s I think.
  12:24:34  25 March 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
 

Message edited by:
Meltac
03/25/2013 12:25:54
Messages: 1519
Ok I checked that. The problem here are the assigned pixel and vertex shaders. They must be written the way you wanna have the result. By copying an existing .s file you assigned the "wrong" shaders, resulting in the weird rendering you got.

The question is, however, which shaders would be best here. If you would want the very same as with all other game objects, plus the additional cube map application, I'm afraid you'd have to write a specific vertex and pixel shader for that, because you can only assign one of each whereas for the other game objects various shaders are involved in the rendering pipeline in order to create the final result. So you'd probably have to write a new shader doing all those things in one file as the engine does during the entire rendering process (i.e. process geometry, create and fill depth buffer, apply lighting calculations, bump mapping, environment mapping, post processing and the like).

Might become heavy, if even possible. However as said before I'm not a pro in this field, so can't say for sure whether there's a better way to go.
  15:53:57  25 March 2013
profilee-mailreply Message URLTo the Top
LoNer1
Настоящий Cталкер, Русская Версия
(Resident)

 

 
On forum: 10/23/2009
Messages: 1890
Try contacting K.D? He seems to be knowing what he's doing
  16:36:11  25 March 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
Messages: 1519

---QUOTATION---
Try contacting K.D? He seems to be knowing what he's doing
---END QUOTATION---



Yeah, might be helpful. I'd leave that up to Millenia as the thread launcher
  13:27:00  26 March 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
 

Message edited by:
Meltac
03/26/2013 13:28:22
Messages: 1519

---QUOTATION---
Anyways, are we sure we'd need to specify bumpmap and all that kinda crap in the .s file? I'm pretty sure stuff like that gets loaded automatically as long as it exists.
I'm new to all this, but it would seem to me that you simply need to start by finding a more neutral .s file as a base and removing transparency.

I don't know for sure, but doesn't "aref" control transparency? Maybe removing that from the .s file would help.
---END QUOTATION---



I've checked that. Try copying different existing .s files and renaming them to "models_weapons.s" and see what happens. The transparency is NOT the issue! It just came from having assigned the wrong shader files in the .s files.

That's the problem: You have to assign a specific shader file within the .s file, regardless of the rest of the settings there. What means that the engine (aka X-Ray) calls that specific shader for the task of rendering (or better, shading) the object in question (in our case, a weapon model). Doing so breaks the entire rendering pipeline as X-Ray just promotes all the shading work to one single shader, instead of processing a chain of subsequent shader calls as it's the case without using the .s file. It's a replacement of the normal rendering we do here.

That means, as soon as you have a .s file for something you are responsible yourself that all the rendering/shading stuff is done properly (by writing a shader doing so). Doable, but pretty some handwork.
  19:28:40  26 March 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
Messages: 867

---QUOTATION---
Anyways, are we sure we'd need to specify bumpmap and all that kinda crap in the .s file? I'm pretty sure stuff like that gets loaded automatically as long as it exists.
I'm new to all this, but it would seem to me that you simply need to start by finding a more neutral .s file as a base and removing transparency.

I don't know for sure, but doesn't "aref" control transparency? Maybe removing that from the .s file would help.

I've checked that. Try copying different existing .s files and renaming them to "models_weapons.s" and see what happens. The transparency is NOT the issue! It just came from having assigned the wrong shader files in the .s files.

That's the problem: You have to assign a specific shader file within the .s file, regardless of the rest of the settings there. What means that the engine (aka X-Ray) calls that specific shader for the task of rendering (or better, shading) the object in question (in our case, a weapon model). Doing so breaks the entire rendering pipeline as X-Ray just promotes all the shading work to one single shader, instead of processing a chain of subsequent shader calls as it's the case without using the .s file. It's a replacement of the normal rendering we do here.

That means, as soon as you have a .s file for something you are responsible yourself that all the rendering/shading stuff is done properly (by writing a shader doing so). Doable, but pretty some handwork.
---END QUOTATION---



I see, I think I get it now. Thank you for explaining it.

I also now realize my dream of having a reflection or refraction shader for scope lenses isn't realistic. Oh well
  05:15:50  27 March 2013
profilee-mailreply Message URLTo the Top
Millenia
(Senior)
 
On forum: 04/04/2007
Messages: 130
Too bad it's that hard and convoluted, would have been amazing to get it working

Thanks for looking into it, Meltac.
  10:15:47  27 March 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
 

Message edited by:
Meltac
03/27/2013 10:17:03
Messages: 1519

---QUOTATION---
I also now realize my dream of having a reflection or refraction shader for scope lenses isn't realistic. Oh well
---END QUOTATION---



Hmm, I'm not entirely sure about that. The scope lenses show some (faked) reflection already in vanilla, which is different from the rest of the weapon. That might mean that the lens has been assigned a different shader by default. Although I don't know what shader file that would be. Maybe xlens.s?


---QUOTATION---
Too bad it's that hard and convoluted, would have been amazing to get it working.
---END QUOTATION---



What I said before is my current understanding of how those files play together. However, as stated initially, I'm not a pro on that front, so there's still a chance that there's some easier way to do it. The question is, though, who has the knowledge to unveil the way - and is willing to share it.
  20:53:57  9 August 2013
profilee-mailreply Message URLTo the Top
Jketiynu
Swartz
(Resident)

 

 
On forum: 04/05/2007
 

Message edited by:
Jketiynu
08/10/2013 7:15:44
Messages: 867
*bump*
Edited at bottom of post

Sorry for bumping such an old thread, but I've been experimenting with this over the past two days and think I'm finally getting somewhere.

Before no matter what I tried to use for models_weapons.s it would be either transparent or some other glitch would occur.

Now I can get it to appear in the normal place, with one of them looking the way it should look (sorta, I'll explain).

Method 1: http://pastebin.com/CXgHwHxW
The model reacts to light and appears correctly, but it's very dark.

Method 2: http://pastebin.com/ELqVWg7C
This version as far as I can tell looks identical to the vanilla version, however there is a graphical glitch in the sky with it enabled.

I obviously don't understand shaders that well so it's probably some simple mistake I made that can be fixed and then models_weapons can finally be modified.

I also sent an email about this to team Dezowave as they've been helpful to me in the past so hopefully they'll help again.

Just posted this since I'd love a better lighting model and reflection map for weapons, but first we need to figure out how models_weapons is handled internally to begin with.

*EDIT*

Got it working finally.
http://imgur.com/k8ZDpqP

In the screenshot the hands and AK74 uses the new weapon shader, the hands are using vanilla (renamed the weapon shader for the ak to models_weapon5 by hex-editing and created corresponding models_weapon5.s file)
Here's the models_weapons.s file used: http://pastebin.com/bEWLTdAV

Some notes:
1) I don't think it uses a bump map (yet, I need to find a better example to see if it gets read. If it doesn't it shouldn't be hard to fix I imagine)
2) The reason I was getting either the glitch in the sky before or a dark model is because I used the VS shader for accum_volumetric which causes problems.
It looks like the first part of the shader line corresponds to the VS, and the 2nd is PS. I set VS to null and thus it came out correctly.
3) The lighting and shadowing on the model is identical to vanilla weapon shader

Now to improve on it by adding a cubemap, maybe writing a custom lighting file for it instead of using accum_volumetric, etc.

Since I was nice enough to share, if anyone including myself creates some neat results lets share it/keep it open source guys.
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2022 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.