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

Gloss control in interaction.vfp

Started by Zombie, October 08, 2014, 09:21:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zombie

Hello,

Is it possible to edit the interaction program to allow the use of gloss maps?

I don't care for keeping it compatible with stock assets, as I am making all new ones. And I'd be ok with a sperate specific gloss map texture.

I don't know assembly at all so I can't even begin to know what I must change to get this to work, if anyone knows, do you think you could get them to have a go at it?

Thanks!

motorsep

Afaik engine changes are required too.

Zombie

#2
That's a bummer.

it's not a big problem. I might just have to jump ship to Prey. It has usable gloss control using a value in the material. I get the results I want.

Bladeghost

Take a look at the interaction and test .vfp's in my Blade Yautja mod, It's what I used to get the aliens and environment glossed up. Those might help. they both need to be used to work, for vanilla D3.

Bladeghost

That's interesting, is that just a material variable. by the way Nice rock pack as I had a chance to have a look, much better than the stock sharprock that comes with D3.

Zombie

Yeah with the interaction shader change, you just tweak the values to get the results you need along with your specular map.

I made a little sample map to try out gloss on different surfaces.


Bladeghost

It's not the same effect as with the glprogs, as they are more intense. these seem to be more subtle. at first how you described it as a interaction shader was confusing believing it had to do with vfp's where its a .mtr variable with the code posted.

Bladeghost

#7
glprogs:
interaction.vfp and test.vfp posted below:

interaction.vfp
###==============================================================================
# Doom 3 Interaction Vertex/Fragment Program
#
# Cook-Torrance Lighting Model w/ Relief Mapping (Isotropic)
###==============================================================================
#
# --------------------------------------
# input:
#
# attrib[8] = texture coordinates
# attrib[9] = global tangent
# attrib[10] = global bitangent
# attrib[11] = global normal
#
# env[0]  = diffuse modifier
# env[1]  = specular modifier
# env[2]  = ?
# env[3]  = ?
# env[4]  = localLightOrigin
# env[5] = localViewOrigin
# env[6] = lightProjection S
# env[7] = lightProjection T
# env[8] = lightProjection Q
# env[9] = lightFalloff S
# env[10] = bumpMatrix S
# env[11] = bumpMatrix T
# env[12] = diffuseMatrix S
# env[13] = diffuseMatrix T
# env[14] = specularMatrix S
# env[15] = specularMatrix T
# env[16] = vertex color modulate
# env[17] = vertex color add
#
#--------------------------------------
# output:
#
# texture 0 = normalization cube map
# texture 1 = per-surface normal map
# texture 2 = 1D light falloff texture
# texture 3 = 2D light projection texture
# texture 4 = per-surface diffuse map
# texture 5 = per-surface specular map
# texture 6 = specular lookup table
#
#--------------------------------------
###==============================================================================

!!ARBvp1.0
OPTION ARB_position_invariant;

# Instruction Count: 25

PARAM defaultTexCoord = { 0.0, 0.5, 0.0, 1.0 };
PARAM projMatrix[4] = { state.matrix.projection };

TEMP R0;

# calculate vector to light in R0
SUB R0, program.env[4], vertex.position;

# put into texture space for TEX0
DP3 result.texcoord[0].x, vertex.attrib[9], R0;
DP3 result.texcoord[0].y, vertex.attrib[10], R0;
DP3 result.texcoord[0].z, vertex.attrib[11], R0;

# texture 1 takes the base coordinates by the texture matrix
MOV result.texcoord[1], defaultTexCoord;
DP4 result.texcoord[1].x, vertex.attrib[8], program.env[10];
DP4 result.texcoord[1].y, vertex.attrib[8], program.env[11];

# texture 2 has one texgen
MOV result.texcoord[2], defaultTexCoord;
DP4 result.texcoord[2].x, vertex.position, program.env[9];

# texture 3 has three texgens
DP4 result.texcoord[3].x, vertex.position, program.env[6];
DP4 result.texcoord[3].y, vertex.position, program.env[7];
DP4 result.texcoord[3].w, vertex.position, program.env[8];

