Jump to content

Recommended Posts

struct VS_OUTPUT 
{
   float4 Pos: POSITION;
   float2 texCoord: TEXCOORD;
};

VS_OUTPUT VS_Electricity(float4 Pos: POSITION)
{
   VS_OUTPUT Out;

   // Clean up inaccuracies
   Pos.xy = sign(Pos.xy);

   Out.Pos = float4(Pos.xy, 0, 1);
   Out.texCoord = Pos.xy;

   return Out;
}

float4 color = float4(0, 0, 0, 0);
float glowStrength = 6;
float height = 5;
float glowFallOff = 1;
float speed = 2;
float sampleDist = 0;
float ambientGlow = 1;
float ambientGlowHeightScale = 0;
float vertNoise = 6;
float time_0_X = 0;
sampler Noise = sampler_state { 
    Texture = ; 
}; 
  
float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR 

   float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);
   // Sample at three positions for some horizontal blu
   // The shader should blur fine by itself in vertical directio
   float xs0 = texCoord.x - sampleDist
   float xs1 = texCoord.x
   float xs2 = texCoord.x + sampleDist;
   // Noise for the three sample
   float noise0 = tex3D(Noise, float3(xs0, t))
   float noise1 = tex3D(Noise, float3(xs1, t))
   float noise2 = tex3D(Noise, float3(xs2, t));
   // The position of the flas
   float mid0 = height * (noise0 * 2 - 1) * (1 - xs0 * xs0)
   float mid1 = height * (noise1 * 2 - 1) * (1 - xs1 * xs1)
   float mid2 = height * (noise2 * 2 - 1) * (1 - xs2 * xs2);
   // Distance to flas
   float dist0 = abs(texCoord.y - mid0)
   float dist1 = abs(texCoord.y - mid1)
   float dist2 = abs(texCoord.y - mid2);
   // Glow according to distance to flas
   float glow = 1.0 - pow(0.25 * (dist0 + 2 * dist1 + dist2), glowFallOff);
   // Add some ambient glow to get some power in the air feeling
   float ambGlow = ambientGlow * (1 - xs1 * xs1) * (1 - abs(ambientGlowHeightScale * texCoord.y));

   return (glowStrength * glow * glow + ambGlow) * color;
}

spacer.png

IN LUA

addEventHandler("onClientRender", root, 	
	function()
		if myShader then
            dxDrawImage( 100, 350, 300, 350, myShader )
        end
	end
)
addCommandHandler("tester", function ( commandName )
		if not myShader then
            myShader = dxCreateShader( "models/arashi.fx" )  -- Create shader
        else        
            destroyElement( myShader )                    -- Destroy shader
            myShader = nil
        end
end)

 

Link to comment

Hello Krokara,

have you looked at the MTA wiki documentation for the HLSL shaders? The error message should point you at a very specific detail of Direct3D9 effect files: the technique definition. Inside of a technique you define passes. In each pass you define the associated render-states and shader functions.

For example, you could define the following technique in your effect file:

technique TS
{
    pass P0
    {
        VertexShader = compile vs_2_0 VS_Electricity();
        PixelShader = compile ps_3_0 PS_Electricity();
    }
}

Good luck!

Edited by The_GTA
Link to comment
Just now, The_GTA said:

Hello Krokara,

have you looked at the MTA wiki documentation for the HLSL shaders? The error message should point you at a very specific detail of Direct3D9 effect files: the technique definition. Inside of a technique you define passes. In each pass you define the associated render-states and shader functions.

For example, you could define the following technique in your effect file:

technique TS
{
    pass P0
    {
        VertexShader = compile vs_2_0 VS_Electricity();
        PixelShader = compile ps_3_0 PS_Electricity();
    }
}

Good luck!

spacer.png
Hi, thank you very much hope to get it too, I think the technique is not being loaded yet
 

struct VS_OUTPUT 
{
   float4 Pos: POSITION;
   float2 texCoord: TEXCOORD;
};

VS_OUTPUT VS_Electricity(float4 Pos: POSITION)
{
   VS_OUTPUT Out;

   // Clean up inaccuracies
   Pos.xy = sign(Pos.xy);

   Out.Pos = float4(Pos.xy, 0, 1);
   Out.texCoord = Pos.xy;

   return Out;
}

