diff options
Diffstat (limited to 'src/Runtime/res/effectlib/fileBumpTexture.glsllib')
-rw-r--r-- | src/Runtime/res/effectlib/fileBumpTexture.glsllib | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/src/Runtime/res/effectlib/fileBumpTexture.glsllib b/src/Runtime/res/effectlib/fileBumpTexture.glsllib index fb041d68..0f27fd80 100644 --- a/src/Runtime/res/effectlib/fileBumpTexture.glsllib +++ b/src/Runtime/res/effectlib/fileBumpTexture.glsllib @@ -47,59 +47,59 @@ // compute a normal based on a heightfield style bump texture // example call: // fileBumpTexture(bump_texture, bump_amount, mono_average -// , transformCoordinate( -// rotationTranslationScale( -// vec3( 0.000000, 0.000000, 0.000000 ) -// , vec3( 0.000000, 0.000000, 0.000000 ) -// , vec3( texture_tiling[0], texture_tiling[1], 1.000000 ) ) -// , textureCoordinateInfo( texCoord0, tangent, binormal ) ) -// , vec2( 0.000000, 1.000000 ), vec2( 0.000000, 1.000000 ) -// , wrap_repeat, wrap_repeat, normal ); +// , transformCoordinate( +// rotationTranslationScale( +// vec3( 0.000000, 0.000000, 0.000000 ) +// , vec3( 0.000000, 0.000000, 0.000000 ) +// , vec3( texture_tiling[0], texture_tiling[1], 1.000000 ) ) +// , textureCoordinateInfo( texCoord0, tangent, binormal ) ) +// , vec2( 0.000000, 1.000000 ), vec2( 0.000000, 1.000000 ) +// , wrap_repeat, wrap_repeat, normal ); vec3 fileBumpTexture( in sampler2D sampler, in float factor, in int bumpSource - , in texture_coordinate_info uvw + , in texture_coordinate_info uvw , in vec2 cropU, in vec2 cropV - , in int wrapU, in int wrapV, in vec3 normal ) + , in int wrapU, in int wrapV, in vec3 normal ) { - vec2 bumpMapSize = vec2( textureSize( sampler, 0 ) ); - float bumpMapLevels = log2( max( bumpMapSize.x, bumpMapSize.y ) ); - // simulate textureQueryLod - vec2 dx = dFdx( uvw.position.xy * bumpMapSize.x ); - vec2 dy = dFdy( uvw.position.xy * bumpMapSize.y ); + vec2 bumpMapSize = vec2( textureSize( sampler, 0 ) ); + float bumpMapLevels = log2( max( bumpMapSize.x, bumpMapSize.y ) ); + // simulate textureQueryLod + vec2 dx = dFdx( uvw.position.xy * bumpMapSize.x ); + vec2 dy = dFdy( uvw.position.xy * bumpMapSize.y ); - float px = dot( dx, dx ); - float py = dot( dy, dy ); + float px = dot( dx, dx ); + float py = dot( dy, dy ); - float maxlod = 0.5 * log2( max( px, py ) ); // log2(sqrt()) = 0.5*log2() - float minlod = 0.5 * log2( min( px, py ) ); + float maxlod = 0.5 * log2( max( px, py ) ); // log2(sqrt()) = 0.5*log2() + float minlod = 0.5 * log2( min( px, py ) ); - float lod = max(0.0, min( maxlod, bumpMapLevels )); + float lod = max(0.0, min( maxlod, bumpMapLevels )); - // invert factor - float invFactor = -factor; + // invert factor + float invFactor = -factor; - // currently no lod supported we use 3.3 GL - //float lod = textureQueryLod( sampler, uvw.position.xy ).x; - vec2 size = mix( vec2( textureSize( sampler, int( floor( lod ) ) ) ), vec2( textureSize( sampler, int( ceil( lod ) ) ) ), fract( lod ) ); - vec2 unitStep = 1.0f / size; + // currently no lod supported we use 3.3 GL + //float lod = textureQueryLod( sampler, uvw.position.xy ).x; + vec2 size = mix( vec2( textureSize( sampler, int( floor( lod ) ) ) ), vec2( textureSize( sampler, int( ceil( lod ) ) ) ), fract( lod ) ); + vec2 unitStep = 1.0f / size; - // Add an inveres scale to keep the original gradient values - // this makes the bumps a lot smoother. - // Or we could do it like in iRay and sample always at original size. - // But this makes me feel better. - vec2 scale = size / bumpMapSize; + // Add an inveres scale to keep the original gradient values + // this makes the bumps a lot smoother. + // Or we could do it like in iRay and sample always at original size. + // But this makes me feel better. + vec2 scale = size / bumpMapSize; - float du = monoChannel( textureLod( sampler, vec2( uvw.position.x + unitStep.x, uvw.position.y ), lod ), bumpSource ) - - monoChannel( textureLod( sampler, vec2( uvw.position.x, uvw.position.y ), lod ), bumpSource ); - float dv = monoChannel( textureLod( sampler, vec2( uvw.position.x, uvw.position.y + unitStep.y ), lod ), bumpSource ) - - monoChannel( textureLod( sampler, vec2( uvw.position.x, uvw.position.y ), lod ), bumpSource ); + float du = monoChannel( textureLod( sampler, vec2( uvw.position.x + unitStep.x, uvw.position.y ), lod ), bumpSource ) + - monoChannel( textureLod( sampler, vec2( uvw.position.x, uvw.position.y ), lod ), bumpSource ); + float dv = monoChannel( textureLod( sampler, vec2( uvw.position.x, uvw.position.y + unitStep.y ), lod ), bumpSource ) + - monoChannel( textureLod( sampler, vec2( uvw.position.x, uvw.position.y ), lod ), bumpSource ); - vec3 n = normalize(vec3(invFactor * scale.x * du, invFactor * scale.x * dv, 1.0)); - n = n.x*uvw.tangent_u + n.y*uvw.tangent_v + n.z*normal; - return normalize(normal + n); + vec3 n = normalize(vec3(invFactor * scale.x * du, invFactor * scale.x * dv, 1.0)); + n = n.x*uvw.tangent_u + n.y*uvw.tangent_v + n.z*normal; + return normalize(normal + n); } #include "textureCoordinateInfo.glsllib" @@ -109,11 +109,11 @@ vec3 fileBumpTexture( in sampler2D sampler, in float factor, in int bumpSource //TODO - figure out if we need to manipulate tangent_u, tangent_v. vec3 simplerFileBumpTexture( in sampler2D sampler, in float factor, vec2 texCoord, vec3 tangent, vec3 binormal, vec3 normal ) { - return fileBumpTexture( sampler, factor, mono_average - , textureCoordinateInfo( vec3( texCoord.x, texCoord.y, 0.0 ), tangent, binormal ) - , vec2( 0.000000, 1.000000 ), vec2( 0.000000, 1.000000 ) - , wrap_repeat, wrap_repeat, normal ); + return fileBumpTexture( sampler, factor, mono_average + , textureCoordinateInfo( vec3( texCoord.x, texCoord.y, 0.0 ), tangent, binormal ) + , vec2( 0.000000, 1.000000 ), vec2( 0.000000, 1.000000 ) + , wrap_repeat, wrap_repeat, normal ); } -#endif
\ No newline at end of file +#endif |