# texture 4 takes the base coordinates by the texture matrix
MOV result.texcoord[4], defaultTexCoord;
DP4 result.texcoord[4].x, vertex.attrib[8], program.env[12];
DP4 result.texcoord[4].y, vertex.attrib[8], program.env[13];

# texture 5 takes the base coordinates by the texture matrix
MOV result.texcoord[5], defaultTexCoord;
DP4 result.texcoord[5].x, vertex.attrib[8], program.env[14];
DP4 result.texcoord[5].y, vertex.attrib[8], program.env[15];

# calculate vector to viewer in R0
SUB R0, program.env[5], vertex.position;

# put into texture space for TEX6
DP3 result.texcoord[6].x, vertex.attrib[9], R0;
DP3 result.texcoord[6].y, vertex.attrib[10], R0;
DP3 result.texcoord[6].z, vertex.attrib[11], R0;

# transform world space normal vector
DP3 result.texcoord[7].x, vertex.attrib[9], projMatrix[2];
DP3 result.texcoord[7].y, vertex.attrib[10], projMatrix[2];
DP3 result.texcoord[7].z, vertex.attrib[11], projMatrix[2];

# generate the vertex color, which can be 1.0, color, or 1.0 - color
# for 1.0 : env[16] =  0.0, env[17] = 1.0
# for color : env[16] =  1.0, env[17] = 0.0
# for 1.0 - color : env[16] = -1.0, env[17] = 1.0
MAD result.color, vertex.color, program.env[16], program.env[17];

END

#==================================================================================

!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

# Instruction Count: ALU: 145 TEX: 27 Total: 172

OUTPUT oColor = result.color;
ATTRIB vColor = fragment.color;

ATTRIB lightVecTC = fragment.texcoord[0];
ATTRIB normalTC = fragment.texcoord[1];
ATTRIB lightFallTC = fragment.texcoord[2];
ATTRIB lightProjTC = fragment.texcoord[3];
ATTRIB diffuseTC = fragment.texcoord[4];
ATTRIB specularTC = fragment.texcoord[5];
ATTRIB viewVecTC = fragment.texcoord[6];
ATTRIB wNormal = fragment.texcoord[7];

PARAM lightColor = program.env[0];

PARAM constval = { 1.0,    2.0,    4.0,    5.0  };
PARAM constval2 = { 0.125,  0.25,   0.5,    0.75 };
PARAM grayscale = { 0.3,    0.59,   0.11  };
PARAM hemiLight = { 0.25,   0.25,  -1.0   };
PARAM skyColor = { 0.5,    0.5,    0.5   };
PARAM grndColor = { 1.0,    1.0,    1.0   };
PARAM epsilon = { 1.0,    0.0,    0.0   };
PARAM specParm = { 0.2,    0.1,    0.425 };
PARAM e = { 2.7182818284590452353602874713527 };
PARAM reliefParm = { 0.0425, 0.0625 };

TEMP RT;
TEMP lightVec, viewVec, halfVec, normalVec, wNormalVec;
TEMP diffuse, specular, gloss, color, ambient;
TEMP light, hemi, atten, rim, lightFall, lightProj;
TEMP geometric, roughness, fresnel;
TEMP NdotA, NdotL, NdotV, NdotH, VdotH, VdotL;
TEMP R1, R2;


#[FPO] relief mapping: view vector with depth factor
###======================================================================
DP3 viewVec, viewVecTC, viewVecTC;
RSQ viewVec, viewVec.x;
MUL viewVec, viewVec.x, viewVecTC;

RCP R1.x, viewVec.z; # R1 = 1.0 / viewVec.z
MUL viewVec.xy, viewVec, reliefParm.x; # viewVec.xy *= depth
MUL viewVec, viewVec, -R1.x; # viewVec *= -R1
MUL viewVec, viewVec, reliefParm.y; # viewVec /= 16.0

MOV RT, normalTC; # RT = texcoord
MOV RT.z, constval.x; # RT.z = 1.0

#[FPO] relief mapping: linear search (15 steps)
###======================================================================
TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MAD RT, viewVec, R2.w, RT; # RT += viewVec;

