News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

fhDOOM (modernized idTech4)

Started by eXistence, April 10, 2016, 12:35:13 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

MrC

Is this an MFC related issue? I remember having similar problems when I used VS express, although maybe this isn't an issue anymore? Unless you're not using express, anyway just a thought. Wish I could be more help.

argoon

#76
Yes it seams to be a MFC issue but i'm using VS2015 and by eXistence instructions i shouldn't need that?

I'm using the free community 2015 version it should be the full version not express, is for this reasons that i was trying to avoid messing with the source code.



edit: Solved it, seams MFC is not installed by default in vs2015 community you need to chose to install it at VS2015 install time, fortunately it asked me for a update and i was able to install MFC by updating the IDE.

MrC

Excellent, I had just compiled it myself with 2015 and was going to see what I might have had set differently. Glad to see you got it working, that's good information to know. Merry Christmas, Happy Holidays and all the rest to everyone. All the best.

argoon

Merry Christmas, Happy Holidays to everyone as well.  :)

motorsep

Happy Holidays and let's mod DOOM 2016 already!  O0

VGames

Get the latest on Perfected Doom 3 here - http://www.moddb.com/mods/perfected-doom-3-version-500

argoon

#81
eXistence i don't know if you still are reading this thread (or forum) but i have a couple questions/requests for you about fhDOOM, would be graceful for any reply.

First a explanation, I'm using your engine for a (non comercial) project of mine and i would like to be able to make custom glsl shaders for it (or at lest convert existant ARB shaders for it) but i'm just a noob at it, not a good thing when you want to do stuff i know :P , the problem is that next to my lack of serious knowledge on glsl and ARB shader programming, i also don't know how to write them in accord to the necessities of your engine, there's no documentation on it, from my days of messing with it on a trial and error style (cursing like crazy) i found at lest how to use your GLSL shaders on a material, is similar to the old ARB shaders but not exactly the same, happy with my progress, i decided to try convert a existant doom 3 fresnel ARB shader to GLSL, nice for me to learn and it would be useful, so I went read the old ARB documentation on the old ARB shader language, just to comprehend what all the MUL and ADD and SUB meant, at the same time tried to decifer the GLSL code that you used on your converted shaders, i opened the old ARB heatHaze code and your GLSL version and my chin dropped, it was not what i was expecting, they were very different, I didn't comprehend almost anything, even so i didn't gave up, read a little more gained some wisdom on it and decided to try to convert the fresnel ARB shader, exactly how it was written on ARB but using GLSL C like language and because i know how to code (at beginner level), i just thought, that couldn't be that hard? And a abomination was born, it does not work i only see a big white square on screen and i'm pretty sure i'm just clueless and this is not how it is done, i would like if you:

1: convert the fresnel ARB shader into GLSL for me in the proper way, with code comments if possible, so i see the diferences and how it is done.

2: if that is not possible at lest tell me if i'm going in the right direction, what i need to change, if i need to research some topic or is better for me to try another hobby. :P

The ARB code


# Fresnel shader written by inolen 2005
# http://www.inolen.com

#################
# vertex shader #
#################

!!ARBvp1.0
OPTION ARB_position_invariant;

TEMP R1, R2, R3, R4;

SUB R1, program.env[5], vertex.position;
DP3 R2, R1, R1;
RSQ R2, R2.x;
MUL R1, R1, R2.x;

DP3 R2, R1, vertex.normal;

SUB R3, 1.0, R2;

MUL R4, R3, R3;

MUL R4, R4, R3;

MUL R4, R4, R3;

MUL R4, R4, R3;

SUB R3, 1.0, program.local[0];

MAD result.texcoord[2].x, R4, R3, program.local[0];

END

################
# pixel shader #
################

!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

TEMP A, C;

MUL A, fragment.position, program.env[1];

TEX C, A, texture[0], 2D;

MOV result.color, C;

MOV result.color.a, fragment.texcoord[2].x;

END



My abomination of GLSL code           be gentle...

vertex shader


#include "global.inc"

layout(location = 0) in vec3 vertex_position;
layout(location = 1) in vec2 vertex_texcoord;
layout(location = 2) in vec3 vertex_normal;
layout(location = 3) in vec4 vertex_color;
layout(location = 4) in vec3 vertex_binormal;
layout(location = 5) in vec3 vertex_tangent;