float4 color = float4(0, 0, 0, 0);
float glowStrength = 6;
float height = 5;
float glowFallOff = 1;
float speed = 2;
float sampleDist = 0;
float ambientGlow = 1;
float ambientGlowHeightScale = 0;
float vertNoise = 6;
float time_0_X = 0;
sampler Noise = sampler_state { 
   Texture = ;
}; 
  
float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR 

   float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);
   // Sample at three positions for some horizontal blu
   // The shader should blur fine by itself in vertical directio
   float xs0 = texCoord.x - sampleDist
   float xs1 = texCoord.x
   float xs2 = texCoord.x + sampleDist;
   // Noise for the three sample
   float noise0 = tex3D(Noise, float3(xs0, t))
   float noise1 = tex3D(Noise, float3(xs1, t))
   float noise2 = tex3D(Noise, float3(xs2, t));
   // The position of the flas
   float mid0 = height * (noise0 * 2 - 1) * (1 - xs0 * xs0)
   float mid1 = height * (noise1 * 2 - 1) * (1 - xs1 * xs1)
   float mid2 = height * (noise2 * 2 - 1) * (1 - xs2 * xs2);
   // Distance to flas
   float dist0 = abs(texCoord.y - mid0)
   float dist1 = abs(texCoord.y - mid1)
   float dist2 = abs(texCoord.y - mid2);
   // Glow according to distance to flas
   float glow = 1.0 - pow(0.25 * (dist0 + 2 * dist1 + dist2), glowFallOff);
   // Add some ambient glow to get some power in the air feeling
   float ambGlow = ambientGlow * (1 - xs1 * xs1) * (1 - abs(ambientGlowHeightScale * texCoord.y));

   return (glowStrength * glow * glow + ambGlow) * color;
}

technique TS
{
    pass P0
    {
        VertexShader = compile vs_2_0 VS_Electricity();
        PixelShader = compile ps_3_0 PS_Electricity();
    }
}

Maybe it's a mistake I made converting to mta shader
file in hsls xna FX
 

struct VS_OUTPUT 
{
   float4 Pos: POSITION;
   float2 texCoord: TEXCOORD;
};

VS_OUTPUT VS_Electricity(float4 Pos: POSITION)
{
   VS_OUTPUT Out;

   // Clean up inaccuracies
   Pos.xy = sign(Pos.xy);

   Out.Pos = float4(Pos.xy, 0, 1);
   Out.texCoord = Pos.xy;

   return Out;
}

float4 color: register(c1);
float glowStrength: register(c2);
float height: register(c3);
float glowFallOff: register(c4);
float speed: register(c5);
float sampleDist: register(c6);
float ambientGlow: register(c7);
float ambientGlowHeightScale: register(c8);
float vertNoise: register(c9);
float time_0_X: register(c0);
sampler Noise: register(s0);

float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR 
{
   float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);

   // Sample at three positions for some horizontal blur
   // The shader should blur fine by itself in vertical direction
   float xs0 = texCoord.x - sampleDist;
   float xs1 = texCoord.x;
   float xs2 = texCoord.x + sampleDist;

   // Noise for the three samples
   float noise0 = tex3D(Noise, float3(xs0, t));
   float noise1 = tex3D(Noise, float3(xs1, t));
   float noise2 = tex3D(Noise, float3(xs2, t));

   // The position of the flash
   float mid0 = height * (noise0 * 2 - 1) * (1 - xs0 * xs0);
   float mid1 = height * (noise1 * 2 - 1) * (1 - xs1 * xs1);
   float mid2 = height * (noise2 * 2 - 1) * (1 - xs2 * xs2);

   // Distance to flash
   float dist0 = abs(texCoord.y - mid0);
   float dist1 = abs(texCoord.y - mid1);
   float dist2 = abs(texCoord.y - mid2);

   // Glow according to distance to flash
   float glow = 1.0 - pow(0.25 * (dist0 + 2 * dist1 + dist2), glowFallOff);

   // Add some ambient glow to get some power in the air feeling
   float ambGlow = ambientGlow * (1 - xs1 * xs1) * (1 - abs(ambientGlowHeightScale * texCoord.y));

   return (glowStrength * glow * glow + ambGlow) * color;
}