#[FPO] relief mapping: binary search (6 steps)
###======================================================================
TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
MUL viewVec, viewVec, constval2.z; # viewVec *= 0.5
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MUL R2, viewVec, R2.w; #
MAD RT, R2, constval.y, RT; # RT += viewVec * 2;
SUB RT, RT, viewVec; # RT -= viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
MUL viewVec, viewVec, constval2.z; # viewVec *= 0.5
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MUL R2, viewVec, R2.w; #
MAD RT, R2, constval.y, RT; # RT += viewVec * 2;
SUB RT, RT, viewVec; # RT -= viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
MUL viewVec, viewVec, constval2.z; # viewVec *= 0.5
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MUL R2, viewVec, R2.w; #
MAD RT, R2, constval.y, RT; # RT += viewVec * 2;
SUB RT, RT, viewVec; # RT -= viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
MUL viewVec, viewVec, constval2.z; # viewVec *= 0.5
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MUL R2, viewVec, R2.w; #
MAD RT, R2, constval.y, RT; # RT += viewVec * 2;
SUB RT, RT, viewVec; # RT -= viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
MUL viewVec, viewVec, constval2.z; # viewVec *= 0.5
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MUL R2, viewVec, R2.w;
MAD RT, R2, constval.y, RT; # RT += viewVec * 2;
SUB RT, RT, viewVec; # RT -= viewVec;

TEX R1, RT, texture[5], 2D; # R1 = tex(RT)
MUL viewVec, viewVec, constval2.z; # viewVec *= 0.5
SLT R2.w, R1.w, RT.z; # if ( R1.w < RT.z )
MUL R2, viewVec, R2.w; #
MAD RT, R2, constval.y, RT; # RT += viewVec * 2;
SUB RT, RT, viewVec; # RT -= viewVec;

###======================================================================

# calculate texcoords for diffuse and specular maps
SUB R1, diffuseTC, normalTC;
SUB R2, specularTC, normalTC;
ADD R1, R1, RT;
ADD R2, R2, RT;

# load texture maps
TEX ambient, lightVecTC, texture[0], CUBE;
TEX normalVec, RT, texture[1], 2D;
TXP lightFall, lightFallTC, texture[2], 2D;
TXP lightProj, lightProjTC, texture[3], 2D;
TEX diffuse, R1, texture[4], 2D;
TEX gloss, R2, texture[5], 2D;

# normalize the vector to the light
DP3 lightVec.x, lightVecTC, lightVecTC;
RSQ lightVec.x, lightVec.x;
MUL lightVec.xyz, lightVec.x, lightVecTC;

# normalize the vector to the viewer
DP3 viewVec.x, viewVecTC, viewVecTC;
RSQ viewVec.x, viewVec.x;
MUL viewVec.xyz, viewVec.x, viewVecTC;

# calculate the half angle vector and normalize
ADD halfVec, lightVec, viewVec;
DP3 R1.x, halfVec, halfVec;
RSQ R1.x, R1.x;
MUL halfVec.xyz, halfVec, R1.x;

# scale normal vector to -1.0<->1.0 range and normalize
MAD normalVec.xyz, normalVec.wyzx, constval.y, -constval.x;
DP3 R1.x, normalVec, normalVec;
RSQ R1.x, R1.x;
MUL normalVec.xyz, normalVec, R1.x;

# transform surface normal into world space
XPD R1, wNormal, epsilon;
XPD R2, wNormal, R1;
DP3 wNormalVec.x, normalVec, R1;
DP3 wNormalVec.y, normalVec, R2;
DP3 wNormalVec.z, normalVec, wNormal;

# calculate vector dot products
DP3 NdotL.x, normalVec, lightVec;
DP3 NdotV.x, normalVec, viewVec;
DP3 NdotH.x, normalVec, halfVec;
DP3 VdotH.x, viewVec, halfVec;
DP3_SAT VdotL.x, viewVec, -lightVec;

# calculate roughness parm using specular map
DP3 R1.x, gloss, grayscale;
SUB R1.x, constval.x, R1.x;
MAD R1.x, R1.x, specParm.x, specParm.y;

