Refraction/Distortion?

Materials, textures, lighting, postfx
27 posts Page 1 of 3
LoLJester
Posts: 38
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Thu Oct 27, 2016 10:35 pm
Anybody's been able to create refraction per object, or any ideas how to do this?
I'm trying to incorporate cloaking in my game.
Duion
Posts: 844
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Thu Oct 27, 2016 11:48 pm
I have cloaking, it uses the fizzle fade that is already in there.
LoLJester
Posts: 38
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Fri Oct 28, 2016 1:37 am
Hi Duion,

I'm already using that. What I want is that the cloaking mantle to be refractive, something like the cloaking used in the movie Predator.
Duion
Posts: 844
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Fri Oct 28, 2016 2:11 am
You are asking complicated things...
I would just replace the whole model texture with a transparent one and add a cubemap with very soft reflection, so it will only be visible from certain angles, maybe that does the trick.
Johxz
Posts: 411
Joined: Sat Feb 07, 2015 11:37 pm
by Johxz » Fri Oct 28, 2016 4:46 am
@
User avatar
LoLJester
you need to use shaders.

You can use the water shader effect to start with, use a waterblock and then play with the settings, to test some effect, and this will give you an idea on how to use shaders for what you need.
Duion
Posts: 844
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Fri Oct 28, 2016 2:42 pm
You have to consider that from a gameplay standpoint all of those solutions are not good, since when the "cloaked" player is visible in some way, he is visible and if he is not visible good, it encourages people cheating, through graphics settings.
Best method may be to just make the player invisible when cloaked and occasionally add particle effects, like smoke, so it helps indicating that there is a cloaked player, but he is not physically visible.
LoLJester
Posts: 38
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Fri Oct 28, 2016 10:33 pm
I'm already using the transparency effect, and it looks quite good, but it is not exactly what I want.
I liked how TGEA did it. It's a bit disappointing that T3D cannot do it by default.
Anybody done a refraction shader?
Bloodknight
Posts: 99
Joined: Tue Feb 03, 2015 8:58 pm
by Bloodknight » Sat Oct 29, 2016 7:51 am
LoLJester
Posts: 38
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Thu Nov 03, 2016 8:45 pm
Thank you Bloodknight, but will these shaders work with T3D, or do they need to be modified to a certain extent? I already have a refraction shader, but I get a black image, instead. Apparently, shaders have to be done differently in deferred type of rendering.
irei1as
Posts: 72
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Fri Nov 04, 2016 11:48 am
Let me share my try at this subject.
What I did is to use a PostFX to copy the backbuffer before the TransparentObj RenderBin into a NamedTexture and use that NamedTexture as a texture sampler for a Custom Material. That Custom material just distorted a bit so it's not really refraction.

If you have a custom RenderBin for those cloacking objects you should change the renderBin for the PostFX to that one.

Note that the use of $backbuffer can cause issues if you use various viewports like with VR.

----------------------------------------------
First we create the PostFX (and exec it somewhere):

Code: Select all

singleton ShaderData( PreTranspCopy_Shader )
{   
   DXVertexShaderFile    = "shaders/common/postFx/postFxV.hlsl";
   DXPixelShaderFile    = "shaders/common/postFx/passthruP.hlsl";
         
   OGLVertexShaderFile  = "shaders/common/postFx/gl/postFxV.glsl";
   OGLPixelShaderFile   = "shaders/common/postFx/gl/passthruP.glsl";
     
   samplerNames[0] = "$inputTex";
   
   pixVersion = 2.0;
};

singleton GFXStateBlockData( PreTranspCopy_stateblock )
{
   zDefined = true;
   zEnable = false;
   zWriteEnable = false;
     
   samplersDefined = true;
   samplerStates[0] = SamplerClampPoint;
};

singleton PostEffect( PreTranspCopy )
{
   // This PostEffect is used by 'AL_FormatToken' directly. It is never added to
   // the PostEffectManager. Do not call enable() on it.
   isEnabled = true;
   renderTime = "PFXBeforeBin";
   renderBin = "ObjTranslucentBin";     
   
   shader = PreTranspCopy_Shader;
   stateBlock = PreTranspCopy_stateblock;
   
   texture[0] = "$backbuffer";
   target = "#PreRenderTranslucent";
};


Then the material. For this example I'll just create a new material in the material.cs of the soldier so I can skin it directly.
I don't have access to a computer with glsl compability so those are up to you.
Add this at the end of that material.cs:

Code: Select all

singleton ShaderData( predatorTextureShader )
{
   DXVertexShaderFile = "shaders/common/z_predatorV.hlsl";
   DXPixelShaderFile    = "shaders/common/z_predatorP.hlsl";
   samplerNames[0] = "$diffuseMap";
   pixVersion =2.0;
};

singleton CustomMaterial(Mat_Predator_Soldier_Main : Mat_Soldier_Main)
{
   mapTo = "Predator_Soldier_Main";
   translucent = true;
   shader = predatorTextureShader;
   sampler["diffuseMap"] = "#PreRenderTranslucent";
};


You may want to use a different CustomMaterial for each object so the woobly effect is not sincronized:

singleton CustomMaterial(Mat_Predator2_Soldier_Main : Mat_Predator_Soldier_Main) {};
singleton CustomMaterial(Mat_Predator3_Soldier_Main : Mat_Predator_Soldier_Main) {};
...

Finally I added the two shader (hlsl) files at shaders/common.
(Remember they must be plain ANSI files.)

----------z_predatorV.hlsl---------

Code: Select all

struct VertToPixOut
{
   float4 hpos       : POSITION;
   float4 screen        : TEXCOORD1;
};

struct VertToPixIn
{
   float4 hpos       : POSITION;
};

uniform float4x4 modelview;

VertToPixOut main( VertToPixIn In)
{
   VertToPixOut Out;
   Out.hpos = mul( modelview, In.hpos);

   Out.screen = Out.hpos;

   return Out;
}


--------------z_predatorP.hlsl-----------
The distortion effect is in here.
You should, of course, use another function for the distortion. This one is just a basic example.

Code: Select all

struct datainput {
   float4 screenCoord : TEXCOORD1;
};

//diffuseMap is defined in the CustomMaterial and its ShaderData
uniform sampler2D diffuseMap        : register(S0);

//accumTime is an engine variable. It's kind of the time of the material.
//Use it to move things in time
uniform float     accumTime;

float4 main( datainput IN ) : COLOR0
{
   //texture to screen
   float2 screenpos = 0.5+IN.screenCoord.xy/2*float2(1,-1)/IN.screenCoord.w;
   
   //wooble effect example
   float2 repeat = (1 - 1/200) - abs(sin(accumTime*3)/200);
   screenpos = screenpos * repeat;
   
   
   float4 colour_exit = tex2D( diffuseMap, screenpos);

   //here you can modify colourexit if needed

   return colour_exit;
}



After these changes just do

%player.setSkinName("Predator")
(%player.setSkinName("Predator2"), etc)

Change %player with the ID of the soldier to re-skin like (LocalClientConnection.player).setSkinName("Predator")
27 posts Page 1 of 3

Who is online

Users browsing this forum: No registered users and 1 guest