Grozz Posted April 9, 2017 Share Posted April 9, 2017 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
Mr.Loki Posted April 9, 2017 Share Posted April 9, 2017 https://wiki.multitheftauto.com/wiki/Shader_examples Scroll down to ped morph. Link to comment
Grozz Posted April 9, 2017 Author Share Posted April 9, 2017 2 hours ago, Mr.Loki said: https://wiki.multitheftauto.com/wiki/Shader_examples Scroll down to ped morph. I know pedmorph, but i don't want to morph the whole model, just a part of it. Link to comment
quindo Posted April 10, 2017 Share Posted April 10, 2017 I don't think it is possible to address individual vertices from shaders in mta, at least i haven't found a way to do that. Link to comment
Addlibs Posted April 10, 2017 Share Posted April 10, 2017 I'm fairly confident it should be possible using a displacement map as if it were a mask for morph or somehow, but I don't know how to write any sort of advanced shader. Link to comment
3aGl3 Posted April 10, 2017 Share Posted April 10, 2017 I will take a look at the morph shader and see if I can add a mask to it so only certain parts will be morphed. Link to comment
Grozz Posted April 10, 2017 Author Share Posted April 10, 2017 8 hours ago, 3aGl3 said: I will take a look at the morph shader and see if I can add a mask to it so only certain parts will be morphed. Thank you! Link to comment
3aGl3 Posted April 11, 2017 Share Posted April 11, 2017 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
Grozz Posted April 11, 2017 Author Share Posted April 11, 2017 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
3aGl3 Posted April 11, 2017 Share Posted April 11, 2017 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
Grozz Posted April 11, 2017 Author Share Posted April 11, 2017 It can handle VS 3.0, Ren_712 said its an exotic issue. I have Ati Mobility Radeon X2300 Link to comment
3aGl3 Posted April 11, 2017 Share Posted April 11, 2017 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
Grozz Posted April 11, 2017 Author Share Posted April 11, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now