Author Topic: RBDoom 3 engine (shader programs)  (Read 4203 times)

0 Members and 1 Guest are viewing this topic.

argoon

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
RBDoom 3 engine (shader programs)
« on: March 28, 2015, 06:07:43 PM »
Hello guys

Now that dmap is supported on this engine ( thank's trebor !!! ) I'm trying to convert a glsl fresnel to it (because i also don't know how to convert the one made in ARB code) below is the fresnel code, i'm also trying to convert a ice/snow opengl shaders, but everytime i try to dmap a map with the fresnel_vertex.glsl and fresnel_fragment.glsl i get a "warning bad vertexParm number" error.

fresnel_vertex

Code: [Select]
const float Eta = 0.67;          // Ratio of indices of refraction (air -> glass)
const float FresnelPower = 10.0; // Controls degree of reflectivity at grazing angles
 
const float F  = ((1.0 - Eta) * (1.0 - Eta)) / ((1.0 + Eta) * (1.0 + Eta));
 
varying vec3  Reflect;
varying vec3  Refract;
varying float Ratio;
 
attribute vec3 normal;
 
uniform vec3 viewer;
 
void main( void )
{
    vec4 worldPosition = calcWorldPos( gl_Vertex );
    vec3 ecPosition3  = worldPosition.xyz - viewer;
 
    vec3 i = normalize(ecPosition3);
    vec3 n = normalize( calcWorldVec(normal) );
 
    Ratio = F + (1.0 - F) * pow((1.0 - dot(-i, n)), FresnelPower);
    //Ratio = 1.0 - Ratio; // Add this line if your cube map is not based on the right side
 
    Refract = refract(i, n, Eta);
    Refract = vec3(gl_TextureMatrix[0] * vec4(Refract, 1.0));
 
 
    Reflect = reflect(i, n);
    Reflect = vec3(gl_TextureMatrix[0] * vec4(Reflect, 1.0));
 
 
    gl_Position   = gl_ModelViewProjectionMatrix * worldPosition;
}


fresnel_fragment

Code: [Select]
varying vec3  Reflect;
varying vec3  Refract;
varying float Ratio;
 
uniform samplerCube tex0;
 
void main(void)
{
    vec3 refractColor = vec3 (textureCube(tex0, Refract));
    vec3 reflectColor = vec3 (textureCube(tex0, Reflect));
 
    vec3 color   = mix(refractColor, reflectColor, Ratio);
 
    gl_FragColor = vec4(color, 1.0);
}

material calling the fresnel shader

Code: [Select]
textures/bod/rock/shiny_mot088
{
   surftype10 //tile

   qer_editorimage   textures/bod/rock/mot088_ed.jpg
   {
      blend      bumpmap         
      map         textures/bod/rock/mot088_local.tga
   }
   diffusemap     textures/bod/rock/mot088.tga
   specularmap     textures/bod/rock/mot088_s.tga
   
   {
      blend   blend
      mirrorRenderMap  128  128

      translate   0.5, 0.5
      scale      0.5, 0.5

      vertexProgram   fresnel_vertex.glsl
      vertexParm   Eta 0.67          // Ratio of indices of refraction (air -> glass)
      vertexParm  FresnelPower 10.0 // Controls degree of reflectivity at grazing angles
 
  fragmentProgram fresnel_fragment.glsl
      fragmentMap   tex0   _scratch

      alpha      0.6
   }

I'm a total noob at this shader thing so please be easy with me. :P 
 

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: RBDoom 3 engine (shader programs)
« Reply #1 on: March 28, 2015, 06:52:26 PM »
this material doesn't seem to call any shader

argoon

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
Re: RBDoom 3 engine (shader programs)
« Reply #2 on: March 28, 2015, 07:23:48 PM »
Isn't this parts on the material "vertexProgram   fresnel_vertex.glsl" and "fragmentProgram fresnel_fragment.glsl" used to call the glsl shader? Isn't that how vanilla doom 3 does it also?


Question for trevor - Is dmap fully functional?

I'm asking because i tried to dmap a simple map using RBDoom3 and it didn't worked.
« Last Edit: March 28, 2015, 07:25:59 PM by argoon »

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: RBDoom 3 engine (shader programs)
« Reply #3 on: March 28, 2015, 09:01:30 PM »
d3map is functional I've compiled several maps of mine and all worked fine. take a look tough to the launch options recommended in the modding section of the readme (12th section) you have to use several cvar in order for the engine to recognize your new content in the mod folder

on the vertex/fragment program issue, I've never tried to use a fragment in the bfg but maybe you can try to call an in-existing  vfp program that bears the same name as your glsl (sort of how the textures with heat-haze do it in the game) and then the engine will use the heat-haze

take a look in inolen water mod (you can see it in the section of "making water" in the darkmodwiki there is Vertex's or Inolen's water shader material which calls a fresnel vfp), try to make it call your program to see if it works ( sort of how d3bfg didn't contain the old vfp files but still they where called whithin the materials, and yet you could see heat-haze effects in d3 bfg)


motorsep

  • Hero Member
  • *****
  • Posts: 974
  • Karma: +74/-128
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: RBDoom 3 engine (shader programs)
« Reply #4 on: March 28, 2015, 09:22:35 PM »
I'm asking because i tried to dmap a simple map using RBDoom3 and it didn't worked.

Can you please elaborate ? I looked into RBDoom 3's dmap port, and while I haven't tried it, it looks like a lot of stuff is missing.

argoon

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
Re: RBDoom 3 engine (shader programs)
« Reply #5 on: March 29, 2015, 12:13:44 AM »
d3map is functional I've compiled several maps of mine and all worked fine. take a look tough to the launch options recommended in the modding section of the readme (12th section) you have to use several cvar in order for the engine to recognize your new content in the mod folder

Hum strange, about the cvar's i did that from the beginning. 

Quote from: BielBdeLuna
on the vertex/fragment program issue, I've never tried to use a fragment in the bfg but maybe you can try to call an in-existing  vfp program that bears the same name as your glsl (sort of how the textures with heat-haze do it in the game) and then the engine will use the heat-haze take a look in inolen water mod (you can see it in the section of "making water" in the darkmodwiki there is Vertex's or Inolen's water shader material which calls a fresnel vfp), try to make it call your program to see if it works ( sort of how d3bfg didn't contain the old vfp files but still they where called whithin the materials, and yet you could see heat-haze effects in d3 bfg)

Didn't worked "ERROR: While linking GLSL program 41 with vertexShader fresnel.vfp and fragmentShader fresnel.vfp"   but i suspect that is because my fresnel glsl is not really made for Doom3.

Can you please elaborate ? I looked into RBDoom 3's dmap port, and while I haven't tried it, it looks like a lot of stuff is missing.

A simple box map with a player start and a single light doesn't work on my end, this using RBDoom3 BFG dmap, when i start the map it just crashes the engine.
« Last Edit: March 29, 2015, 12:16:35 AM by argoon »

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: RBDoom 3 engine (shader programs)
« Reply #6 on: March 29, 2015, 05:17:50 AM »
if you try to dmap the map, and then after finished compiling you restart the engine, does then opening the map crash the engine?

argoon

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +21/-81
  • Doom Newbie
    • View Profile
Re: RBDoom 3 engine (shader programs)
« Reply #7 on: March 29, 2015, 12:42:40 PM »
if you try to dmap the map, and then after finished compiling you restart the engine, does then opening the map crash the engine?

Yes, tried it right now. On the maps that work for you, are you also using doom 3 assets or only custom assets? Be it textures and models.

btw i used Darkradiant to make the map. 
« Last Edit: March 29, 2015, 12:55:32 PM by argoon »

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: RBDoom 3 engine (shader programs)
« Reply #8 on: March 29, 2015, 03:11:57 PM »
well most of the code and enemies and models I used are d3 elements, but even if you set up a box map with a "info_player_start" this is already a d3 element.

I did my maps with Darkradiant like you. what does the compiling process say? what are the process of opening the map say?

nbohr1more

  • Jr. Member
  • **
  • Posts: 96
  • Karma: +13/-8
  • Doom Newbie
    • View Profile
Re: RBDoom 3 engine (shader programs)
« Reply #9 on: March 29, 2015, 09:02:50 PM »
Try replacing "fragmentProgram fresnel_fragment.glsl" with "fragmentProgram fresnel_fragment"
I believe the material parser adds the extension. That said, the shipping programs with BFG are labeled
*.vp and *.fp so you'd probably want to break your program into fragment and vertex programs and
use that naming convention.

trebor

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +14/-7
  • Boomstick Veteran
    • View Profile
Re: RBDoom 3 engine (shader programs)
« Reply #10 on: March 30, 2015, 06:56:32 AM »
Look at the base/renderprogs/  shaders. GLSL is not supported. You need to write your custom shader in Cg like heatHaze.vertex heatHaze.pixel.
It is automatically translated to GLSL/HLSL and whatever renderer backend is used.

And yes dmap is fully functional. I compiled all D3 maps with it on another branch.

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: RBDoom 3 engine (shader programs)
« Reply #11 on: March 30, 2015, 07:35:06 AM »
what? I don't get it, RBDoom3 doesn't use GLSL?

nbohr1more

  • Jr. Member
  • **
  • Posts: 96
  • Karma: +13/-8
  • Doom Newbie
    • View Profile
Re: RBDoom 3 engine (shader programs)
« Reply #12 on: March 30, 2015, 09:59:58 AM »
Ah, I thought something like that might be the case.

You can hard code GLSL calls in the source of course but to define shaders in materials you need to use Cg unless someone
adds a GLSL parser in the material system. The whole point of the Cg to GLSL system being a system to ease cross-platform
targets (and apparently native GLSL is a bugaboo of undefined performance cliffs so Cg does a better job of choosing
optimized paths for recompile... if you trust nvidia of course...)

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: RBDoom 3 engine (shader programs)
« Reply #13 on: March 30, 2015, 12:41:57 PM »
but, apparently Nvidia recommends to no longer use CG but GLSL because "future hardware features might not be supported", the material system parses the definitions to a shader language? I didn't know that, I always though it was a fixed point system where specific definitions did that and only that, in a defined c++ part of de renderer code.
« Last Edit: March 30, 2015, 12:44:13 PM by BielBdeLuna »

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: RBDoom 3 engine (shader programs)
« Reply #14 on: March 30, 2015, 01:11:11 PM »
I always thought it was work of the drivers to convert the GLSL (or whatever is the shader language the application is using) to whatever the hardware needed in order to render the scene

does the d3bfg engine transcode the material definition tokens to CG in the loading of the level? and then the engine also transcodes it to GLSL in order to use it with OpenGL commands? how much shaders does the engine use, because per level the engine could be using a lot of material definition commands, if so why not dump the material definitions and code every "texture needs" directly with GLSL (it would be less transcode work to the engine) or transcode the material definitions in the start of the game (all of them, at least once, and then you're always using GLSL

please tell me if Iím getting this wrong because I feel I'm getting it quite wrong.