out vs_output
{
  vec3 R1;
  vec3 R2;
  vec3 R3;
  vec3 R4;
  vec3 pos;
  vec2 texcoord;
} result;


void main(void)
{
gl_Position = rpProjectionMatrix * rpModelViewMatrix * vec4(vertex_position, 1.0);

  result.pos = rpLocalViewOrigin.xyz;
  result.R1 = SUB(result.pos, vertex_position);
  result.R2 = sqrt( dot(R1, R1).x );
  result.R1 = R1 * R2.x;
 
  result.R2 = dot(R1, vertex_normal);
  result.R3 = SUB( 1.0, R2 );
  result.R4 = R3 * R3;
  result.R4 = (R4 * R3 ) * 3;
  result.R3 = SUB( 1.0, vertex_position);

  result.texcoord.x = (R4 * R3 ) + vertex_position;
}

vec3 SUB(vec3 op1, vec3 op2)
{
vec3 _result;

_result.x = op1.x - op2.x;
_result.y = op1.y - op2.y;
_result.z = op1.z - op2.z;

return _result;
}


fragment shader


#include "global.inc"

layout(binding = 1) uniform sampler2D texture1;

in vs_output
{
vec4 color;
vec2 A;
vec2 texcoord;
} frag;

out vec4 result;

// texture 0 is the cube map
// texture 1 is the per-surface bump map
// texture 2 is the light falloff texture
// texture 3 is the light projection texture
// texture 4 is the per-surface diffuse map
// texture 5 is the per-surface specular map
// texture 6 is the specular lookup table

void main(void)

frag.texcoord = texture2D(texture1, result.texcoord.xy) * texture1.xy + texture1.zw );
frag.A = frag.texcoord * rpSpecularColor;

frag.color = frag.A;
frag.color.a = result.texcoord.x;
}


My GLSL code doesn't work because it doesn't compile :s (obviously)  the console  prints errors about "undeclared identifier" R1 R2 etc don't see how that could be true, i declared them exactly like you did on your shaders and - cannot convert from "float" to "default out high 3-component vector of vector3", thinking about it as i write this, perhaps is the naming of the variables the numbers could be causing problems... 
I also forgot to include a function declaration for the SUB function (that i think is not even necessary but i did it like that at first just because the ARB docs show that its what SUB cmd does if coded in C, i didn't made the others like MUL, etc, in the same way because was redundant, in my recent modifications to the code i don't use it anymore.   

eXistence

from time to time i take a look at the forum.

don't look at heathaze.fp to learn how to port ARB to GLSL, because heathaze.fp is not a straight port.
heathaze.fp was the very first shader i re-wrote and i experimented a lot with it. The current version achieves a very similar effect, but is implemented differently.

IIRC heathazewithmaskandvertex is much closer to the original ARB shader.

It's hard for me find any time for fhDOOM at all, so i probably won't look into the details of your fresnel shader any time soon.
A few things i noticed after glancing over your GLSL:
* R1 and others are indeed undefined, you probably meant result.R1
* output of vertex shader and input of fragment shader must be equal (look at vs_output)
* R1, R2, etc. should be temporary values ('R' for register), you only need them in your vertex shader (don't pass them to fragment shader)

the new shader system is pretty much undocumented. I could write something up, but it won't help you very much when you are totally new to writing shaders. Writing shaders is not that trivial, especially with an engine like idTech4. The whole shader thing is pretty much hacked on top of Doom3's fixed-function-style material system. The shader system is not that cleanly designed and integrated like in a more modern engine.

argoon

Quote from: eXistence on April 18, 2017, 12:25:15 PM

don't look at heathaze.fp to learn how to port ARB to GLSL, because heathaze.fp is not a straight port.
heathaze.fp was the very first shader i re-wrote and i experimented a lot with it. The current version achieves a very similar effect, but is implemented differently.

IIRC heathazewithmaskandvertex is much closer to the original ARB shader.


Hello eXistence thanks for taking the time to reply, i will study heathazewithmaskandvertex to see what i can learn.


Quote from: eXistence on April 18, 2017, 12:25:15 PM

It's hard for me find any time for fhDOOM at all, so i probably won't look into the details of your fresnel shader any time soon.


Sad news about not having time for fhDOOM imo is a very nice engine, sad knowing its development could stagnate but i comprehend, working on it doesn't put food on the table, thanks for the changes to idtech4 you made this far and good luck with whatever you decided to do.

Quote from: eXistence on April 18, 2017, 12:25:15 PM
A few things i noticed after glancing over your GLSL:
* R1 and others are indeed undefined, you probably meant result.R1
* output of vertex shader and input of fragment shader must be equal (look at vs_output)
* R1, R2, etc. should be temporary values ('R' for register), you only need them in your vertex shader (don't pass them to fragment shader)


1) Ok i see what you mean i should have used result.R1 = result.Rx instead of result.R1 = Rx, etc.  facepalm

2) About the in and out struct's, yes i realized they should be equal by seeing the other glsl shaders you made, i just don't know exactly why but on my latest code i made them equal.

3) What do you mean by temporary? I think of them as variables just like in doomScript or C++, a place in memory where i save some type of value, the only way that i can think of making them temporary is if i replace the value in it for another?

