Unity compute shader function that calculates Laplacian value
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
This piece of code calculates the laplacian value of a points neighbours based on x & y co-ord passed and pixel size.
float Laplacian (sampler2D TheText, float x, float y, float2 pixsize)
float Value=0;
//Top Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y+pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y+pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y+pixsize.y,0,0)).r*0.05f;
//Middle Row
Value+= tex2Dlod(TheText, float4(x,y,0,0)).r*-1.0f;
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y,0,0)).r*0.2f;
//Bottom Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y-pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y-pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y-pixsize.y,0,0)).r*0.05f;
return Value;
c#
add a comment |Â
up vote
0
down vote
favorite
This piece of code calculates the laplacian value of a points neighbours based on x & y co-ord passed and pixel size.
float Laplacian (sampler2D TheText, float x, float y, float2 pixsize)
float Value=0;
//Top Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y+pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y+pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y+pixsize.y,0,0)).r*0.05f;
//Middle Row
Value+= tex2Dlod(TheText, float4(x,y,0,0)).r*-1.0f;
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y,0,0)).r*0.2f;
//Bottom Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y-pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y-pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y-pixsize.y,0,0)).r*0.05f;
return Value;
c#
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This piece of code calculates the laplacian value of a points neighbours based on x & y co-ord passed and pixel size.
float Laplacian (sampler2D TheText, float x, float y, float2 pixsize)
float Value=0;
//Top Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y+pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y+pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y+pixsize.y,0,0)).r*0.05f;
//Middle Row
Value+= tex2Dlod(TheText, float4(x,y,0,0)).r*-1.0f;
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y,0,0)).r*0.2f;
//Bottom Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y-pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y-pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y-pixsize.y,0,0)).r*0.05f;
return Value;
c#
This piece of code calculates the laplacian value of a points neighbours based on x & y co-ord passed and pixel size.
float Laplacian (sampler2D TheText, float x, float y, float2 pixsize)
float Value=0;
//Top Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y+pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y+pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y+pixsize.y,0,0)).r*0.05f;
//Middle Row
Value+= tex2Dlod(TheText, float4(x,y,0,0)).r*-1.0f;
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y,0,0)).r*0.2f;
//Bottom Row
Value+= tex2Dlod(TheText, float4(x+pixsize.x,y-pixsize.y,0,0)).r*0.05f;
Value+= tex2Dlod(TheText, float4(x,y-pixsize.y,0,0)).r*0.2f;
Value+= tex2Dlod(TheText, float4(x-pixsize.x,y-pixsize.y,0,0)).r*0.05f;
return Value;
c#
edited May 21 at 7:53
RobH
14k42461
14k42461
asked May 21 at 7:12
Munkybunky
1526
1526
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194845%2funity-compute-shader-function-that-calculates-laplacian-value%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password