Hardware shader update

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Hardware shader update

Re: Hardware shader update

by Guest » Tue Nov 06, 2018 11:43 pm

Is it possible to use height maps in pbr materials? It seems like this only works on specular materials, since I remove the specular input for the pbr to have effect from gldefs file, gzdoom crash.

This works:

material texture 640080
{
normal "normalmaps/640080.png"
specular "specularmaps/640080.png"
shader "shaders/texture/parallax.fp"
texture tex_heightmap "heightmaps/640080.png"
specularlevel 0.7
glossiness 7.0
define "Foobarr"

This works:


material texture 640080
{
ao "ao/640080.png"
metallic "specularmaps/white.png"
roughness "specularmaps/640080.png"
normal "normalmaps/640080.png"
specularlevel 0.7
glossiness 7.0
define "Foobarr"

}


This not working:

material texture 640080
{
ao "ao/640080.png"
metallic "metallic/640080.png"
roughness "specularmaps/640080.png"
normal "normalmaps/640080.png"
//specular "specularmaps/640080.png"
shader "shaders/texture/parallax.fp"
texture tex_heightmap "heightmaps/640080.png"
texture tex_gloss "gloss/640080.png"
specularlevel 0.7
glossiness 7.0
define "Foobarr"

}

Re: Hardware shader update

by Gez » Sun Sep 30, 2018 12:41 pm

enderandrew wrote:What is the purpose of Define "Foobar"
Nothing. It's probably just a forgotten remnant of debugging/testing something.

Re: Hardware shader update

by enderandrew » Sun Sep 30, 2018 12:08 pm

dpJudas wrote:Metallic, Roughtness, AO are texture names and are not valid for a material using a specular map. The intensity of the effect is a float constant inside the parallax.fp file itself.
I may just stick with specular, normal (and maybe height) maps for now. But in testing, I'm not sure the effects are working at all. I'm not really seeing any fake height effect from the normal or height maps. Dynamic lights are turned on in the engine, but it may just be that I need a map with moving dynamic lights to really see the effect.

Re: Hardware shader update

by dpJudas » Sun Sep 30, 2018 5:45 am

Metallic, Roughtness, AO are texture names and are not valid for a material using a specular map. The intensity of the effect is a float constant inside the parallax.fp file itself.

Re: Hardware shader update

by enderandrew » Sat Sep 29, 2018 8:06 pm

So I assumed that these float numbers:

float Glossiness;
float SpecularLevel;
float Metallic;
float Roughness;
float AO;

Referred to the intensity of the effect. I just ran a test with this (with matching textures):

material texture ashwall
{
normal "normalmaps/ashwall-n.dds"
specular "specular/ashwall-s.dds"
specularlevel 1
roughness 5
ao 5
Shader "shaders/texture/parallax.fp"
}

And I got these errors:

Roughness texture '5' not found in texture 'ASHWALL'
Ambient occlusion texture '5' not found in texture 'ASHWALL'

So those numbers don't reflect level of the effect, but rather the number of a texture.

Re: Hardware shader update

by Rachael » Thu Sep 27, 2018 9:11 am

When it comes to detail settings, including SSAO, "speed" indicates the lowest possible setting. It's the one that's going to look the roughest and have the fewest passes.

Re: Hardware shader update

by enderandrew » Thu Sep 27, 2018 9:04 am

I've got some stupid questions.

What does "speed" do?

I get that AO sets an Ambient Occlusion level, but what type of effect would I see with different values? I assume this effects shadows, but aren't the shadows determined by the specular, normal and height maps?

What is the purpose of Define "Foobar"

Re: Hardware shader update

by furyweb » Fri Aug 31, 2018 6:50 pm

PixelWAD wrote:It works here on GTX680 GZDoom 3.5.1. How did you generate heightmap from existing pbr textures?
I use Substance Designer to convert normal map to height map. Just a little bit of tweaking to get it right.

Re: Hardware shader update

by furyweb » Fri Aug 31, 2018 6:48 pm

Thanks so much for this works perfect and looks even better. Here is an updated pk3 with some tweaked textures

https://mega.nz/#!IGxECSqZ!bomfSG_ODtdx ... fJqD7w_r2w

also the higher res the texture the better the parallax works.

Re: Hardware shader update

by dpJudas » Fri Aug 31, 2018 1:06 pm

Thanks for the updated pk3. I looked into error you were experiencing with the floor/ceiling - turns out the math in the parallax shader is wrong. Here's an updated fixed version:

Code: Select all

mat3 GetTBN();
vec3 GetBumpedNormal(mat3 tbn, vec2 texcoord);
vec2 ParallaxMap(mat3 tbn);

Material ProcessMaterial()
{
    mat3 tbn = GetTBN();
    vec2 texCoord = ParallaxMap(tbn);

    Material material;
    material.Base = getTexel(texCoord);
    material.Normal = GetBumpedNormal(tbn, texCoord);
    material.Specular = texture(speculartexture, texCoord).rgb;
    material.Glossiness = uSpecularMaterial.x;
    material.SpecularLevel = uSpecularMaterial.y;
#if defined(BRIGHTMAP)
    material.Bright = texture(brighttexture, texCoord);
#endif
    return material;
}

// Tangent/bitangent/normal space to world space transform matrix
mat3 GetTBN()
{
    vec3 n = normalize(vWorldNormal.xyz);
    vec3 p = pixelpos.xyz;
    vec2 uv = vTexCoord.st;

    // get edge vectors of the pixel triangle
    vec3 dp1 = dFdx(p);
    vec3 dp2 = dFdy(p);
    vec2 duv1 = dFdx(uv);
    vec2 duv2 = dFdy(uv);

    // solve the linear system
    vec3 dp2perp = cross(n, dp2); // cross(dp2, n);
    vec3 dp1perp = cross(dp1, n); // cross(n, dp1);
    vec3 t = dp2perp * duv1.x + dp1perp * duv2.x;
    vec3 b = dp2perp * duv1.y + dp1perp * duv2.y;

    // construct a scale-invariant frame
    float invmax = inversesqrt(max(dot(t,t), dot(b,b)));
    return mat3(t * invmax, b * invmax, n);
}

vec3 GetBumpedNormal(mat3 tbn, vec2 texcoord)
{
#if defined(NORMALMAP)
    vec3 map = texture(normaltexture, texcoord).xyz;
    map = map * 255./127. - 128./127.; // Math so "odd" because 0.5 cannot be precisely described in an unsigned format
    map.y = -map.y;
    return normalize(tbn * map);
#else
    return normalize(vWorldNormal.xyz);
#endif
}

vec2 ParallaxMap(mat3 tbn)
{
    const float parallaxScale = 0.045;
    const float minLayers = 8.0;
    const float maxLayers = 16.0;

    // Calculate fragment view direction in tangent space
    mat3 invTBN = transpose(tbn);
    vec3 V = normalize(invTBN * (uCameraPos.xyz - pixelpos.xyz));
    vec2 T = vTexCoord.st;

    float numLayers = mix(maxLayers, minLayers, clamp(abs(V.z), 0.0, 1.0)); // clamp is required due to precision loss

    // calculate the size of each layer
    const float layerDepth = 1.0 / numLayers;

    // depth of current layer
    float currentLayerDepth = 0.0;

    // the amount to shift the texture coordinates per layer (from vector P)
    vec2 P = V.xy * parallaxScale; 
    vec2 deltaTexCoords = P / numLayers;
    vec2 currentTexCoords = T;
    float currentDepthMapValue = texture(tex_heightmap, currentTexCoords).r;

    while (currentLayerDepth < currentDepthMapValue)
    {
        // shift texture coordinates along direction of P
        currentTexCoords -= deltaTexCoords;

        // get depthmap value at current texture coordinates
        currentDepthMapValue = texture(tex_heightmap, currentTexCoords).r;  

        // get depth of next layer
        currentLayerDepth += layerDepth;  
    }

    // get texture coordinates before collision (reverse operations)
    vec2 prevTexCoords = currentTexCoords + deltaTexCoords;

    // get depth after and before collision for linear interpolation
    float afterDepth  = currentDepthMapValue - currentLayerDepth;
    float beforeDepth = texture(tex_heightmap, prevTexCoords).r - currentLayerDepth + layerDepth;
     
    // interpolation of texture coordinates
    float weight = afterDepth / (afterDepth - beforeDepth);
    vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);

    return finalTexCoords;  
}