3a) Ok i think i know what you mean about only needing them on the vertex shader, lets see they are just used as temp variables inside the vertex shader to calculate the reflection índice we don't need them in the pixel shader (frag shader) we just need the final result from the vertex shader calculation, i'm right?


Quote from: eXistence on April 18, 2017, 12:25:15 PM

the new shader system is pretty much undocumented. I could write something up, but it won't help you very much when you are totally new to writing shaders. Writing shaders is not that trivial, especially with an engine like idTech4. The whole shader thing is pretty much hacked on top of Doom3's fixed-function-style material system. The shader system is not that cleanly designed and integrated like in a more modern engine.

Please do, if you have some time to write something about the shader system, even if i'm new to all of it, will always help, me and others.

Yes writing shaders is not trivial and from my foray into it, i think i will stay at converting existent shaders if possible, because the maths on it are pretty much over my head.

Even if is not cleanly design and integrated does it work as expected for the most part? 


BTW after some google searchs on shaders specially fresnel shaders i found this link on there you find the next HLSL vertex shader and frag shader:

VS
vOUT vert(vIN v)
{
vOUT o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord;

float3 posWorld = mul(_Object2World, v.vertex).xyz;
float3 normWorld = normalize(mul(float3x3(_Object2World), v.normal));

float3 I = normalize(posWorld - _WorldSpaceCameraPos.xyz);
o.R = _Bias + _Scale * pow(1.0 + dot(I, normWorld), _Power);

return o;
}


FS
float4 frag(vOUT i) :  COLOR

float4 col = tex2D(_MainTex, i.uv.xy * _MainTex_ST.xy + _MainTex_ST.zw);
return lerp(col,_Color, i.R);
}


I then tried to convert it to GLSL for fhDOOM

This was what i came up with, still doesn't compile but at lest i'm only getting a single the error now:

[b]VS[/b]
out vs_output
{
vec4 color;
vec2 texcoord;
} result;

void main(void)
{
  gl_Position = rpProjectionMatrix * rpModelViewMatrix * vec4(vertex_position, 1.0);

result.texcoord = vertex_texcoord;

vec4 _Bias = shaderParm0;
vec4 _Scale = shaderParm1;
vec4 _Power = shaderParm2;

vec4 posWorld = rpModelMatrix * vec4(vertex_position, 1.0);
vec4 normWorl = normalize(rpModelMatrix * vec4(vertex_normal, 1.0));
 
vec4 I = normalize(posWorld - rpLocalViewOrigin);
float dotR = dot(I, normWorl);
result.color = _Bias + _Scale * pow(1.0 + vec4(dotR, 1.0, 1.0), _Power);

}

[b]FS[/b]
in vs_output
{
vec4 color;
vec2 texcoord;
} frag;

out vec4 result;


void main(void)

frag.color = texture2D(texture1, result.texcoord);

result = mix(frag.color, result.color);
}

Quoteerror #174 - Not enough data provided for construction constructor

walking the path there, pretty sure is something basic that i'm just ignorant about.

Any input from you or anyone else would be awesome, cheers.

argoon

after doing what eXistance suggested and seeing how he converted heathazewithmaskandvertex this is what my fresnel shader now looks like (inspired again on the ARB version).

VS
out vs_output
{
vec4 color;
vec2 texcoord2;
} result;

