User Tag List

Results 1 to 8 of 8

Thread: Working on a shader - need some help

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Working on a shader - need some help

    It's supposed to be a mode 7 shader. The code:

    Code:
    // Pixel shader input structure//struct PS_INPUT
    //{
    //    float4 Position   : POSITION;
    //    float2 Texture    : TEXCOORD0;
    //};
    
    
    // Pixel shader output structure
    //struct PS_OUTPUT
    //{
    //    float4 Color   : COLOR0;
    //};
    
    
    
    
    // Global variables
    sampler2D Tex0 : register(s1);
    sampler2D img;
    
    
    float     scale1, scale2;
    
    
    float4 ps_main( in float2 In : TEXCOORD0 )
    {
        In.x=In.x*(In.y*scale1)*scale2;
        In.y=In.y*(In.y*scale1)*scale2;
        float4 myColor = tex2D( img, In );
        return myColor;
    }
    
    
    // Effect technique
    technique tech_main
    {
        pass P0
        {
            // shaders
            VertexShader = NULL;
            PixelShader  = compile ps_2_0 ps_main();
        }  
    }
    And the XML:

    Code:
    <name>Mode 7</name><description>A mode 7 shader. Awesome, right?</description>
    <parameter>
    
    
            // Name of parameter property
            <name>Scale angle (float)</name>
    
    
            // Parameter name (in the .fx file)
            <code>scale1</code>
    
    
            // Description
            <description>Changes the 3D angle multiplier</description>
    
    
            // Type (int or float)
            <type>float</type>
    
    
            // Property type (EDIT, SLIDER, SPIN, CHECKBOX, COLOR)
            <property>edit</property>
    
    
            // Default value
            <value>2.0</value>
    
    
            // Optional : min and max values, not used by all the parameters
            //<min>0.0</min>
    </parameter>
    <parameter>
    
    
            // Name of parameter property
            <name>Scale (float)</name>
    
    
            // Parameter name (in the .fx file)
            <code>scale2</code>
    
    
            // Description
            <description>Changes the scale multiplier (good for a zooming effect, like F-Zero)</description>
    
    
            // Type (int or float)
            <type>float</type>
    
    
            // Property type (EDIT, SLIDER, SPIN, CHECKBOX, COLOR)
            <property>edit</property>
    
    
            // Default value
            <value>1.0</value>
    
    
            // Optional : min and max values, not used by all the parameters
            //<min>0.0</min>
    </parameter>
    </effect>
    And the error I get:

    Code:
    error X3503: 'ps_main': function return value missing semantics(36): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression
    ID3DXEffectCompiler: Compilation failed
    I'm partially basing the code on Looki's Background Lens shader, and using some information from the documentation MuddyMole made. Anyone got any ideas as to why it isn't working? And yes, I know that I'm going to have to modify it a little if I want the perspective to work properly, but that isn't the problem right now, and I think I know how to make it work right once I'm done with this problem.

  2. #2
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    You seem to be using a different template than I'm used to, so I can't tell you why it doesn't work - but this ought to do the same thing:


    sampler2D img : register(s0);
    sampler2D Tex0 : register(s1);

    float scale1, scale2;

    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0 {

    In.x=In.x*(In.y*scale1)*scale2;
    In.y=In.y*(In.y*scale1)*scale2;
    float4 myColor = tex2D( img, In );
    return myColor;
    }

    technique tech_main { pass P0 { PixelShader = compile ps_2_0 ps_main(); } }


    ...and don't forget the "<effect>" tag in your xml file.

    btw: I have no idea how the shader is actually supposed to work. I'm assuming it's unfinished? For example, you register texture "Tex0", but then don't add it as a parameter in the xml file, and never sample it.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I'm kinda new to shader development for anything other than palettes. I didn't use a good template, though, so that might have something to do with it. It is unfinished, I'm still working on it. I was using the blend example shader as a template, and basing some of the code off of the Background Lens shader. Thanks for the help! It works okay now. Also, the XML file does have the effect tag, I guess I just didn't copy it.

    EDIT: It's almost done, just need to flip the image upside-down from what it is now (it renders it upside-down), and then it's complete.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Okay, so here is the progress I have so far:

    Code:
    sampler2D img : register(s0);
    
    float scale1, scale2;
    
    
    float4 ps_main(in float2 In : TEXCOORD0) : COLOR0	{
    
    
    In.x=0.5+((0.5-In.x)*((In.y*In.y)*scale1)/scale2);
    In.y=(In.y*((In.y*2)*scale1))*scale2;
    float4 myColor = tex2D( img, float2(In.x,In.y) );
    return myColor;
    }
    And the XML file:

    Code:
    <effect><name>Mode 7</name>
    <description>A mode 7 shader. Awesome, right?</description>
    <parameter>
    
    
    		// Name of parameter property
    		<name>Scale angle (float)</name>
    
    
    		// Parameter name (in the .fx file)
    		<code>scale2</code>
    
    
    		// Description
    		<description>Changes the 3D angle multiplier (not fully working: Best to leave this as-is for now)</description>
    
    
    		// Type (int or float)
    		<type>float</type>
    
    
    		// Property type (EDIT, SLIDER, SPIN, CHECKBOX, COLOR)
    		<property>edit</property>
    
    
    		// Default value
    		<value>1.0</value>
    
    
    		// Optional : min and max values, not used by all the parameters
    		//<min>0.0</min>
    </parameter>
    <parameter>
    
    
    		// Name of parameter property
    		<name>Scale (float)</name>
    
    
    		// Parameter name (in the .fx file)
    		<code>scale1</code>
    
    
    		// Description
    		<description>Changes the scale multiplier (good for a zooming effect, like F-Zero).</description>
    
    
    		// Type (int or float)
    		<type>float</type>
    
    
    		// Property type (EDIT, SLIDER, SPIN, CHECKBOX, COLOR)
    		<property>edit</property>
    
    
    		// Default value
    		<value>1.0</value>
    
    
    		// Optional : min and max values, not used by all the parameters
    		//<min>0.0</min>
    </parameter>
    </effect>
    Now it's in a usable state, though it requires that you apply the flip vertically shader to the frame. Unfortunately, it doesn't give me the desired effect at all.

  5. #5
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    What's the desired effect?
    If you can post pictures of the original texture and how you want it to look with the shader applied, I might be able to help.

    Flipping should be easy. I believe you ought to be able to just change this one line:
    float4 myColor = tex2D( img, float2(In.x,1-In.y) );

    btw: Instead of saying "float2( In.x, In.y )", you can just say "In" - you only need the float2() function if you're combining values to create a new pair of coordinates (like in the new line above).

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    The desired effect should be somewhat similar to Mode7EX. I'll add your fix, then take a screenshot of how it looks. Then I'll take a screenshot of the same texture applied to the Mode7EX object. Basically, it is supposed to be a perspective shader. The existing one doesn't handle the vertical part correctly (making closer parts move vertically faster). EDIT: I tried your fix, and it doesn't work with my shader.

    Here is a screenshot of it not working:

    Click image for larger version. 