# calculate microfacet distribution term (Beckmann Distribution)
MAX NdotH.x, NdotH.x, 0.00001; # sikk - Ambient lighting fix
MUL R1.z, R1.x, R1.x;
POW R1.x, NdotH.x, constval.z;
MUL R1.y, R1.z, constval.z;
MUL R1.x, R1.x, R1.y;
RCP roughness.x, R1.x;
MUL R1.x, NdotH.x, NdotH.x;
SUB R1.y, constval.x, R1.x;
MUL R1.x, R1.x, R1.z;
RCP R1.x, R1.x;
MUL R1.x, R1.x, R1.y;
POW roughness.y, e.x, -R1.x;
MUL roughness.w, roughness.x, roughness.y;

# calculate geometric attenuation term
MUL R1.x, NdotH.x, constval.y;
RCP R1.y, VdotH.x;
MUL geometric.x, R1.x, NdotV.x;
MUL geometric.y, R1.x, NdotL.x;
MUL geometric.x, geometric.x, R1.y;
MUL geometric.y, geometric.y, R1.y;
MIN geometric.w, geometric.x, geometric.y;
MIN geometric.w, geometric.w, constval.x;

# calculate Fresnel term (Schlick approximation)
SUB_SAT R1.x, constval.x, NdotV.x;
POW fresnel.x, R1.x, constval.w;
LRP fresnel.w, specParm.z, constval.x, fresnel.x;

# calculate final specular term
MUL R1.x, roughness.w, geometric.w;
MUL R1.x, R1.x, fresnel.w;
MUL R1.y, NdotV.x, NdotL.x;
RCP R1.y, R1.y;
MUL specular, R1.x, R1.y;

# modulate specular by gloss map and add diffuse color
MAD color, specular, gloss, diffuse;

# calculate self shadowing
MAD_SAT R1.x, normalVec.z, lightVec.z, constval2.x;
MUL_SAT R1.x, R1.x, constval.z;
MUL light, R1.x, NdotL.x;

# calculate hemisphere lighting ambient term
DP3 hemi.x, wNormalVec, hemiLight;
MAD hemi.x, hemi.x, constval2.z, constval2.z;
LRP hemi, hemi.x, skyColor, grndColor;
SUB R1.x, ambient.w, constval2.w;
CMP light, R1.x, hemi, light;

# calculate attenuation using the light falloff and projection maps
MUL atten, lightFall, lightProj;

# modulate light by attenuation
MUL light, light, atten;

# rim light
MUL_SAT rim, fresnel.x, VdotL.x;
ADD color, color, rim;

# modulate by light and light color
MUL color, color, light;
MUL color, color, lightColor;

# modify by the vertex color
MUL oColor.xyz, color, vColor;

END


test.vfp:
###==============================================================================
# Doom 3 Interaction Vertex/Fragment Program
#
# Blinn-Phong Lighting Model w/ Parallax Occlusion Mapping (Isotropic)
###==============================================================================
#
# --------------------------------------
# input:
#
# attrib[8] = texture coordinates
# attrib[9] = global tangent
# attrib[10] = global bitangent
# attrib[11] = global normal
#
# env[0]  = diffuse modifier
# env[1]  = specular modifier
# env[2]  = ?
# env[3]  = ?
# env[4]  = localLightOrigin
# env[5] = localViewOrigin
# env[6] = lightProjection S
# env[7] = lightProjection T
# env[8] = lightProjection Q
# env[9] = lightFalloff S
# env[10] = bumpMatrix S
# env[11] = bumpMatrix T
# env[12] = diffuseMatrix S
# env[13] = diffuseMatrix T
# env[14] = specularMatrix S
# env[15] = specularMatrix T
# env[16] = vertex color modulate
# env[17] = vertex color add
#
#--------------------------------------
# output:
#
# texture 0 = normalization cube map
# texture 1 = per-surface normal map
# texture 2 = 1D light falloff texture
# texture 3 = 2D light projection texture
# texture 4 = per-surface diffuse map
# texture 5 = per-surface specular map
# texture 6 = specular lookup table
#
#--------------------------------------
###==============================================================================

!!ARBvp1.0
OPTION ARB_position_invariant;

# Instruction Count: 25

