Jump to content

Steve_Yorkshire

Contributor
  • Posts

    353
  • Joined

  • Last visited

Posts posted by Steve_Yorkshire

  1. If only I'd known this 10 years ago I wouldn't have spent all my dev life avoiding debug mode ... :oops:


    http://i.imgur.com/SZ4Aez3.jpg


    It's not muh leet haxxor skillz that were to blame - it was having incompatible variables in Torquescript datablocks ...

    This is of course something that never occurred to me, so I've spent the last month hunting through my spaghetti code - which these days is the good stuff that is actually commented and makes some semblence of sense - only to have been on the wildest of goosechases.


    So let's check the top pic problem with the out of range value of 627/256. Kept calling a stack with explosion.cpp - kept doing it even without my custom changes. Why? Because one of my explosion datablocks had lightStartBrightness set to 50 when I meant 5.0. The maximum limit is actually 20.


    Now let's check the bottom problem which has the out of range value of -ALL_THE_BITS_IN_THE_OBSERVABLE_UNIVERSE/64. Now this is player.cpp - which has THREE (count 'em) custom modes of movement. The sort of code which falls out of your pockets and spills everywhere when you trip in the hall.


    f4d1124776b6f0ef5de80decd2de0001.jpg


    Failing on head rotations - but I don't actually use head rotations in a twin stick shooter control method. And that was why. PlayerData Torquescript had min/maxLookAngles set to ZERO (because they weren't really in use) so it freaked out when trying to subtract them.


    And that was it, all the reasons I could never get debug exe to work for all these years, because I was always looking in my custom code for the issues and not expecting it to throw a wobbly over being past a dodgy script value from a scriptedd datablock. :evil:


    And now all is right with the world which comprises of my spagbol C++ and my status as 1337 is confirmed (unless someone else actually looks at my code and then starts laughing, but hey). :P


    C4AeHCyWAAItQ1a.jpg

  2. Stock 3.9 - no code changes:


    Does anyone have any ideas what is happening and/or why?


    MYgGHilVb9I


    I'm using orbitCamera to get a topdown/isometric view. When moving beyond levelInfo visibleDistance from starting position it appears to lose controlObject connection - but I actually still have control of the playerObject and can walk it back into range.


    TS changes: scripts/server/gamecore.cs (function GameCore::spawnPlayer) My changes listed as //YORKS in caps

    function GameCore::spawnPlayer(%game, %client, %spawnPoint, %noControl)
    {
       //echo (%game @"\c4 -> "@ %game.class @" -> GameCore::spawnPlayer");
     
       if (isObject(%client.player))
       {
          // The client should not already have a player. Assigning
          // a new one could result in an uncontrolled player object.
          error("Attempting to create a player for a client that already has one!");
       }
     
       // Attempt to treat %spawnPoint as an object
       if (getWordCount(%spawnPoint) == 1 && isObject(%spawnPoint))
       {
          // Defaults
          %spawnClass      = $Game::DefaultPlayerClass;
          %spawnDataBlock  = $Game::DefaultPlayerDataBlock;
     
          // Overrides by the %spawnPoint
          if (isDefined("%spawnPoint.spawnClass"))
          {
             %spawnClass = %spawnPoint.spawnClass;
             %spawnDataBlock = %spawnPoint.spawnDatablock;
          }
          else if (isDefined("%spawnPoint.spawnDatablock"))
          {
             // This may seem redundant given the above but it allows
             // the SpawnSphere to override the datablock without
             // overriding the default player class
             %spawnDataBlock = %spawnPoint.spawnDatablock;
          }
     
          %spawnProperties = %spawnPoint.spawnProperties;
          %spawnScript     = %spawnPoint.spawnScript;
     
          // Spawn with the engine's Sim::spawnObject() function
          %player = spawnObject(%spawnClass, %spawnDatablock, "",
                                %spawnProperties, %spawnScript);
     
          // If we have an object do some initial setup
          if (isObject(%player))
          {
             // Pick a location within the spawn sphere.
             %spawnLocation = GameCore::pickPointInSpawnSphere(%player, %spawnPoint);
             %player.setTransform(%spawnLocation);
     
          }
          else
          {
             // If we weren't able to create the player object then warn the user
             // When the player clicks OK in one of these message boxes, we will fall through
             // to the "if (!isObject(%player))" check below.
             if (isDefined("%spawnDatablock"))
             {
                   MessageBoxOK("Spawn Player Failed",
                                 "Unable to create a player with class " @ %spawnClass @
                                 " and datablock " @ %spawnDatablock @ ".\n\nStarting as an Observer instead.",
                                 "");
             }
             else
             {
                   MessageBoxOK("Spawn Player Failed",
                                  "Unable to create a player with class " @ %spawnClass @
                                  ".\n\nStarting as an Observer instead.",
                                  "");
             }
          }
       }
       else
       {
     
          // Create a default player
          %player = spawnObject($Game::DefaultPlayerClass, $Game::DefaultPlayerDataBlock);
     
          if (!%player.isMemberOfClass("Player"))
             warn("Trying to spawn a class that does not derive from Player.");
     
          // Treat %spawnPoint as a transform
          %player.setTransform(%spawnPoint);
       }
     
       // If we didn't actually create a player object then bail
       if (!isObject(%player))
       {
          // Make sure we at least have a camera
          %client.spawnCamera(%spawnPoint);
     
          return;
       }
     
    /* //YORKS OUT START
       // Update the default camera to start with the player
       if (isObject(%client.camera) && !isDefined("%noControl"))
       {
          if (%player.getClassname() $= "Player")
             %client.camera.setTransform(%player.getEyeTransform());
          else
             %client.camera.setTransform(%player.getTransform());
       }
    */ //YORKS OUT END
     
       // Add the player object to MissionCleanup so that it
       // won't get saved into the level files and will get
       // cleaned up properly
       MissionCleanup.add(%player);
     
       // Store the client object on the player object for
       // future reference
       %player.client = %client;
     
       // If the player's client has some owned turrets, make sure we let them
       // know that we're a friend too.
       if (%client.ownedTurrets)
       {
          for (%i=0; %i<%client.ownedTurrets.getCount(); %i++)
          {
             %turret = %client.ownedTurrets.getObject(%i);
             %turret.addToIgnoreList(%player);
          }
       }
     
       // Player setup...
       if (%player.isMethod("setShapeName"))
          %player.setShapeName(%client.playerName);
     
       if (%player.isMethod("setEnergyLevel"))
          %player.setEnergyLevel(%player.getDataBlock().maxEnergy);
     
       if (!isDefined("%client.skin"))
       {
          // Determine which character skins are not already in use
          %availableSkins = %player.getDatablock().availableSkins;             // TAB delimited list of skin names
          %count = ClientGroup.getCount();
          for (%cl = 0; %cl < %count; %cl++)
          {
             %other = ClientGroup.getObject(%cl);
             if (%other != %client)
             {
                %availableSkins = strreplace(%availableSkins, %other.skin, "");
                %availableSkins = strreplace(%availableSkins, "\t\t", "");     // remove empty fields
             }
          }
     
          // Choose a random, unique skin for this client
          %count = getFieldCount(%availableSkins);
          %client.skin = addTaggedString( getField(%availableSkins, getRandom(%count)) );
       }
     
       %player.setSkinName(%client.skin);
     
       // Give the client control of the player
       %client.player = %player;
       %camera = %client.camera;//YORKS
     
       //YORKS cheats for ease of use
       %player.setName("hero");
       %camera.setName("cam");
     
       // Give the client control of the camera if in the editor
       if( $startWorldEditor )
       {
          %control = %client.camera;
          %control.mode = "Fly";
          EditorGui.syncCameraGui();
       }
       else
          %control = %player;
     
    //YORKS NEW START
       %client.camera.setOrbitObject(%control, "1.308996 0 0" , 5.0, 20.0, 20.0,true, "0 -3.2 0", false);
       %client.setControlObject(%control); //- Set the control object to the player
       %client.setCameraObject(%client.camera); //- Set the camera object to the camera
     
       toggleFirstPerson(1);
       echo("client and camera " @ %client SPC %client.camera);
    //YORKS NEW END
     
       // Allow the player/camera to receive move data from the GameConnection.  Without this
       // the user is unable to control the player/camera.
       //if (!isDefined("%noControl"))//YORKS OUT
       //   %client.setControlObject(%control);//YORKS OUT
    }

     

    EDIT: visibleDistance and ghost distance thingy work fine in "normal" third person.

  3. Finally worked out how to get customMaterials to use castShadows the same way as normal materials. As it's spread over multiple pages of the refraction/distortion thread - it's posted here together.


    First thing to do is stop customMaterials from ALWAYS casting a shadow. Someone at GG decided to force this regardless. Problem is, that it doesn't matter whether translucent or anything else has filtered shadows out, shadows will be forcibly set on here.


    lighting/shadowMap/shadowMatHook.cpp

    void ShadowMaterialHook::init( BaseMatInstance *inMat )
    {
    //...
       // Do instancing in shadows if we can.
       if ( inFeatures.hasFeature( MFT_UseInstancing ) )
          features.addFeature( MFT_UseInstancing );
     
       Material *shadowMat = (Material*)inMat->getMaterial();
       /* yorks out start - let customMaterials decide for themselves
       if (dynamic_cast< CustomMaterial* >(shadowMat))
       {
    	   // This is a custom material... who knows what it really does, but
    	   // if it wasn't already filtered out of the shadow render then just
    	   // give it some default depth out material.
    	   shadowMat = MATMGR->getMaterialDefinitionByName("AL_DefaultShadowMaterial");
       }
       */ //yorks end of out
     
       // By default we want to disable some states
       // that the material might enable for us.
       GFXStateBlockDesc forced;
    //...

     

    source/materials/CustomMaterialDefinition.h

    class CustomMaterial : public Material
    {
       typedef Material Parent;
    public:
    //...
       bool mForwardLit;
       bool mCastShadows;//yorks in
     
       F32 mVersion;   // 0 = legacy, 1 = DX 8.1, 2 = DX 9.0   
       bool mRefract;   
    //...
       virtual bool onAdd();
       virtual void onRemove();
       virtual bool castsShadows() const { return mCastShadows; }//yorks in
    //...

     

    source/materials/CustomMaterialDefinition.cpp

    CustomMaterial::CustomMaterial()
    {  
    //...
       mForwardLit = false;
       mCastShadows = true;//yorks in
    }
     
    //--------------------------------------------------------------------------
    // Init fields
    //--------------------------------------------------------------------------
    void CustomMaterial::initPersistFields()
    {
    //...
       addField("forwardLit",  TypeBool,      Offset(mForwardLit, CustomMaterial), 
          "@brief Determines if the material should recieve lights in Basic Lighting. "
          "Has no effect in Advanced Lighting.\n\n");
       //yorks start in
       addField("castShadows", TypeBool, Offset(mCastShadows, CustomMaterial),
    	   "If set to false the lighting system will not cast shadows from this material.");
       //yorks end in
     
       Parent::initPersistFields();
    }

     

    After that you can control the shadows in your CustomMaterial.

    Remember shadows are on by default so your TorqueScript definition wants to look like

    singleton CustomMaterial(Mat_wobble_Soldier_Main : Mat_Soldier_Main)
    {
       mapTo = "wobble_Soldier_Main";
     
       translucent = true;//translucent materials (custom or standard) never cast shadows
     
       shader = wobbleTextureShader;
       sampler["diffuseMap"] = "#PreRenderTranslucent";
    };
     
    singleton CustomMaterial(Mat_wobble2_Soldier_Main : Mat_Soldier_Main)
    {
       mapTo = "wobble2_Soldier_Main";
     
       translucent = false;
       //castShadows = true;//default is true so don't need this.
     
       shader = wobbleTextureShader;
       sampler["diffuseMap"] = "#PreRenderTranslucent";
    };
     
    singleton CustomMaterial(Mat_wobble3_Soldier_Main : Mat_Soldier_Main)
    {
       mapTo = "wobble3_Soldier_Main";
     
       translucent = false;
       castShadows = false;
     
       shader = wobbleTextureShader;
       sampler["diffuseMap"] = "#PreRenderTranslucent";
    };

     

    And these 3 then look like this in-game:

    http://i.imgur.com/YJni7sA.jpg

  4. Actually after a bit of experimenting it looks like DAE and CACHED.DTS are where it's having trouble. DAE doesn't seem to grab the material and CACHED.DTS needs a reload for material but can't grab animations.

    I'm not seeing any problems using straight up ye olde model.DTS.

  5. Thanks for this @irei1as


    Setting the sceneRenderThingy to false stopped the horrible fogging and alpha issues and the material loss was fixed by having the gui element reload itself in playGui.onWake().

     

    function PlayGui::onWake(%this)
    {
    //...
     
       //yorks make guiObjectView reload it's object to prevent material loss
       //easier if we have the gui element named
       %viewer = "meshViewer";
       if(%viewer.isActive())
       {
          %mesh = %viewer.getModel();
          echo("\c4guiObjectViewer is " @ %viewer SPC %mesh);
          if(isFile(%mesh))
             %viewer.setModel(%mesh);
          else
             echo("\c2no model");
       }
       else
          echo("\c2nope - no mesh viewer");
    }
  6. Ah thanks for the tip, didn't see that in the search. I did notice that the renderState in an older version ended with false instead of true though - but that the whole "scene" file had kinda had a big overhaul since. Going back to 2009 guiObjectViewer worked as expected. I still have various older versions of T3D lying around on my HD for reference ;)

  7. Hang on, maybe lerp is the better bet here:

     

    //...
        float4 colour_exit = tex2D(diffuseMap, screenpos);
     
    	//here you can modify colourexit if needed
       	float4 color;
     
    	color = float4(0.2, 0.2, 0.2, 1.0);//0.2 is dark
     
    	colour_exit = lerp(colour_exit, color, 0.3);//1.0 would be solid matt colour so 0.3 gives color and transparency
     
    	return colour_exit;
    }

     

    Code looks less hacky at least ...


    C3XNTBIWEAQ6wGt.jpg

  8. Aha! Was doing it wrong - probably still doing it wrong but at least I have a result.


    C3XE3BYXAAAVMss.jpg


    To pixel shader:

    //...
        float4 colour_exit = tex2D(diffuseMap, screenpos);
     
    	//here you can modify colourexit if needed
       	float4 color;//new color value
     
    	//positive = more white, negative = more black
    	color = float4(-0.1, -0.1, -0.1, 1.0);//rgba
     
    	colour_exit = colour_exit.rgba + color;//add color to colour_exit rgba
     
    	return colour_exit;
    }

     

    There's probably a better way of doing use this using diffuseColor or something but I'm not sure how that works ...

  9. (Using T3D 3.9) - I did a search for issues on github but only found one which seems unrelated to this problem from Duion https://github.com/GarageGames/Torque3D/pull/1691.


    I noticed guiObjectView appears broken.


    http://i.imgur.com/uH3El34.jpg


    1: There's some funky add alpha and fogging thing going on with the background.

    2: When you quit Torque, restart, load a level the object is missing it's texture. Reselecting the object in the Gui Editor seems the only way to restore the texture. Nothing seems to get mentioned in the console that's relevant.


    Anyone else seeing this?

  10. @irei1as I tested this in basic lighting too and it seems to work fine - though as you say BL is pretty redundant these days.

    I did notice screen-wrapping as well when adding it to a static object and moving it to the edge of the screen - but only on the "Y axis" (?), so 0 0 0 in worldspace. Horizontal seems okay for some reason ... :|


    Not sure what to do about that though - though thankfully it's not going to affect what I want it for too much as it might help the player see invisible enemies when they approach.


    One more thing I'd like to do, is to add a colour shade/tint/darken to it but don't know. I noticed you commented about modifying colour_exit:

    //here you can modify colourexit if needed
     
       return colour_exit;

     

    I tried adding an rgba to colour_exit before the return and got the colouring - but lost all the transparency and wobble :(


    Any hints for how I should be doing this? :?:

  11. Righty, had a bit of a look at shaders hlsl code ... and it's gibberish to me :roll: but having said that I still managed to get some cool improvements! :mrgreen:


    RDZRU7PpILQ


    Two types of distortion material in the video, the first has translucency the second doesn not - hence the shadow, and also this creates more distortion for reasons ...


    Bascially I added a swirly distort effect to screenpos x and y using y and x and some offsets.


    So the Pixel shader now looks like this:

     

    struct datainput 
    {
       float4 screenCoord : TEXCOORD1;
    };
     
    //diffuseMap is defined in the CustomMaterial and its ShaderData
    uniform sampler2D diffuseMap        : register(S0);
     
    //accumTime is an engine variable. It's kind of the time of the material.
    //Use it to move things in time
    uniform float     accumTime;
     
    float4 main( datainput IN ) : COLOR0
    {
     
       //texture to screen
       float2 screenpos = 0.5+IN.screenCoord.xy/2*float2(1,-1)/IN.screenCoord.w;
     
       	float2 wobble;
    	float speed = 0.03;
    	float magnify = 1.0;
     
    	wobble.y = magnify + sin(IN.screenCoord.x + accumTime) * speed;
        wobble.x = magnify + sin(IN.screenCoord.y + accumTime) * speed;
     
    	//yorks abs seems to give more rotation but splits it into visible cells
        //wobble.y = magnify + abs(sin(IN.screenCoord.x + accumTime) * speed);
        //wobble.x = magnify + abs(sin(IN.screenCoord.y + accumTime) * speed);
     
    	screenpos = screenpos * wobble;
     
        float4 colour_exit = tex2D(diffuseMap, screenpos);
     
       return colour_exit;
    }

     

    Initially I did abs(sin like the original wobble script but it dissected the area into noticeable cells which then rotated against each other. Dropping abs gives a more integrated flow.


    And the Vertex Shader has a very minor change to increase the distortion somewhat:

     

    struct VertToPixOut
    {
       float4 hpos       : POSITION;
       float4 screen        : TEXCOORD1;
    };
     
    struct VertToPixIn
    {
       float4 hpos       : POSITION;
    };
     
    uniform float4x4 modelview;
     
    VertToPixOut main( VertToPixIn In)
    {
       VertToPixOut Out;
       Out.hpos = mul( modelview, In.hpos);
     
       //Out.screen = Out.hpos;
       Out.screen = Out.hpos * 1.5;//yorks bump it up a bit but not too much
     
       return Out;
    }

     

    I'd still like a couple of extra things ... though I'm not entirely sure what ... perhaps make the material slightly darker like introduce a color float of 0.9 or something. Really I'm trying for the old Doom pink demons which had invisible types but you could still see them if if you were looking. Having said that I haven't tested this with an enemy attack on the player so not sure how well it'd currently show up attacking/following in game.

  12. @JeffR yeah this used to be an issue when T3D was first done but then got a fix at some point - I just noticed it was back recently and loses precision quite quickly and does not clear-up/reset when loading new missions. But as I say, only with animated materials but not with animated texture particles.


    Also the material animation is kinda crappy as it's a film strip (1 column X-axis) rather than an X-Y cell system which particles use.


    Here's a link, includes decal and particle

    http://yorkshirerifles.com/downloads/texAnim_issue.zip

×
×
  • Create New...