void main(void)
{
  gl_Position = rpProjectionMatrix * rpModelViewMatrix * vec4(vertex_position, 1.0);


float rTWO,rTHREE,rFOUR;

result.color = vertex_color;

vec4 rONE = rpLocalViewOrigin - vec4(vertex_position, 1.0);

rTWO = dot(rONE, rONE);
rTWO = sqrt(rTWO);
rONE = rONE * rTWO;
rTWO = dot(rONE, vec4(vertex_normal, 1));
rTHREE = 1.0 - rTWO;
rFOUR = rTHREE * rTHREE;
rFOUR = (rFOUR * rTHREE ) * 3;
rTHREE = 1.0 - shaderParm0;

  result.texcoord2.x = (rFOUR * rTHREE ) + shaderParm0;
}


FS
in vs_output
{
vec4 color;
vec2 texcoord2;
} frag;

out vec4 result;

// texture 0 is the cube map
// texture 1 is the per-surface bump map
// texture 2 is the light falloff texture
// texture 3 is the light projection texture
// texture 4 is the per-surface diffuse map
// texture 5 is the per-surface specular map
// texture 6 is the specular lookup table

void main(void)

vec4 A;
vec4 C;

//calculate the screen texcoord in the 0.0 to 1.0 range
A = vec4(gl_FragCoord.x/rpCurrentRenderSize.z, gl_FragCoord.y/rpCurrentRenderSize.w, 0, 0);

C = texture2D(A,texture1);

frag.color = C;
frag.color.a = frag.texcoord2.x;
}



Still doesn't compile

I Get two type conversion errors something like "cannot convert from vec4 to high float" that i can't seem to know how to solve and because the error massages don't tell what line of the shader code gives the error is very hard to debugg. :(

bitterman

Try to exclude shaderParm0 from VS, then try to compile it.

And 'vec4(vertex_position, 1.0)' expression looks strange for me.

argoon

Quote from: bitterman on April 20, 2017, 09:30:40 AM
Try to exclude shaderParm0 from VS, then try to compile it.

And 'vec4(vertex_position, 1.0)' expression looks strange for me.


I will try but the original ARB uses that shaderParm0 but instead refers to it as program.local
  • , on my new modification i found that it was a vec4 so i changed it to a float by using a single component of the vec4.

    That  'vec4(vertex_position, 1.0)' expression is exactly how eXistence  wrote it on all its shaders when he wanted to convert a vec3 to a vec4.

    Btw was able to make it compile now, the fragment shader also gave me no end of trouble, some times the ARB to GLSL conversion is very straight forward other times you need to really think it through.   
    It works but I didn't tested if it is rendering exactly like the ARB version, need to test and see.

    Here is my new version

    VS

    out vs_output
    {
    vec4 color;
    vec2 texcoord2;
    } result;

    void main(void)
    {
      gl_Position = rpProjectionMatrix * rpModelViewMatrix * vec4(vertex_position, 1.0);


    float rTWO,rTHREE,rFOUR;

    result.color = vertex_color;

    vec4 rONE = rpLocalViewOrigin - vec4(vertex_position, 1.0);

    rTWO = dot(rONE, rONE);
    rTWO = sqrt(rTWO);
    rONE = rONE * rTWO;
    rTWO = dot(rONE, vec4(vertex_normal, 1.0));
    rTHREE = 1.0 - rTWO;
    rFOUR = rTHREE * rTHREE;
    rFOUR = (rFOUR * rTHREE ) * 3;
    rTHREE = 1.0 - shaderParm0.x;

      result.texcoord2.x = (rFOUR * rTHREE ) + shaderParm0.x;
    }


    FS

    layout(binding = 1) uniform sampler2D texture1;


    in vs_output
    {
    vec4 color;
    vec2 texcoord2;
    } frag;

    out vec4 result;

    // texture 0 is the cube map
    // texture 1 is the per-surface bump map
    // texture 2 is the light falloff texture
    // texture 3 is the light projection texture
    // texture 4 is the per-surface diffuse map
    // texture 5 is the per-surface specular map
    // texture 6 is the specular lookup table

    void main(void)

    vec4 A;
    vec4 C;
    float alpha;

    //calculate the screen texcoord in the 0.0 to 1.0 range
    A = vec4(gl_FragCoord.x/rpCurrentRenderSize.z, gl_FragCoord.y/rpCurrentRenderSize.w, 0, 0);

    C = frag.color;
    alpha = frag.color.a;
    alpha = frag.texcoord2.x;
    result = texture2D(texture1, A.xy);
    }

