Brush preview
This commit is contained in:
@@ -4,18 +4,19 @@ uniform mat4 invVP;
|
||||
uniform vec2 mouse;
|
||||
uniform vec2 texStep;
|
||||
uniform float radius;
|
||||
uniform vec3 cameraRight;
|
||||
uniform sampler2D gbufferD;
|
||||
in vec4 pos;
|
||||
in vec2 nor;
|
||||
in vec2 tex;
|
||||
out vec2 texCoord;
|
||||
mat3 rotAxis(vec3 axis, float a) {
|
||||
float c = cos(a);
|
||||
vec3 as = axis * sin(a);
|
||||
mat3 p = mat3(axis.x * axis, axis.y * axis, axis.z * axis);
|
||||
mat3 q = mat3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c);
|
||||
return p * (1.0 - c) + q;
|
||||
}
|
||||
// mat3 rotAxis(vec3 axis, float a) {
|
||||
// float c = cos(a);
|
||||
// vec3 as = axis * sin(a);
|
||||
// mat3 p = mat3(axis.x * axis, axis.y * axis, axis.z * axis);
|
||||
// mat3 q = mat3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c);
|
||||
// return p * (1.0 - c) + q;
|
||||
// }
|
||||
vec3 getPos(vec2 uv) {
|
||||
float depth = textureLod(gbufferD, uv, 0.0).r;
|
||||
vec4 wpos = vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
||||
@@ -27,6 +28,10 @@ vec3 getNormal(vec3 p0, vec2 uv) {
|
||||
vec3 p2 = getPos(uv + vec2(0, texStep.y * 4));
|
||||
return normalize(cross(p2 - p0, p1 - p0));
|
||||
}
|
||||
void createBasis(vec3 normal, out vec3 tangent, out vec3 binormal) {
|
||||
tangent = normalize(cameraRight - normal * dot(cameraRight, normal));
|
||||
binormal = cross(tangent, normal);
|
||||
}
|
||||
void main() {
|
||||
texCoord = tex;
|
||||
vec3 wpos = getPos(mouse);
|
||||
@@ -39,12 +44,19 @@ void main() {
|
||||
getNormal(wpos1, uv1) +
|
||||
getNormal(wpos2, uv2)
|
||||
);
|
||||
float ax = acos(dot(vec3(1,0,0), vec3(n.x,0,0)));
|
||||
float az = acos(dot(vec3(0,0,1), vec3(0,0,n.z)));
|
||||
float sy = -sign(n.y);
|
||||
wpos +=
|
||||
rotAxis(vec3(1,0,0), -az * sy + 3.14/2) *
|
||||
rotAxis(vec3(0,0,1), ax + 3.14/2) *
|
||||
(pos.xyz * radius);
|
||||
// float ax = acos(dot(vec3(1,0,0), vec3(n.x,0,0)));
|
||||
// float az = acos(dot(vec3(0,0,1), vec3(0,0,n.z)));
|
||||
// float sy = -sign(n.y);
|
||||
// wpos +=
|
||||
// rotAxis(vec3(1,0,0), -az * sy + 3.14/2) *
|
||||
// rotAxis(vec3(0,0,1), ax + 3.14/2) *
|
||||
// (pos.xyz * radius);
|
||||
vec3 n_tan;
|
||||
vec3 n_bin;
|
||||
createBasis(n, n_tan, n_bin);
|
||||
if (gl_VertexID == 0) wpos += normalize(-n_tan - n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 1) wpos += normalize( n_tan - n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 2) wpos += normalize( n_tan + n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 3) wpos += normalize(-n_tan + n_bin) * 0.7 * radius;
|
||||
gl_Position = VP * vec4(wpos, 1.0);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -3,17 +3,20 @@ uniform float4x4 invVP;
|
||||
uniform float2 mouse;
|
||||
uniform float2 texStep;
|
||||
uniform float radius;
|
||||
uniform float3 cameraRight;
|
||||
Texture2D<float4> texa; // direct3d12 unit align
|
||||
SamplerState _texa_sampler; // direct3d12 unit align
|
||||
Texture2D<float4> gbufferD;
|
||||
SamplerState _gbufferD_sampler;
|
||||
float3x3 rotAxis(float3 axis, float a) {
|
||||
float c = cos(a);
|
||||
float3 as = axis * sin(a).xxx;
|
||||
float3x3 p = float3x3(axis.xxx * axis, axis.yyy * axis, axis.zzz * axis);
|
||||
float3x3 q = float3x3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c);
|
||||
return p * (1.0 - c) + q;
|
||||
}
|
||||
|
||||
// float3x3 rotAxis(float3 axis, float a) {
|
||||
// float c = cos(a);
|
||||
// float3 as = axis * sin(a).xxx;
|
||||
// float3x3 p = float3x3(axis.xxx * axis, axis.yyy * axis, axis.zzz * axis);
|
||||
// float3x3 q = float3x3(c, -as.z, as.y, as.z, c, -as.x, -as.y, as.x, c);
|
||||
// return p * (1.0 - c) + q;
|
||||
// }
|
||||
|
||||
float3 getPos(float2 uv) {
|
||||
float2 uvinv = float2(uv.x, 1.0 - uv.y);
|
||||
float depth = gbufferD.SampleLevel(_gbufferD_sampler, uvinv, 0).r;
|
||||
@@ -21,13 +24,21 @@ float3 getPos(float2 uv) {
|
||||
wpos = mul(wpos, invVP);
|
||||
return wpos.xyz / wpos.w;
|
||||
}
|
||||
|
||||
float3 getNormal(float3 p0, float2 uv) {
|
||||
float3 p1 = getPos(uv + float2(texStep.x, 0));
|
||||
float3 p2 = getPos(uv + float2(0, texStep.y));
|
||||
return normalize(cross(p2 - p0, p1 - p0));
|
||||
}
|
||||
|
||||
void createBasis(float3 normal, out float3 tangent, out float3 binormal) {
|
||||
// Project vector onto plane
|
||||
tangent = normalize(cameraRight - normal * dot(cameraRight, normal));
|
||||
binormal = cross(tangent, normal);
|
||||
}
|
||||
|
||||
struct SPIRV_Cross_Output { float2 texCoord : TEXCOORD0; float4 gl_Position : SV_Position; };
|
||||
SPIRV_Cross_Output main(float2 nor : TEXCOORD0, float4 pos : TEXCOORD1, float2 tex : TEXCOORD2) {
|
||||
SPIRV_Cross_Output main(float2 nor : TEXCOORD0, float4 pos : TEXCOORD1, float2 tex : TEXCOORD2, uint gl_VertexID : SV_VertexID) {
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.texCoord = tex;
|
||||
float3 wpos = getPos(mouse);
|
||||
@@ -42,11 +53,21 @@ SPIRV_Cross_Output main(float2 nor : TEXCOORD0, float4 pos : TEXCOORD1, float2 t
|
||||
getNormal(wpos1, uv1) +
|
||||
getNormal(wpos2, uv2)
|
||||
);
|
||||
float ax = acos(dot(float3(1,0,0), float3(n.x,0,0)));
|
||||
float az = acos(dot(float3(0,0,1), float3(0,0,n.z)));
|
||||
float sy = -sign(n.y);
|
||||
wpos += mul(mul(pos.xyz * radius.xxx, rotAxis(float3(0,0,1), ax + 3.14/2)),
|
||||
rotAxis(float3(1,0,0), -az * sy + 3.14/2));
|
||||
|
||||
// float ax = acos(dot(float3(1,0,0), float3(n.x,0,0)));
|
||||
// float az = acos(dot(float3(0,0,1), float3(0,0,n.z)));
|
||||
// float sy = -sign(n.y);
|
||||
// wpos += mul(mul(pos.xyz * radius.xxx, rotAxis(float3(0,0,1), ax + 3.14/2)),
|
||||
// rotAxis(float3(1,0,0), -az * sy + 3.14/2));
|
||||
|
||||
float3 n_tan;
|
||||
float3 n_bin;
|
||||
createBasis(n, n_tan, n_bin);
|
||||
if (gl_VertexID == 0) wpos += normalize(-n_tan - n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 1) wpos += normalize( n_tan - n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 2) wpos += normalize( n_tan + n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 3) wpos += normalize(-n_tan + n_bin) * 0.7 * radius;
|
||||
|
||||
stage_output.gl_Position = mul(float4(wpos, 1.0), VP);
|
||||
stage_output.gl_Position.z = (stage_output.gl_Position.z + stage_output.gl_Position.w) * 0.5;
|
||||
return stage_output;
|
||||
|
||||
Reference in New Issue
Block a user