CRaycaster::CRaycaster() { // defaultne nastavenie rozmerov obrazovky scr_x = scr_y = 0; // nastavenie kamery initCamRot(); //kamera = CKamera(CVektor3(0, 0, -1),CVektor3(0.0f,0.0f,0.0f),CVektor3(0.0f,1.0f,0.0f), // 1.0f,0.1f,30.0f); // maximalny pocet odobratych vzoriek max_vz = 1024; // mnozstvo odobratych vzoriek pozdlz luca samplingRate = 1.0f; // typ dat typ_dat = 16; initPokrytie(800,4095,0.0f,0.3f); // nastavenie hodnot pre linearnu interpolaciu pokrytia pozadie = 0.0f; intenzita = -1.0f; acc_color = 0.0f; acc_opacity = 0.0f; // nastavenie svetla svetlo = CSvetlo(CVektor3(1024.0f,1024.0f,-1024.0f),CVektor3(0.0f,0.0f,0.0f),CFarba(1.0f,1.0f,1.0f,1.0f)); // nastavenie tienovania shader = CShader(CFarba(), CFarba(), CFarba(), 40.0f, 0.5f, 0.5f, 0.5f); // data pre texturu textura.data=NULL; // textura je struct, takze nema konstruktor->treba ju na zaciatku manualne vynullovat }
CRaycaster::CRaycaster(UINT16 scr_x, UINT16 scr_y) { // nastavenie rozmerov obrazovky this->scr_x = scr_x; this->scr_y = scr_y; // nastavenie kamery initCamRot(); //kamera = CKamera(CVektor3(-1.0*cam_vz*sin(cam_dx)*cos(cam_dy), cam_vz*sin(cam_dy), -1.0f*cam_vz*cos(cam_dx)*cos(cam_dy)),CVektor3(0.0f,0.0f,0.0f),CVektor3(0.0f,1.0f,0.0f), //kamera = CKamera(CVektor3(0, 0, -1),CVektor3(0.0f,0.0f,0.0f),CVektor3(0.0f,1.0f,0.0f), //kamera = CKamera(CVektor3(0, 0, -1),CVektor3(0.0f,0.0f,0.0f),CVektor3(0.0f,1.0f,0.0f), // 1.0f,0.1f,30.0f); // nastavime UV ratio setRatioUV(); // maximalny pocet vzoriek max_vz = 1024; // mnozstvo odobratych vzoriek pozdlz luca samplingRate = 1.0f; // typ dat typ_dat = 16; initPokrytie(2000,4095,0.0f,0.1f); pozadie = 0.0f; intenzita = -1.0f; acc_color = 0.0f; acc_opacity = 0.0f; // nastavenie svetla svetlo = CSvetlo(kamera.from,kamera.to,CFarba(1.0f,1.0f,1.0f,1.0f)); // nastavenie tienovania - prispevky jednotlivych svetiel shader = CShader(CFarba(), CFarba(), CFarba(), 40.0f, 0.9f, 0.5f, 1.0f); // data pre texturu textura.data=NULL; // textura je struct, takze nema konstruktor->treba ju na zaciatku manualne vynullovat }
void CShaderLibrary::AddShader(const tstring& sFile) { TAssert(!Get()->m_bCompiled); if (Get()->m_bCompiled) return; std::basic_ifstream<tchar> f(sFile.c_str()); if (!f.is_open()) { TError("Couldn't open shader file: " + sFile + "\n"); return; } std::shared_ptr<CData> pData(new CData()); CDataSerializer::Read(f, pData.get()); CData* pName = pData->FindChild("Name"); CData* pVertex = pData->FindChild("Vertex"); CData* pFragment = pData->FindChild("Fragment"); TAssert(pName); if (!pName) { TError("Malformed shader file. " + sFile + " has no Name entry.\n"); return; } TAssert(pVertex); if (!pVertex) { TError("Malformed shader file. " + sFile + " has no Vertex entry.\n"); return; } TAssert(pFragment); if (!pFragment) { TError("Malformed shader file. " + sFile + " has no Fragment entry.\n"); return; } Get()->m_aShaders.push_back(CShader(pName->GetValueString(), pVertex->GetValueString(), pFragment->GetValueString())); Get()->m_aShaderNames[pName->GetValueString()] = Get()->m_aShaders.size()-1; auto& oShader = Get()->m_aShaders.back(); for (size_t i = 0; i < pData->GetNumChildren(); i++) { CData* pChild = pData->GetChild(i); if (pChild->GetKey() == "Parameter") { auto& oParameter = oShader.m_aParameters[pChild->GetValueString()]; oParameter.m_sName = pChild->GetValueString(); for (size_t j = 0; j < pChild->GetNumChildren(); j++) { CData* pUniform = pChild->GetChild(j); if (pUniform->GetKey() == "Uniform") { auto& oUniform = oParameter.m_aActions.push_back(); oUniform.m_sName = pUniform->GetValueString(); oUniform.m_bTexture = false; CData* pValue = pUniform->FindChild("Value"); CData* pTexture = pUniform->FindChild("Texture"); TAssert(!(pValue && pTexture)); TAssert(pValue || pTexture); if (pValue) oUniform.m_sValue = pValue->GetValueString(); else if (pTexture) { oUniform.m_sValue = pTexture->GetValueString(); oShader.m_asTextures.push_back(pUniform->GetValueString()); oUniform.m_bTexture = true; } } else if (pUniform->GetKey() == "Blend") { tstring& sBlend = oParameter.m_sBlend; sBlend = pUniform->GetValueString(); } } } else if (pChild->GetKey() == "Defaults") { for (size_t j = 0; j < pChild->GetNumChildren(); j++) { CData* pUniform = pChild->GetChild(j); auto& oDefault = oShader.m_aDefaults[pUniform->GetKey()]; oDefault.m_sName = pUniform->GetKey(); oDefault.m_sValue = pUniform->GetValueString(); } } } }