I'm learning to work with shaders now if you can help me or specify me a specific tutorial, or even defining the technique does not compile something missing?

current code:

struct VS_OUTPUT 
{
   float4 Pos: POSITION;
   float2 texCoord: TEXCOORD;
};

VS_OUTPUT VS_Electricity(float4 Pos: POSITION)
{
   VS_OUTPUT Out;

   // Clean up inaccuracies
   Pos.xy = sign(Pos.xy);

   Out.Pos = float4(Pos.xy, 0, 1);
   Out.texCoord = Pos.xy;

   return Out;
}

float4 color = float4(0, 0, 0, 0);
float glowStrength = 6;
float height = 5;
float glowFallOff = 1;
float speed = 2;
float sampleDist = 0;
float ambientGlow = 1;
float ambientGlowHeightScale = 0;
float vertNoise = 6;
float time_0_X = 0;
sampler Noise = sampler_state { 
    Texture = (gTexture0);
}; 
  
float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR 

   float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);
   // Sample at three positions for some horizontal blu
   // The shader should blur fine by itself in vertical directio
   float xs0 = texCoord.x - sampleDist
   float xs1 = texCoord.x
   float xs2 = texCoord.x + sampleDist;
   // Noise for the three sample
   float noise0 = tex3D(Noise, float3(xs0, t))
   float noise1 = tex3D(Noise, float3(xs1, t))
   float noise2 = tex3D(Noise, float3(xs2, t));
   // The position of the flas
   float mid0 = height * (noise0 * 2 - 1) * (1 - xs0 * xs0)
   float mid1 = height * (noise1 * 2 - 1) * (1 - xs1 * xs1)
   float mid2 = height * (noise2 * 2 - 1) * (1 - xs2 * xs2);
   // Distance to flas
   float dist0 = abs(texCoord.y - mid0)
   float dist1 = abs(texCoord.y - mid1)
   float dist2 = abs(texCoord.y - mid2);
   // Glow according to distance to flas
   float glow = 1.0 - pow(0.25 * (dist0 + 2 * dist1 + dist2), glowFallOff);
   // Add some ambient glow to get some power in the air feeling
   float ambGlow = ambientGlow * (1 - xs1 * xs1) * (1 - abs(ambientGlowHeightScale * texCoord.y));

   return (glowStrength * glow * glow + ambGlow) * color;
}

technique TS
{
    pass P0
    {
        VertexShader = compile vs_2_0 VS_Electricity();
        PixelShader = compile ps_3_0 PS_Electricity();
    }
}

 

Link to comment
8 hours ago, Krokara said:

spacer.png
Hi, thank you very much hope to get it too, I think the technique is not being loaded yet

I think that you have not properly applied my code to your shader. Since you are using XNA you might have overwritten the file again and the technique definition is missing. Try creating the newest .fx file and putting in the technique definition.

The error message you have provided above does not happen if you put the technique definition inside of the file. Please try giving us the actual, most recent error message!

Edited by The_GTA
Link to comment
16 hours ago, The_GTA said:

I think that you have not properly applied my code to your shader. Since you are using XNA you might have overwritten the file again and the technique definition is missing. Try creating the newest .fx file and putting in the technique definition.

The error message you have provided above does not happen if you put the technique definition inside of the file. Please try giving us the actual, most recent error message!

spacer.png
Truth seems like I hadn't updated the file, do you know what the problem is now?

struct VS_OUTPUT 
{
   float4 Pos: POSITION;
   float2 texCoord: TEXCOORD;
};

VS_OUTPUT VS_Electricity(float4 Pos: POSITION)
{
   VS_OUTPUT Out;

   // Clean up inaccuracies
   Pos.xy = sign(Pos.xy);

   Out.Pos = float4(Pos.xy, 0, 1);
   Out.texCoord = Pos.xy;

   return Out;
}

