Home Technical Talk

CGFX - Polygon Stretching / Uvs - ???

polycounter lvl 16
Offline / Send Message
funshark polycounter lvl 16
HI guys,

I'm on the way to search for how to create a CGFX shader which shows the stretching of polygon's UVs, exactly like Roadkill does.
( http://www.pullin-shapes.co.uk/page8.htm )
It is intended to work inside Maya to help with Uvs corrections.

If anyone has links or hints to help me on the process, and if the shader doesn't exist yet ( I've searched and found nothing ), I think it will be very useful for the community.

( I'm not a programmer but i have some basic knowledges to write cg )

Replies

  • funshark
    Offline / Send Message
    funshark polycounter lvl 16
    Ok
    Thanks to the help of a friend, I have a cgfx which is working in FXcomposer.
    In maya, the result is not satisfactory yet ( and by extension, in FXcomposer too ) because of one parameter which is arbitrary for the moment.

    Feel free to comment and help.
    /**** UNTWEAKABLES: Hidden & Automatically-Tracked Parameters **********/
    
    float4x4 view_proj_matrix : WorldViewProjection < string UIWidget="None"; >;
    
    //////// CONNECTOR DATA STRUCTURES ///////////
    
    struct vertexInput {
        float3 Position    : POSITION;
        float2 TexCoord0 : TEXCOORD0;
    };
    
    /* data passed from vertex shader to pixel shader */
    struct vertexOutput {
        float4 HPosition : POSITION;
        float2 TexCoord    : TEXCOORD0;
        float4 HPosCopy : TEXCOORD1;
    };
    
    ///////// VERTEX SHADING /////////////////////
    
    vertexOutput directVS(vertexInput IN) 
    {
        vertexOutput OUT = (vertexOutput)0;
        float4 Po = float4(IN.Position.xyz,1);
        OUT.TexCoord = IN.TexCoord0;
        OUT.HPosition = mul(view_proj_matrix,Po);
        OUT.HPosCopy.xyz = Po.xyz;
        return OUT;
    }
    
    ///////// PIXEL SHADING /////////////////////
    
    float3 directPS(vertexOutput IN) : COLOR0
    {
        float2 uv = IN.TexCoord.xy;
        float3 pos = IN.HPosCopy.xyz;
        float2 ddxUV = ddx(uv);
        float2 ddyUV = ddy(uv);
        float3 ddxPOS = ddx(pos);
        float3 ddyPOS = ddy(pos);
        float3 crossPos = cross(ddxPOS, ddyPOS);
        float FaceArea = length(crossPos);
        
        float3 crossUV = cross(float3(ddxUV,0), float3(ddyUV,0));
        float UVArea = length(crossUV);
        
        float xL = length(ddxPOS);
        float yL = length(ddyPOS);
        float2 rX = ddxUV/xL;
        float2 rY = ddyUV/yL;
        float xVar = rX.x * rX.x + rY.x * rY.x;
        float yVar = rX.y * rX.y + rY.y * rY.y;
        float density = sqrt(xVar + yVar);
        density = UVArea/FaceArea;
        density = 100000 * density; //scale multiplier !!
        if(density < 0.5)
        {
            float ratio = saturate(density * 2);
            return lerp(float4(1,0,0,1) , float4(0,1,0,1), ratio);
        }
        else
        {
            float ratio = saturate(density * 2 - 1);
            return lerp(float4(0,1,0,1) , float4(0,0,1,1), ratio);
        }
        return float4(density.xxx,1);
    
    }
    
    ///////////////////////////////////////
    /// TECHNIQUES ////////////////////////
    ///////////////////////////////////////
    
    technique direct0 <
        string Script = "Pass=p0;";
    > {
        pass p0 <
        string Script = "Draw=geometry;";
        > {
            VertexProgram = compile vp40 directVS();
            DepthTestEnable = true;
            DepthMask = true;
            CullFaceEnable = true;
            BlendEnable = false;
            DepthFunc = LEqual;
            FragmentProgram = compile fp40 directPS();
        }
    }
    
  • Bal
    Offline / Send Message
    Bal polycounter lvl 17
    Hey, this isn't perfect but it's already pretty cool and useful, nice work to the both of you. =)
    Apps like max and maya should have this in by default really.

    Obvious Problem here is that when you have an object that has different parts that aren't unwrapped with the same pixel aspect ratio, the color is gonna change, I'm pretty sure this is not the case in software like Roadkill/Unfoled3D/etc... (I think this is what you mentioned earlier at work).

    Will try to see if it works in Max too later.
Sign In or Register to comment.