Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About originaldaemon

  • Rank
  1. originaldaemon

    Creating Multiple Point Lights

    I have managed to get it to the stage where the shaders are blending succesfully, but sadly the zbuffer isn't functioning. When i set it to greaterequal the screen is just black. Anyone encountered this problem
  2. originaldaemon

    Creating Multiple Point Lights

    ok ive tried to put in a loop in the shader again. This is what i have so far. //These Values passed into the shader from the main program //Global variable, these values are sent to the effect //using the various Set functions of the effect object uniform extern float4x4 g_matView : View; uniform extern float4x4 g_matProjection : Projection; uniform extern float4x4 g_matWorld : World; //Light Position const static int numLights = 2; float4 g_LightPositionArray[numLights]; //Ambient Colour float4 g_AmbientLightColour; float g_AmbientLightIntensity; //Diffuse Light Colour float4 g_DiffuseLightColour; float g_DiffuseLightIntensity; //Specular float4 g_SpecularLightColour; float g_SpecularLightIntensity; //Eye Position float3 g_EyePosition; float3 g_AttenuationFactor; //Material Colour float4 g_AmbientColour; float4 g_DiffuseColour; float4 g_SpecularColour; //Struct that holds the Input to the Vetex Shader //HLSL language shares the same synatx as C, so a Shader can have structs, //functions, loops etc. struct VS_INPUT { //a Float4 that represents the untransfomed position of a vertex, POSITION0 is //a semantic this tells the Shader that the variable hold postional values of a //vertex float4 Position : POSITION0; //vertex normal float3 Normal :NORMAL0; float2 TexCoords:TEXCOORD0; }; //Struct that holds the output from the Vertex Shader struct VS_OUTPUT { //Float4 Represents the position float4 Position : POSITION0; float2 TexCoords:TEXCOORD0; //light Direction float3 LightDirection[numLights]:TEXCOORD1; //Normal float3 Norm :TEXCOORD2; float3 View :TEXCOORD3; float attenuation[numLights]:TEXCOORD4; }; //The Vertex Shader entry point //This recieves VS_INPUT structure as an Input and it returns a VS_OUTPUT //structure. VS_OUTPUT vs_main( VS_INPUT Input ) { //Declare a VS_OUTPUT structure VS_OUTPUT Output; float4x4 matViewProjection=mul(g_matView,g_matProjection); float4x4 matWorldViewProjection=mul(g_matWorld,matViewProjection); float3 lightDir; Output.Position = mul(Input.Position , matWorldViewProjection); for (int i=0; i<numLights; i++){ float4 g_LightPosition = g_LightPositionArray; //sets the ouput light direction to the global light direction Output.LightDirection[numLights]=Output.Position-g_LightPosition; lightDir=normalize(g_LightPosition.xyz-Output.Position.xyz); Output.LightDirection[numLights]=lightDir; } //attenuation float d=length(lightDir); Output.attenuation[numLights]=g_AttenuationFactor.x+g_AttenuationFactor.y*d+ g_AttenuationFactor.z*d*d; //sets the output normal to the value of input normal multiplied by the world //matrix. Normalize - this normalizes the normals so that the length of the //vector is equal to 1 Output.Norm=mul(Input.Normal,g_matWorld); //return the Output structure. if there is a pixel shader then the Pixel Shader //is called. float4 worldPos=mul(Input.Position,g_matWorld); Output.View=g_EyePosition-worldPos; Output.TexCoords=Input.TexCoords; return( Output ); } //PS_INPUT structure //holds the inputs to the pixel shader struct PS_INPUT { float2 TexCoords:TEXCOORD0; float3 LightDirection[numLights]:TEXCOORD1; float3 Norm :TEXCOORD2; float3 View :TEXCOORD3; float attenuation[numLights]:TEXCOORD4; }; Texture diffuseMap; Texture specularMap; sampler diffuseSampler= sampler_state { Texture=diffuseMap; }; sampler specularSampler= sampler_state { Texture=specularMap; }; //Entry point for the Pixel Shader //this recieves a PS_INPUT structure as input, this value comes from the //Vertex Shader. //The pixel shader returns float4 that represents a colour of a pixel, the COLOR0 //semantic indicates float4 ps_main(PS_INPUT input) : COLOR0 { float3 Normal = normalize(input.Norm); float4 diffuseColour=tex2D(diffuseSampler,input.TexCoords)*g_DiffuseColour; float4 specularColour=tex2D(specularSampler,input.TexCoords)*g_SpecularColour; //float4 to hold the final colour this is set to the ambinet colour contained //in the PS_INPUT structure //Ia=Ic*Ii float4 ambientComponent=g_AmbientLightColour*g_AmbientLightIntensity; float4 specularComponent = 0; float4 diffuseComponent = 0; for(int j = 0; j<numLights; j++){ float3 LightDir = normalize(input.LightDirection[j]); //Diffuse //N.L float nDotL=saturate(dot(Normal,LightDir)); //Id=Dc*Di*N.L diffuseComponent+=g_DiffuseLightColour*g_DiffuseLightIntensity*nDotL/input.attenuation[j]; //Specular //H=V+L float3 HalfVec=normalize(LightDir+normalize(input.View)); //Sp=N.H^n float specularPower=pow(saturate(dot(Normal,HalfVec)),25); specularComponent+=g_SpecularLightColour*g_SpecularLightIntensity*specularPower/input.attenuation[j]; } float4 finalColour=(saturate(g_AmbientColour*ambientComponent)+((diffuseColour*diffuseComponent)+(specularColour*specularComponent))); //returns the final colour return finalColour; } //--------------------------------------------------------------// // Technique Section for PerPixelSpecular //--------------------------------------------------------------// technique PointLight { pass Pass_0 { VertexShader = compile vs_3_0 vs_main(); PixelShader = compile ps_3_0 ps_main(); } } i think im having problems with passing the array of positions for the light. p_Effect->SetVector("g_LightPositionArray",&m_vecLightDirection); the definition for g_LightPositionArray is at the top of the shader file. Can someone tell me how i should be passing this array. m_vecLightDirection is declare like this: D3DXVECTOR4 m_vecLightDirection[2];
  3. originaldaemon

    Creating Multiple Point Lights

    When i enable the zbuffer in that way the program doesn't display anything. Just black. Also i've tried out several of the blend operations by placing them in the same place but they don't work either, is there other things that i would ahve to change aswell
  4. originaldaemon

    Creating Multiple Point Lights

    Quote:Original post by Ashaman73 There are many way to add more than one light to your scene. One way is to use one pass for each light. In this case you normally don't have to alter your shader code, but must be careful about your blending mode (i.e. use additive mode) and your z-comparision (less_or_equal instead of less). An other way is to consider multiple lights in your shader. Instead of transfering data for one light, transfer an whole array of light data to your shader. Then your shader should look like this (pseudo-code): LightData light_data[8]; .. .. diffuse_light = 0; specular_light = 0; for(i=0;i<8;i++) { diffuse_light += calculateDiffuseLight( light_data); light light += calculateSpecularLight( light_data); } final_color = ...diffuse_light...+...specular_light... -- Ashaman73 Thanks very much. Could you tell me how you set the blending mode and the z-comparison, or tell me some keywords i should be using to search for the information myself. Also, are these things i set in the render function of my program, or small things i have to change in the shader. Also i tried changing the shader so that it used an array. I wasn't sure how i should change all the parameters in the shader to suit that. There are things in the vertex shader that use the light data, for attenuation and such, then that gets passed to the pixel shader. I just couldn't figure out how to get it to work. Also, i might not have been sending the data to the .fx file properly. i Was using: D3DXVECTOR4 lightPos; p_Effect->setValue("g_LightPosition", &lightPos) Is this right?
  5. Im looking for a method to sort strings alphabetically, that takes into account strings with numbers. It would be good if you could point me in the direction of a few methods for me to try out.
  6. originaldaemon

    Converting string types

    Im using system strings because a text box created in the windows form design page, returns a system string.
  7. originaldaemon

    Converting string types

    I apreciate your help with showing me the more up to date c++ methods but it doesn't really help. I've already written a programme similar to that, but it got complex when i decided that i should be using structs so that later on i can do more fancy things like hashing. Still my main problem stands, putting it into a windows form and to do this i need to know the best methods for dealing with system strings, not standard strings, unless there's a way i can get the form text boxes to deal with things other than system strings. Sorry if i sound ungrateful its just ive been trying to do this for a while and its starting to frustrate me quite a bit. All the books ive been using show examples like the one you made but they all end up using char arrays when it comes to working with structs. Thats why i ended up giving up on working with strnigs and opted to just use character arrays instead. Thanks for trying though.
  8. originaldaemon

    Converting string types

    The problem with std::strings was when i was using the fstream read and write. I couldn't write out the struct of strings. I tried: write((char *)temp.firstname.c_str(), sizeof(temp.name)) but when i read the string from the file all i got was jargen. I also became confused about assigning a data size because i was having to write part of the struct instead of the entire struct in one go. But my problem now is with system strings and c_str() doesn't work with them. Why would wfstream help. It still only takes char * arguments doesn't it??
  9. I have created these two functions in a console programme: struct Info{ char firstname[20]; char lastname[20]; }temp; void addInfo{ fstream file; file.open("info.txt", ios::in|ios::end); cin.getline(temp.firstname, '100'); cin.getline(temp.lastname, '100'); file.write((char *)&temp, sizeof(Info)); file.close(); } void viewInfo{ fstream file; file.open("info.txt", ios::in|ios::beg); do{ file.read((char *)&temp, sizeof(Info)); cout<<temp.firstname<<endl; cout<<temp.lastname<<endl; cout<<"--------"<<endl; while(!file.eof()); } Now i want to put them into a windows form. So far i have made it so the form can open the file specified by the user. I use this function to convert from the system string to a char pointer: char *strPointer = (char *)Marshal::StringToHGobalAnsi(textBox->text).toPointer(); then i can use: fstream::open(strPointer, ios::in| ios::out| ios::beg) to open the file. My problem is i can't read or write information to the file because i can't convert between char *, char array and system::string (im using char arrays to store the information because i havn't been able to get it to work with std::Strings or system::strings). If someone can tell me how to convert between these data types or a way to use other information types in the struct that would be very helpful. P.S. i do have access to a lot of c++ books but none of them tell you anything about windows forms and all the examples of the fstream they use only deal with char arrays. When i say a lot i am talking about a good 20 books. Can someone point me in the direction of a book that does deal with these issues, the more detail the better because im also finding a lot of them very vague. [Edited by - originaldaemon on July 29, 2008 10:42:22 AM]
  10. i want to convert a system string, taken as an input from a windows form text box, to a char array. the system string is refered to by using textBox1->Text. I want it converted to a char array declared "char array[100]". or something like that.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!