PARAM defaultTexCoord = { 0.0, 0.5, 0.0, 1.0 };
PARAM hemiLightVec = { 0.25, 0.25, -1.0 };

TEMP R0;

# calculate vector to light in R0
SUB R0, program.env[4], vertex.position;

# put into texture space for TEX0
DP3 result.texcoord[0].x, vertex.attrib[9], R0;
DP3 result.texcoord[0].y, vertex.attrib[10], R0;
DP3 result.texcoord[0].z, vertex.attrib[11], R0;

# texture 1 takes the base coordinates by the texture matrix
MOV result.texcoord[1], defaultTexCoord;
DP4 result.texcoord[1].x, vertex.attrib[8], program.env[10];
DP4 result.texcoord[1].y, vertex.attrib[8], program.env[11];

# texture 2 has one texgen
MOV result.texcoord[2], defaultTexCoord;
DP4 result.texcoord[2].x, vertex.position, program.env[9];

# texture 3 has three texgens
DP4 result.texcoord[3].x, vertex.position, program.env[6];
DP4 result.texcoord[3].y, vertex.position, program.env[7];
DP4 result.texcoord[3].w, vertex.position, program.env[8];

# texture 4 takes the base coordinates by the texture matrix
MOV result.texcoord[4], defaultTexCoord;
DP4 result.texcoord[4].x, vertex.attrib[8], program.env[12];
DP4 result.texcoord[4].y, vertex.attrib[8], program.env[13];

# texture 5 takes the base coordinates by the texture matrix
MOV result.texcoord[5], defaultTexCoord;
DP4 result.texcoord[5].x, vertex.attrib[8], program.env[14];
DP4 result.texcoord[5].y, vertex.attrib[8], program.env[15];

# calculate vector to viewer in R0
SUB R0, program.env[5], vertex.position;

# put into texture space for TEX6
DP3 result.texcoord[6].x, vertex.attrib[9], R0;
DP3 result.texcoord[6].y, vertex.attrib[10], R0;
DP3 result.texcoord[6].z, vertex.attrib[11], R0;

# put hemi-light vector into texture space for TEX7
DP3 result.texcoord[7].x, vertex.attrib[9], hemiLightVec;
DP3 result.texcoord[7].y, vertex.attrib[10], hemiLightVec;
DP3 result.texcoord[7].z, vertex.attrib[11], hemiLightVec;

# generate the vertex color, which can be 1.0, color, or 1.0 - color
# for 1.0 : env[16] =  0.0, env[17] = 1.0
# for color : env[16] =  1.0, env[17] = 0.0
# for 1.0 - color : env[16] = -1.0, env[17] = 1.0
MAD result.color, vertex.color, program.env[16], program.env[17];

END

#==================================================================================

!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

# Instruction Count: ALU: 129 TEX: 32 Total: 161

OUTPUT oColor = result.color;
ATTRIB vColor = fragment.color;

ATTRIB lightVecTC = fragment.texcoord[0];
ATTRIB normalTC = fragment.texcoord[1];
ATTRIB lightFallTC = fragment.texcoord[2];
ATTRIB lightProjTC = fragment.texcoord[3];
ATTRIB diffuseTC = fragment.texcoord[4];
ATTRIB specularTC = fragment.texcoord[5];
ATTRIB viewVecTC = fragment.texcoord[6];
ATTRIB hemiLight = fragment.texcoord[7];

PARAM lightColor = program.env[0];
PARAM specColor = program.env[1];

PARAM const = {  1.0,  2.0,  4.0,  5.0  };
PARAM const2 = {  0.25, 0.5,  0.75, 0.1 };
PARAM skyColor = {  0.5,  0.5,  0.5  };
PARAM grndColor = {  1.0,  1.0,  1.0  };
PARAM lumVec = {  0.212671, 0.715160, 0.072169 };
PARAM specExp = { 64.0,  0.00001 };
PARAM Scale = 0.0625;
PARAM Steps = 16.0;
PARAM invSteps = 0.0625;
PARAM ssStrength = 3.0;