Name:	Fail fix.jpg 
Views:	192 
Size:	18.1 KB 
ID:	10171

    Here is a screenshot of it with the vertical flip shader applied to the frame:

    Click image for larger version. 

Name:	Mode 7 shader not working..jpg 
Views:	224 
Size:	18.9 KB 
ID:	10172

    And a screenshot of Mode 7 EX:

    Click image for larger version. 

Name:	Mode 7 EX.jpg 
Views:	172 
Size:	17.0 KB 
ID:	10173

    NOTE: Ignore the lines at the bottom/top of the first two screenshots, they can be covered up, or I could have changed the settings of the shader.

    I think the difference between each one is pretty obvious.

  7. #7
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Posts
    1,305
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Where's the source texture?
    I get the impression v3 is just like v2, except that it's zoomed in rather than tiling the texture many times? Is that the issue?

    btw: If you're planning to have the viewpoint move / rotate (which I'd have thought is pretty important for use in a game), things are going to get insanely complicated, very fast.

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    The source texture is the object you apply it to. The 3rd screenshot is showing an extension. The problem with the second one is that the perspective isn't done right, the texture is supposed to look that way (with the tiling and all). It looks more like you are on a loop-de-loop than a flat 3d plane, especially when moving.

    btw: If you're planning to have the viewpoint move / rotate (which I'd have thought is pretty important for use in a game), things are going to get insanely complicated, very fast.
    Actually, I've already made something like this using another shader, it's just that I can't implement sprites very well with it, as it is technically a lens shader. As a result, this isn't a problem. Maybe it would help if I could understand this formula, but I can't. It alone can only scale and rotate, but, to fake perspective on the Super NES, you could use mode 7, and then alter the scale on each scanline. As a result, a shader should be able to do it, as you can modify images based on the Y coordinate at the specific X coordinate that it is currently modifying (that is apart of the code of my shader, in case you didn't notice).

Similar Threads

  1. 3d shader.fx
    By Bogeyman in forum Hardware Accelerated Runtime
    Replies: 4
    Last Post: 21st April 2016, 07:00 PM
  2. Tilemap Pixel Shader (aka "texture atlas" shader)
    By MuddyMole in forum Hardware Accelerated Runtime
    Replies: 3
    Last Post: 10th May 2013, 08:21 PM
  3. Any shader effects working yet?
    By DJFuego in forum Android Export Module Version 2.0
    Replies: 8
    Last Post: 10th March 2013, 05:13 PM
  4. 3D Shader ever possible in iOS?
    By StingRay in forum iOS Export Module Version 2.0
    Replies: 1
    Last Post: 16th January 2013, 07:54 AM
  5. Hue Shader (for PS 2.0 !)
    By Nobuyuki in forum Shader Development
    Replies: 2
    Last Post: 25th September 2010, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •