Jump to content

Recommended Posts

Hi! I made a simple character customization in MTA with CJ skin, bone_attach, and some custom models. I want to make a new version, like Sims or Saints Row's Character customizations. Its possible to make it, but I need a very simple displacement mapping shader to finish. (https://en.wikipedia.org/wiki/Displacement_mapping)
If someone can write that shader, please notice me.

Character customization video:

 

Link to comment

Sooo...I'm stuck.
MTA (seems to) support(s) only Shader Version 3_x and lower but I would apparently need 4_x to get the masking to work.
I'm pretty much all out of ideas, did a bunch of google searches and got nothing...or at least nothing that I could get anything out of.

Note that I'm really not that big into HLSL so maybe someone with more experience could get it to work.

Link to comment

So this shader works, but my Video Card just can't handle the tex2Dlod() function, so the result is crash, blue screen, or MTA just start flashing and lagging at me.
 

//
// Example shader - deform.fx
//


//------------------------------------------------------------------------------------------
// Variables
//------------------------------------------------------------------------------------------
texture gDeformTexture;
float3 sResizeAmount = float3(0,0,0);
bool bIncludeNormal = false;

//---------------------------------------------------------------------
// Include some common stuff
//---------------------------------------------------------------------
#include "mta-helper.fx"
static float PI = 3.14159265359;

//---------------------------------------------------------------------
// Sampler for the main texture
//---------------------------------------------------------------------
sampler Sampler0 = sampler_state
{
    Texture = (gTexture0);
};

sampler SamplerDeform = sampler_state
{
    Texture = (gDeformTexture);
    MinFilter = Point;
    MagFilter = Point;
    MipFilter = None;
};

//---------------------------------------------------------------------
// Structure of data sent to the vertex shader
//---------------------------------------------------------------------
struct VSInput
{
  float3 Position : POSITION0;
  float3 Normal : NORMAL0;
  float4 Diffuse : COLOR0;
  float3 TexCoord : TEXCOORD0;
};

//---------------------------------------------------------------------
// Structure of data sent to the pixel shader ( from the vertex shader )
//---------------------------------------------------------------------
struct PSInput
{
  float4 Position : POSITION0;
  float4 Diffuse : COLOR0;
  float2 TexCoord : TEXCOORD0;
  float4 WorldPos : TEXCOORD1;
};

//------------------------------------------------------------------------------------------
// VertexShaderFunction
//------------------------------------------------------------------------------------------
PSInput VertexShaderFunction(VSInput VS)
{
    PSInput PS = (PSInput)0;
	
    // Make sure normal is valid
    MTAFixUpNormal( VS.Normal );
	
    // deform vertex position
    float4 defTex = tex2Dlod(SamplerDeform, float4(VS.TexCoord.xy - float2(0,1), 0, 0.0));
    if (bIncludeNormal) VS.Position += defTex.xyz * sResizeAmount * VS.Normal.xyz;
       else VS.Position += defTex.xyz * sResizeAmount;
    // Calculate screen pos of vertex
    PS.WorldPos = mul(float4(VS.Position.xyz, 1), gWorld);
    float4 viewPos = mul(PS.WorldPos, gView);
    PS.Position = mul(viewPos, gProjection);

    // Calculate world normal
    float3 worldNormal = mul(VS.Normal, (float3x3)gWorld);
	
    // Pass through tex coord
    PS.TexCoord = VS.TexCoord.xyz;

    // Calculate GTA lighting for vehicle
    PS.Diffuse = MTACalcGTAVehicleDiffuse( worldNormal, VS.Diffuse );

    return PS;
}


//------------------------------------------------------------------------------------------
// MTAApplyFog
//------------------------------------------------------------------------------------------
int gFogEnable                     < string renderState="FOGENABLE"; >;
float4 gFogColor                   < string renderState="FOGCOLOR"; >;
float gFogStart                    < string renderState="FOGSTART"; >;
float gFogEnd                      < string renderState="FOGEND"; >;
 
float3 MTAApplyFog( float3 texel, float3 worldPos )
{
    if ( !gFogEnable )
        return texel;
 
    float DistanceFromCamera = distance( gCameraPosition, worldPos );
    float FogAmount = ( DistanceFromCamera - gFogStart )/( gFogEnd - gFogStart );
    texel.rgb = lerp(texel.rgb, gFogColor.rgb, saturate( FogAmount ) );
    return texel;
}