TEMP lightVec, viewVec, halfVec, normalVec;
TEMP diffuse, specular, gloss, color, ambient, shadow;
TEMP light, hemi, atten, lightFall, lightProj;
TEMP NdotL, NdotV, NdotH, VdotL;
TEMP TC, shadowTC, delta, delta0, delta1, H0, H1;
TEMP R1, R2;


# normalize the vector to the viewer
DP3 viewVec.w, viewVecTC, viewVecTC;
RSQ viewVec.w, viewVec.w;
MUL viewVec.xyz, viewVecTC, viewVec.w;

# normalize the vector to the light
DP3 lightVec.w, lightVecTC, lightVecTC;
RSQ lightVec.w, lightVec.w;
MUL lightVec.xyz, lightVecTC, lightVec.w;

###======================================================================
# parallax occlusion mapping: linear search (16 steps)
###======================================================================
MUL R1.xy, viewVec, Scale;
MUL R1.z, -viewVec.z, Steps;
RCP R1.z, R1.z;
MUL delta.xy, R1, R1.z;
MOV delta.z, -invSteps;

TEX H0, specularTC, texture[5], 2D;

ADD TC, specularTC, delta;
MOV TC.z, 0.9375; # 1.0 - invSteps

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

TEX H1, TC, texture[5], 2D;
SLT R1.x, H1.w, TC.z;
CMP H0, -R1.x, H1.w, H0.w;
MAD TC, R1.x, delta, TC;

###======================================================================
# parallax occlusion mapping: intersection calculation
###======================================================================
MOV R1.y, TC.z;
ADD R1.x, R1.y, invSteps;
ADD delta0, R1.x, -H0.w;
ADD delta1, R1.y, -H1.w;
MUL R2.x, R1.y, delta0;
MAD R2.x, R1.x, delta1, -R2.x;
ADD R2.y, delta1, -delta0;
RCP R2.y, R2.y;
MUL R2, R2.x, R2.y;

MUL R1.xy, delta, Steps;
MAD R1.zw, delta.xyxy, Steps, specularTC.xyxy;
MAD TC, -R2, R1.xyxy, R1.zwzw;

###======================================================================
# self shadowing
###======================================================================
MUL delta.xy, lightVec, Scale;

TEX H0, TC, texture[5], 2D;

MAD shadowTC, delta, 1.0, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, 0.0, R1.w;
MAD shadowTC, delta, 0.875, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, H1, R1.w;
MAD shadowTC, delta, 0.750, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, H1, R1.w;
MAD shadowTC, delta, 0.625, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, H1, R1.w;
MAD shadowTC, delta, 0.500, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, H1, R1.w;
MAD shadowTC, delta, 0.375, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, H1, R1.w;
MAD shadowTC, delta, 0.250, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, H1, R1.w;
MAD shadowTC, delta, 0.125, TC;
TEX R1, shadowTC, texture[5], 2D;
MAX H1, H1, R1.w;

ADD R1, H1, -H0.w;
MAD_SAT shadow, R1, -ssStrength, 1.0;

###======================================================================

# calculate texcoords for diffuse and specular maps
SUB R1, diffuseTC, specularTC;
SUB R2, normalTC, specularTC;
ADD R1, R1, TC;
ADD R2, R2, TC;

# load texture maps
TEX ambient, lightVecTC, texture[0], CUBE;
TEX normalVec, R2, texture[1], 2D;
TXP lightFall, lightFallTC, texture[2], 2D;
TXP lightProj, lightProjTC, texture[3], 2D;
TEX diffuse, R1, texture[4], 2D;
TEX gloss, TC, texture[5], 2D;

# calculate the half angle vector and normalize
ADD halfVec, lightVec, viewVec;
DP3 R1.x, halfVec, halfVec;
RSQ R1.x, R1.x;
MUL halfVec.xyz, halfVec, R1.x;

# scale normal vector to -1.0<->1.0 range and normalize
MAD normalVec.xyz, normalVec.wyzx, const.y, -const.x;
DP3 R1.x, normalVec, normalVec;
RSQ R1.x, R1.x;
MUL normalVec.xyz, normalVec, R1.x;