argoon

#87
Don't know if is my GLSL that is badly translated, or if is other reason but testing the ARB in the vanilla idtech4 material editor and the GLSL in the fhdoom material editor show different results in a very similar material.

See the attachment.


argoon

#88
This is my latest fresnel conversion i'm almost sure it is the most faitfull to the original ARB version but still the rendering is different.

VS

#include "global.inc"

layout(location = 0) in vec3 vertex_position;
layout(location = 1) in vec2 vertex_texcoord;
layout(location = 2) in vec3 vertex_normal;
layout(location = 3) in vec4 vertex_color;
layout(location = 4) in vec3 vertex_binormal;
layout(location = 5) in vec3 vertex_tangent;


invariant out vs_output
{
vec4 color;
vec2 texcoord2;
} result;

void main(void)
{
  gl_Position = rpProjectionMatrix * rpModelViewMatrix * vec4(vertex_position, 1.0);


float rTWO,rTHREE,rFOUR;

result.color = vertex_color;
result.texcoord2 = vertex_texcoord;

vec4 rONE = rpLocalViewOrigin - vec4(vertex_position, 1.0);

rTWO = dot(rONE.xyz, rONE.xyz);
rTWO = ( 1.0 / sqrt(rTWO.x) );
rONE = rONE * rTWO.x;

rTWO = dot(rONE.xyz, vertex_normal);

rTHREE = 1.0 - rTWO;

rFOUR = ( rTHREE * rTHREE ) + ( (rFOUR * rTHREE ) * 3 ) ;
//rFOUR = (rFOUR * rTHREE ) * 3;

rTHREE = 1.0 - shaderParm0.x;

result.texcoord2.x = (rFOUR * rTHREE ) + shaderParm0.x;
}


FS

#include "global.inc"

layout(binding = 0) uniform sampler2D texture0;


in vs_output
{
vec4 color;
vec2 texcoord2;
} frag;

out vec4 result;

// texture 0 is the cube map
// texture 1 is the per-surface bump map
// texture 2 is the light falloff texture
// texture 3 is the light projection texture
// texture 4 is the per-surface diffuse map
// texture 5 is the per-surface specular map
// texture 6 is the specular lookup table

vec2 fixScreenTexCoord(vec2 st)
{
  float x = rpCurrentRenderSize.z / rpCurrentRenderSize.x;
  float y = rpCurrentRenderSize.w / rpCurrentRenderSize.y;
  return st * vec2(x, y); 
}

void main(void)

vec2 A;
vec4 C;
vec4 targetColor;
float targetColorAlpha;

targetColor = frag.color;
targetColorAlpha = frag.color.a;

//calculate the screen texcoord in the 0.0 to 1.0 range
A = gl_FragCoord.xy / rpCurrentRenderSize.zw;

C = texture2D(texture0, fixScreenTexCoord(A));
//C = texture2D(texture0, A);

targetColor = C;
targetColorAlpha = frag.texcoord2.x;

vec3 col = targetColor.rgb;

result = vec4(col,targetColorAlpha);
}



UPDATE 1 - More modifications to the shader, still doesn't render exactly like the ARB version. :(

- On the original ARB shader the var A is done with a MUL (multiplication), like so:

MUL A, fragment.position, program.env[1];

- On all converted shaders from eXistence i see that he uses instead:

A = gl_FragCoord.xy / rpCurrentRenderSize.zw;   
OR
vec4 screenTexCoord = vec4(gl_FragCoord.x/rpCurrentRenderSize.z, gl_FragCoord.y/rpCurrentRenderSize.w, 0, 0);

I assume fragment.position is gl_FragCoord and program.env[1] is rpCurrentRenderSize, i just don't know why he uses that divisions instead of a straight multiplication like in the ARB version, perhaps it has something to do with GLSL not being cleanly implemented in the engine like he said?

eXistence

#89
send me (via PM) full examples (map, materials, shaders, textures, etc.) for ARB and GLSL version and i will take a closer look at.