Repe [T3DU] Update - 31f26d171bba0355ce2a77031e3aad4c64dbc7e9
This commit is contained in:
@ -1,41 +1,81 @@
|
||||
/*
|
||||
https://github.com/JonasFolletete/glsl-triplanar-mapping
|
||||
vec4 boxProjection(sampler2D image, vec3 normal, vec3 coord, float blend) {
|
||||
vec3 n = normalize(normal);
|
||||
vec3 N = abs(n);
|
||||
vec4 color1, color2, color3;
|
||||
|
||||
MIT License
|
||||
vec2 uv = coord.yz;
|
||||
if (n.x < 0.0) {
|
||||
uv.x = 1.0 - uv.x;
|
||||
}
|
||||
color1 = texture(image, uv);
|
||||
|
||||
Copyright (c) 2018 Jonas Folletête
|
||||
uv = coord.xz;
|
||||
if (n.y > 0.0) {
|
||||
uv.x = 1.0 - uv.x;
|
||||
}
|
||||
color2 = texture(image, uv);
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
uv = vec2(coord.y, 1.0 - coord.x);
|
||||
if (n.z > 0.0) {
|
||||
uv.x = 1.0 - uv.x;
|
||||
}
|
||||
color3 = texture(image, uv);
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
N /= max(dot(N, vec3(1.0)), 1e-8);
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
float limit = 0.5 + 0.5 * clamp(blend, 0.0, 1.0);
|
||||
vec3 weight;
|
||||
weight = N.xyz / (N.xyx + N.yzz);
|
||||
weight = clamp((weight - 0.5 * (1.0 - clamp(blend, 0.0, 1.0))) / max(1e-8, clamp(blend, 0.0, 1.0)), 0.0, 1.0);
|
||||
|
||||
vec3 blendNormal(vec3 normal) {
|
||||
vec3 blending = abs(normal);
|
||||
blending = normalize(max(blending, 0.00001));
|
||||
blending /= vec3(blending.x + blending.y + blending.z);
|
||||
return blending;
|
||||
if (N.z < (1.0 - limit) * (N.y + N.x)) {
|
||||
weight.z = 0.0;
|
||||
weight.y = 1.0 - weight.x;
|
||||
}
|
||||
else if (N.x < (1.0 - limit) * (N.y + N.z)) {
|
||||
weight.x = 0.0;
|
||||
weight.z = 1.0 - weight.y;
|
||||
}
|
||||
else if (N.y < (1.0 - limit) * (N.x + N.z)) {
|
||||
weight.y = 0.0;
|
||||
weight.x = 1.0 - weight.z;
|
||||
}
|
||||
else {
|
||||
weight = ((2.0 - limit) * N + (limit - 1.0)) / max(1e-8, clamp(blend, 0.0, 1.0));
|
||||
}
|
||||
|
||||
return color1 * weight.x + color2 * weight.y + color3 * weight.z;
|
||||
}
|
||||
|
||||
vec3 triplanarMapping (sampler2D ImageTexture, vec3 normal, vec3 position) {
|
||||
vec3 normalBlend = blendNormal(normal);
|
||||
vec3 xColor = texture(ImageTexture, position.yz).rgb;
|
||||
vec3 yColor = texture(ImageTexture, position.xz).rgb;
|
||||
vec3 zColor = texture(ImageTexture, position.xy).rgb;
|
||||
|
||||
return (xColor * normalBlend.x + yColor * normalBlend.y + zColor * normalBlend.z);
|
||||
vec2 sphericalMapping(vec3 coord) {
|
||||
vec3 vin = coord * 2.0 - vec3(1.0);
|
||||
float len = length(vin);
|
||||
float v, u;
|
||||
if (len > 0.0) {
|
||||
if (vin.x == 0.0 && vin.y == 0.0) {
|
||||
u = 0.0;
|
||||
}
|
||||
else {
|
||||
u = (1.0 - atan(vin.x, vin.y) / PI) * 0.5;
|
||||
}
|
||||
v = acos(clamp(vin.z / len, -1.0, 1.0)) / PI;
|
||||
}
|
||||
else {
|
||||
v = u = 0.0;
|
||||
}
|
||||
return vec2(u, v);
|
||||
}
|
||||
|
||||
vec2 tubeMapping(vec3 coord) {
|
||||
vec3 vin = coord * 2.0 - vec3(1.0);
|
||||
float u, v;
|
||||
v = - (vin.z + 1.0) * 0.5;
|
||||
float len = sqrt(vin.x * vin.x + vin.y * vin.y);
|
||||
if (len > 0.0) {
|
||||
u = (1.0 - (atan(vin.x / len, vin.y / len) / PI)) * 0.5;
|
||||
}
|
||||
else {
|
||||
v = u = 0.0;
|
||||
}
|
||||
return vec2(u, v);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user