Re: Hardware shader update

by PixelWAD » Fri Aug 31, 2018 1:00 pm

It works here on GTX680 GZDoom 3.5.1. How did you generate heightmap from existing pbr textures?

Re: Hardware shader update

by drfrag » Fri Aug 31, 2018 12:51 pm

Just tested this and works fine in LZDoom (the new old renderer). In GZDoom dynamic lights won't light walls on my crappy GL 3.3 ati card. Besides that it still crashes of course, i really need an nvidia card.
Now there's that draw thick lines thing (new assasin sent to kill the old legacy build)...

Re: Hardware shader update

by furyweb » Fri Aug 31, 2018 10:12 am

updated link with just a straight .pk3 download

https://mega.nz/#!hCQwCSQa!b_Muvo-8nqtL ... 4fat91Lsb0

Re: Hardware shader update

by dpJudas » Thu Aug 30, 2018 8:23 pm

furyweb wrote:1: I had to invert the heightmap for the wall textures for it to parallax the right way.
There seems to be multiple conventions about which way height maps points. Same deal with normal maps. You may have to adjust both to get it correct.

Note: I did not write the original parallax map code used in this example. UsernameAK provided it.
2 : Parallax on the ground flat works but only one way, whichever dynlight it sees first. So it looks a little strange.
The code doesn't use the dynamic lights for parallax calculations at all. It uses the view space direction of the face normal to figure out which pixel would have been hit with the given height map. From there it grabs the normal map normal of that location and feeds it into the normal light calculations.

If the ground/ceiling looks odd, perhaps the normal map also needs its Red or Green channels inverted.
3: I had to 0 everything on the warp effect otherwise it just warps the walls which felt like I was tripping. does the warp effect do something with the parallax effect or is it just another shader effect. When I delete the bit of code I get errors spitting out.
It is just another shader effect stacked on top. You can remove it without it affecting the parallax effect, just make sure you keep the "vec2 texCoord = vTexCoord.st;" line - otherwise you'll get a compile error.

Btw. I tried to download your rar file, but 7zip couldn't unextract it.

Re: Hardware shader update

by wildweasel » Thu Aug 30, 2018 7:12 pm

furyweb wrote:
PixelWAD wrote:This looks awesome!
Rebecca, would you mind sharing PK3 file with this sample?
Im not rebecca for some reason its coming up with the wrong name for me lol. Anyway the link should come soon after its been modded. My user name is furyweb btw :D
Because you were posting while not logged in, and the forum generates random names for guests.

Top