float4 color = float4(0, 0, 0, 0);
float glowStrength = 6;
float height = 5;
float glowFallOff = 1;
float speed = 2;
float sampleDist = 0;
float ambientGlow = 1;
float ambientGlowHeightScale = 0;
float vertNoise = 6;
float time_0_X = 0;
sampler Noise = sampler_state { 
    Texture = ; 
}; 
  
float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR 

   float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);
   // Sample at three positions for some horizontal blu
   // The shader should blur fine by itself in vertical directio
   float xs0 = texCoord.x - sampleDist;
   float xs1 = texCoord.x;
   float xs2 = texCoord.x + sampleDist;
   // Noise for the three sample
   float noise0 = tex3D(Noise, float3(xs0, t));
   float noise1 = tex3D(Noise, float3(xs1, t));
   float noise2 = tex3D(Noise, float3(xs2, t));
   // The position of the flas
   float mid0 = height * (noise0 * 2 - 1) * (1 - xs0 * xs0);
   float mid1 = height * (noise1 * 2 - 1) * (1 - xs1 * xs1);
   float mid2 = height * (noise2 * 2 - 1) * (1 - xs2 * xs2);
   // Distance to flas
   float dist0 = abs(texCoord.y - mid0);
   float dist1 = abs(texCoord.y - mid1);
   float dist2 = abs(texCoord.y - mid2);
   // Glow according to distance to flas
   float glow = 1.0 - pow(0.25 * (dist0 + 2 * dist1 + dist2), glowFallOff);
   // Add some ambient glow to get some power in the air feeling
   float ambGlow = ambientGlow * (1 - xs1 * xs1) * (1 - abs(ambientGlowHeightScale * texCoord.y));

   return (glowStrength * glow * glow + ambGlow) * color;
}

technique TS
{
    pass P0
    {
        VertexShader = compile vs_2_0 VS_Electricity();
        PixelShader = compile ps_3_0 PS_Electricity();
    }
}

 

Link to comment
3 hours ago, Krokara said:

Truth seems like I hadn't updated the file, do you know what the problem is now?

Take a look at the following HLSL construct by you:

sampler Noise = sampler_state { 
    Texture = ; 
}; 

You seem to have forgotten to type the texture variable name and have left a blank instead. If you want to make use of a sampler, then I recommend you to feed the shader with an actual texture to sample from, like this:

texture noiseTex;
sampler Noise = sampler_state { 
    Texture = noiseTex; 
}; 

Then you can assign a texture to the shader using the "noiseTex" shader variable (dxSetShaderValue function).

Edited by The_GTA
Link to comment
35 minutes ago, The_GTA said:

Take at the following HLSL construct by you:

sampler Noise = sampler_state { 
    Texture = ; 
}; 

You seem to have forgotten to type the texture variable name and have left a blank instead. If you want to make use of a sampler, then I recommend you to feed the shader with an actual texture to sample from, like this:

texture noiseTex;
sampler Noise = sampler_state { 
    Texture = noiseTex; 
}; 

Then you can assign a texture to the shader using the "noiseTex" shader variable (dxSetShaderValue function).

 

36 minutes ago, The_GTA said:

Take at the following HLSL construct by you:

sampler Noise = sampler_state { 
    Texture = ; 
}; 

You seem to have forgotten to type the texture variable name and have left a blank instead. If you want to make use of a sampler, then I recommend you to feed the shader with an actual texture to sample from, like this:

texture noiseTex;
sampler Noise = sampler_state { 
    Texture = noiseTex; 
}; 

Then you can assign a texture to the shader using the "noiseTex" shader variable (dxSetShaderValue function).

That was it
spacer.png

Presented something new is not recognizing float2 in line 37,4
 

float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);

 

Link to comment
5 minutes ago, Krokara said:

Presented something new is not recognizing float2 in line 37,4
 

float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);

 

You are asking questions that go beyond this Lua support forum. You are asking me whether you are typing correct HLSL syntax. The language documentation itself is very vague about what data types it does support and what the feature-set looks like for every version. Try looking at the error message and typing the shader correctly. You have left out the exact form of the error message but that does not matter much.

Are you aware that we are working with Direct3D 9 version HLSL? You may be using syntax that is available in Direct3D 10+ HLSL.