# calculate vector dot products
DP3 NdotL.x, normalVec, lightVec;
DP3 NdotV.x, normalVec, viewVec;
DP3_SAT NdotH.x, normalVec, halfVec;
DP3_SAT VdotL.x, viewVec, -lightVec;

# calculate specular exp using specular map
DP3 R1.x, gloss, lumVec;
MAD R1.x, R1.x, specExp.x, specExp.y;
MUL R1.x, R1.x, const.z;

# calculate specular term
POW specular, NdotH.x, R1.x;

# scale the specular map * 2
MUL gloss, gloss, const.y;

# modulate specular by gloss map and add diffuse color
MAD color, specular, gloss, diffuse;

# calculate self shadowing
ADD R1.x, lightVec.z, const2.x;
MUL_SAT R1.x, R1.x, const.z;
MUL light, R1.x, NdotL.x;

# calculate hemisphere lighting ambient term
DP3 hemi.x, normalVec, hemiLight;
MAD hemi.x, hemi.x, const2.z, const2.z;
LRP hemi, hemi.x, skyColor, grndColor;
SUB R1.x, ambient.w, const2.z;
CMP light, R1.x, hemi, light;
CMP shadow, R1.x, const.x, shadow;

# calculate attenuation using the light falloff and projection maps
MUL atten, lightFall, lightProj;

# modulate light by attenuation
MUL light, light, atten;

# modulate by light and light color
MUL color, color, light;
MUL color, color, lightColor;
MUL color, color, shadow;

# modify by the vertex color
MUL oColor.xyz, color, vColor;

END


these go in the glprogs folder, try them out and see.
these are modified .vfp's to get the extra gloss effect.
and are used for post processing.
of course make backups first :) before testing!

edit:
you'll notice in your posted .vfp its a    Custom Blinn-Phong Lighting Model (Isotropic)
where this one is a  Cook-Torrance Lighting Model w/ Relief Mapping (Isotropic)
however it needs the modified test.vfp to work in tandem as they wont work without the other to have the gloss render properly.

it may or may not have issues with ATI cards but on Nvidia it works great.

Bladeghost

#8
But getting back to the TOPIC  gloss(control) the two vfp's render all specular materials with a shine (especially the bright ones)
darker specular maps render less shiny... your (material) variable
may be the control over a specific material that may work as well, again as I've said it's a different effect but looking at your screenshots it does seem interesting as I've had mixed results.

Bladeghost

A texture trick I sometimes use is taking the texture and in photoshop use the plastic 'filter on it
and then make it black and white
and highlight some light areas or whatever I feel looks good and use that for a specularmap. in some cases. sometimes works sometimes not yet still fun to do with certain things. also specularmaps can blend in stages as well to have a combination of more than one texture.

but this can be for fun or stuff. just Thought I'd share some things I've tried.

Rock and Roll!

tron

I'm a bit confused as to why you need both set the gloss strength in the alpha channel, and then also adjust the gloss in the material definition?

Zombie

#11
Just to clarify I made a mistake on the first image, I was editing both values so it wasn't clear gloss is working.

The second screenshot I posted it is working fine.

http://i.imgur.com/ZE9KA9G.jpg this shows it is working very clearly

https://www.youtube.com/watch?v=s0sv6EArQ0w&feature=youtu.be

The content doesn't change it's just different levels of gloss

Zombie

Quote from: tron on October 08, 2014, 10:15:27 PM
I'm a bit confused as to why you need both set the gloss strength in the alpha channel, and then also adjust the gloss in the material definition?

Yup I made that confusing.

You just edit the alpha value to adjust the gloss. And that's it.

You can adjust the RGB scale if you want to really tweak the end result.

motorsep

I made a post here last night, with example of how gloss should work (per Valve) and someone deleted it  ::)

Zombie

Quote from: motorsep on October 09, 2014, 09:13:45 AM
I made a post here last night, with example of how gloss should work (per Valve) and someone deleted it  ::)

Yeah I did by accident. I intended to remove my post as it was the wrong information and I didn't want people reading the wrong thing. I am living in a hotel at the moment in France, and the internet is quite terrible and I sometimes post and click the wrong things because the page takes a very long time to load.

Please post it again, it was really helpful.