//------------------------------------------------------------------------------------------
// PixelShaderFunction
//------------------------------------------------------------------------------------------
float4 PixelShaderFunction(PSInput PS) : COLOR0
{
    // sample color texture
    float4 finalColor = tex2D(Sampler0, PS.TexCoord.xy);
    // multiply by vertex color
    finalColor *= PS.Diffuse;
    // recreate fog
    finalColor.rgb = MTAApplyFog( finalColor.rgb, PS.WorldPos.xyz );

    return saturate(finalColor);
}

//------------------------------------------------------------------------------------------
// Techniques
//------------------------------------------------------------------------------------------
technique deform
{
    pass P0
    {
        VertexShader = compile vs_3_0 VertexShaderFunction();
        PixelShader  = compile ps_3_0 PixelShaderFunction();
    }
}

// Fallback
technique fallback
{
    pass P0
    {
        // Just draw normally
    }
}

 

Link to comment

I'll give it a shot, even though it sounds unlikely that your GPU can't handle the function...
If it can handle VS3.0 it should also be fine with the functions provided...odd.

Maybe I can strip down the entire thing a little.

Give this a shot, I basically just altered the ped-morph.fx to use a mask with tex2Dlod.

//
// Example shader - ped_morph.fx
//


//---------------------------------------------------------------------
// Ped morph settings
//---------------------------------------------------------------------
float3 sMorphSize = float3(0,0,0);
texture maskMap;

//---------------------------------------------------------------------
// Include some common stuff
//---------------------------------------------------------------------
#include "mta-helper.fx"

//---------------------------------------------------------------------
// Sampler for the mask texture
//---------------------------------------------------------------------
sampler maskSampler = sampler_state
{
    Texture = (maskMap);
};

//---------------------------------------------------------------------
// Structure of data sent to the vertex shader
//---------------------------------------------------------------------
struct VSInput
{
    float3 Position : POSITION0;
    float3 Normal : NORMAL0;
    float4 Diffuse : COLOR0;
    float2 TexCoord : TEXCOORD0;
};

//---------------------------------------------------------------------
// Structure of data sent to the pixel shader ( from the vertex shader )
//---------------------------------------------------------------------
struct PSInput
{
    float4 Position : POSITION0;
    float4 Diffuse : COLOR0;
    float2 TexCoord : TEXCOORD0;
};

//------------------------------------------------------------------------------------------
// VertexShaderFunction
//  1. Read from VS structure
//  2. Process
//  3. Write to PS structure
//------------------------------------------------------------------------------------------
PSInput VertexShaderFunction(VSInput VS)
{
    PSInput PS = (PSInput)0;

	float4 texel = tex2Dlod( maskSampler, float4(VS.TexCoord.xy - float2(0,1), 0, 0) );

    // Do morph effect by adding surface normal to the vertex position
    VS.Position += VS.Normal * sMorphSize * texel.rgb;

    // Calculate screen pos of vertex
    PS.Position = MTACalcScreenPosition ( VS.Position );

    // Pass through tex coords
    PS.TexCoord = VS.TexCoord;

    // Calc GTA lighting for peds
    PS.Diffuse = MTACalcGTABuildingDiffuse( VS.Diffuse );

    return PS;
}


//------------------------------------------------------------------------------------------
// Techniques
//------------------------------------------------------------------------------------------
technique tec0
{
    pass P0
    {
        VertexShader = compile vs_3_0 VertexShaderFunction();
    }
}

// Fallback
technique fallback
{
    pass P0
    {
        // Just draw normally
    }
}

 

Link to comment

Well then, if it's really that function I doubt the shader I posted fared any better...
I played around a little with both shaders and I have to say, the use is pretty limited, at least on the default SA models.
I only tried a few but there were usually holes etc. in them...however given enough time this seems to be a great way to alter models for e.g muscles and fat.

Link to comment

I want to make face morph with this shader, but i have to figure out how can i supply tex2Dlod function. Is there a way to calculate it with tex2D function in PS, and export it to VS? Or just another solution with Shadermodel 2.0?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...