Link to comment

@Krokara I'd suggest analyzing shader examples from wiki (screen space ones to be exact) and see what You are missing here. Because just copying and pasting stuff will not do. The code you posted is compatible with Dx9 HLSL. The only thing i'd need would be the 3d noise texture (that should be somewhere you got the code from)

Link to comment
11 minutes ago, Ren_712 said:

@Krokara I'd suggest analyzing shader examples from wiki (screen space ones to be exact) and see what You are missing here. Because just copying and pasting stuff will not do. The code you posted is compatible with Dx9 HLSL. The only thing i'd need would be the 3d noise texture (that should be somewhere you got the code from)

Well, he seems to have issues writing HLSL in general. @Krokara You are missing the { at the following construct...

...
  
float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR 
{ // HERE
   float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);
...

 

Link to comment
3 hours ago, Ren_712 said:

@Krokara I'd suggest analyzing shader examples from wiki (screen space ones to be exact) and see what You are missing here. Because just copying and pasting stuff will not do. The code you posted is compatible with Dx9 HLSL. The only thing i'd need would be the 3d noise texture (that should be somewhere you got the code from)

https://ru.wikipedia.org/wiki/HLSL

 

spacer.png

3 hours ago, The_GTA said:

Well, he seems to have issues writing HLSL in general. @Krokara You are missing the { at the following construct...

...
  
float4 PS_Electricity(float2 texCoord: TEXCOORD) : COLOR 
{ // HERE
   float2 t = float2(speed * time_0_X * 0.5871 - vertNoise * abs(texCoord.y), speed * time_0_X);
...

 

that was it thank, is the code right?
 

  	myShader = dxCreateShader( "models/Arashi.fx" )  -- Create shader
    myTexture = dxCreateTexture( "models/electricity_effect.jpg" )
    dxSetShaderValue( myShader, "noiseTex", myTexture ) 
  	dxDrawImage( 100, 350, 300, 350, myShader )

not give an error but also does not display the shader

Link to comment
10 minutes ago, Krokara said:
  	myShader = dxCreateShader( "models/Arashi.fx" )  -- Create shader
    myTexture = dxCreateTexture( "models/electricity_effect.jpg" )
    dxSetShaderValue( myShader, "noiseTex", myTexture ) 
  	dxDrawImage( 100, 350, 300, 350, myShader )
  • Please do not create textures or shaders every onClientRender event call (put the shader creation outside of the drawing routine)
  • Make sure you put dxDrawImage and related drawing functions inside of an onClientRender event handler (dxCreateTexture is not considered a drawing but a resource allocation function!)
  • Have you put the .jpg file into your meta.xml file so it gets downloaded by connected clients?
Link to comment
Just now, The_GTA said:
  • Please do not create textures or shaders every onClientRender event call (put the shader creation outside of the drawing routine)
  • Make sure you put dxDrawImage and related drawing functions inside of an onClientRender event handler (dxCreateTexture is not considered a drawing but a resource allocation function!)
  • Have you put the .jpg file into your meta.xml file so it gets downloaded by connected clients?
myShader = dxCreateShader( "models/Arashi.fx" )  -- Create shader
function dxshader( )
  	dxDrawImage( 100, 350, 300, 350, myShader )
end
addCommandHandler("ts", function(commandName)
 addEventHandler("onClientRender", root, dxshader)
 myTexture = dxCreateTexture( "models/electricity_effect.jpg" )
 dxSetShaderValue( myShader, "noiseTex", myTexture ) 
end)

mta.xml
 

 <file src="models/electricity_effect.jpg" />

 

Link to comment
float4 color = float4(0, 0, 0, 0);

Your shader is not putting out anything (a completely translucent space of nothing). Are you sure you put in meaningful values inside of the shader? To me it looks like you put in garbage values in the hopes to receive any visible result!

To be fair, I have no expertise in the kind of math that you provide in your shader example (picked from that Russian website). I would try setting the color to (1, 0, 0, 1) to specify complete red and then mess around with the other variables. Please follow any leads that you get from the creator of the shader.

Edited by The_GTA
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...