float2 fmax(float2 p, float2 q) { return float2(fmax(p.x, q.x), fmax(p.y, q.y)); }
STARTDECL(gl_scaling) () { auto sc = float2(object2view[0].x(), object2view[1].y()); return ToValue(sc); }
void SSR::Render(const Ptr<RenderView> & view) { auto sceneTex = view->GetViewRenderContext()->GetSharedTexture("RenderResult"); auto sceneClipDepth = view->GetViewRenderContext()->GetSharedTexture("SceneClipDepth"); auto gbuffer0 = view->GetViewRenderContext()->GetSharedTexture("GBuffer0"); auto gbuffer1 = view->GetViewRenderContext()->GetSharedTexture("GBuffer1"); TextureDesc ssrDesc = sceneTex->GetDesc(); ssrDesc.format = RENDER_FORMAT_R16G16B16A16_FLOAT; auto ssrResultTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, ssrDesc }); auto ssrResult = ssrResultTexRef->Get()->Cast<Texture>(); auto tmpDepthTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, sceneClipDepth->GetDesc() }); auto tmpDepthTex = tmpDepthTexRef->Get()->Cast<Texture>(); sceneClipDepth->CopyTo(tmpDepthTex, 0, 0, 0, 0, 0, 0, 0); auto ps = Shader::FindOrCreate<ScreenSpaceReflectionPS>(); view->BindShaderParams(ps); ps->SetScalar("frameCount", Global::GetInfo()->frameCount); ps->SetScalar("ssrMaxRoughness", _ssrMaxRoughness); ps->SetScalar("ssrIntensity", _ssrIntensity); ps->SetSRV("sceneTex", sceneTex->GetShaderResourceView()); ps->SetSRV("depthTex", tmpDepthTex->GetShaderResourceView(0, 0, 0, 0, false, RENDER_FORMAT_R24_UNORM_X8_TYPELESS)); ps->SetSRV("gbuffer0", gbuffer0->GetShaderResourceView()); ps->SetSRV("gbuffer1", gbuffer1->GetShaderResourceView()); ps->SetSampler("pointClampSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get()); ps->SetSampler("linearSampler", SamplerTemplate<>::Get()); ps->Flush(); auto rc = Global::GetRenderEngine()->GetRenderContext(); rc->SetDepthStencilState( DepthStencilStateTemplate< false, DEPTH_WRITE_ZERO, COMPARISON_LESS, true, 0xff, 0xff, STENCIL_OP_KEEP, STENCIL_OP_KEEP, STENCIL_OP_KEEP, COMPARISON_NOT_EQUAL>::Get(), 0); DrawQuad( { ssrResult->GetRenderTargetView(0, 0, 1) }, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT)); auto ssrSharedRef = SSRNeighborShare(view, ssrResult, gbuffer1, tmpDepthTex, sceneClipDepth); auto ssrShared = ssrSharedRef->Get()->Cast<Texture>(); // Temporal AA for SSR auto ssrAAedResultTexRef = TexturePool::Instance().FindFree({ TEXTURE_2D, sceneTex->GetDesc() }); auto ssrAAedResultTex = ssrAAedResultTexRef->Get()->Cast<Texture>(); { auto adaptedExposureScale = view->GetViewRenderContext()->GetSharedTexture("AdaptedExposureScale"); float2 offsets[5] = { float2(0.0f, 0.0f), float2(-1.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, -1.0f), float2(0.0f, 1.0f), }; float filterWeights[5]; float weightsSum = 0.0f; for (int i = 0; i < 5; ++i) { float2 offset = offsets[i] - float2(0.5f, -0.5f) * view->temporalAAJitter; //filterWeights[i] = CatmullRom(offset.x()) * CatmullRom(offset.y()); offset.x() *= 1.0f + 0.0f * 0.5f; offset.y() *= 1.0f + 0.0f * 0.5f; filterWeights[i] = exp(-2.29f * (offset.x() * offset.x() + offset.y() * offset.y())); weightsSum += filterWeights[i]; } for (auto & i : filterWeights) i /= weightsSum; std::map<String, String> macros; macros["TAA_DYNAMIC"] = "0"; macros["TAA_HISTORY_BICUBIC"] = "0"; auto ps = Shader::FindOrCreate<TemporalAAPS>(macros); view->BindShaderParams(ps); ps->SetScalar("texSize", ssrResult->GetTexSize()); ps->SetScalar("neighborFilterWeights", filterWeights, (int)sizeof(float) * 5); ps->SetScalar("frameCount", (uint32_t)Global::GetInfo()->frameCount); ps->SetScalar("lerpFactor", 0.125f); //ps->SetSRV("linearDepth", sceneLinearClipDepth->GetShaderResourceView()); ps->SetSRV("sceneDepth", sceneClipDepth->GetShaderResourceView(0, 0, 0, 0, false, RENDER_FORMAT_R24_UNORM_X8_TYPELESS)); ps->SetSRV("sceneTex", ssrShared->GetShaderResourceView()); //ps->SetSRV("velocityTex", velocityTex->GetShaderResourceView()); //ps->SetSRV("adaptedExposureScale", adaptedExposureScale->GetShaderResourceView()); if (_preSSRResultRef) ps->SetSRV("historyTex", _preSSRResultRef->Get()->Cast<Texture>()->GetShaderResourceView()); else ps->SetSRV("historyTex", nullptr); ps->SetSampler("pointSampler", SamplerTemplate<FILTER_MIN_MAG_MIP_POINT>::Get()); ps->SetSampler("linearSampler", SamplerTemplate<>::Get()); ps->Flush(); DrawQuad( { ssrAAedResultTex->GetRenderTargetView(0, 0, 1) }, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT)); _preSSRResultRef = ssrResultTexRef; } /*rc->SetBlendState( BlendStateTemplate<false, false, true, BLEND_PARAM_ONE, BLEND_PARAM_ONE, BLEND_OP_ADD>::Get()); rc->SetDepthStencil(sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT)); Transform( ssrAAedResultTex->GetShaderResourceView(), sceneTex->GetRenderTargetView(0, 0, 1), { COLOR_WRITE_R, COLOR_WRITE_G ,COLOR_WRITE_B ,COLOR_WRITE_A }, 0.0f, 0.0f, nullptr, sceneClipDepth->GetDepthStencilView(0, 0, 1, RENDER_FORMAT_D24_UNORM_S8_UINT));*/ rc->SetBlendState(nullptr); rc->SetDepthStencilState(nullptr); view->GetViewRenderContext()->SetSharedResource("SSR", ssrAAedResultTexRef); }
void cTitle::draw() { static float2 pos = float2(-150, 0); static float count = 0.3f; font.draw("Push Any Key", pos, count, Color(0.0f, 0.2f, 1.0f, font_alpha)); }
STARTDECL(gl_rotate_z) (Value &angle, Value &body) { auto a = transangle(angle); return pushtrans(rotationZ(a), rotationZ(a * float2(1, -1)), body); }
void SubThreadStage() { ResIdentifierPtr psmm_input = ResLoader::Instance().Open(ps_desc_.res_name); KlayGE::XMLDocument doc; XMLNodePtr root = doc.Parse(psmm_input); { XMLNodePtr particle_node = root->FirstNode("particle"); { XMLNodePtr alpha_node = particle_node->FirstNode("alpha"); ps_desc_.ps_data->particle_alpha_from_tex = alpha_node->Attrib("from")->ValueString(); ps_desc_.ps_data->particle_alpha_to_tex = alpha_node->Attrib("to")->ValueString(); } { XMLNodePtr color_node = particle_node->FirstNode("color"); { Color from; XMLAttributePtr attr = color_node->Attrib("from"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); from[i] = static_cast<float>(atof(strs[i].c_str())); } else { from[i] = 0; } } } from.a() = 1; ps_desc_.ps_data->particle_color_from = from; Color to; attr = color_node->Attrib("to"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); to[i] = static_cast<float>(atof(strs[i].c_str())); } else { to[i] = 0; } } } to.a() = 1; ps_desc_.ps_data->particle_color_to = to; } } } { XMLNodePtr emitter_node = root->FirstNode("emitter"); XMLAttributePtr type_attr = emitter_node->Attrib("type"); if (type_attr) { ps_desc_.ps_data->emitter_type = type_attr->ValueString(); } else { ps_desc_.ps_data->emitter_type = "point"; } XMLNodePtr freq_node = emitter_node->FirstNode("frequency"); if (freq_node) { XMLAttributePtr attr = freq_node->Attrib("value"); ps_desc_.ps_data->frequency = attr->ValueFloat(); } XMLNodePtr angle_node = emitter_node->FirstNode("angle"); if (angle_node) { XMLAttributePtr attr = angle_node->Attrib("value"); ps_desc_.ps_data->angle = attr->ValueInt() * DEG2RAD; } XMLNodePtr pos_node = emitter_node->FirstNode("pos"); if (pos_node) { float3 min_pos(0, 0, 0); XMLAttributePtr attr = pos_node->Attrib("min"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); min_pos[i] = static_cast<float>(atof(strs[i].c_str())); } else { min_pos[i] = 0; } } } ps_desc_.ps_data->min_pos = min_pos; float3 max_pos(0, 0, 0); attr = pos_node->Attrib("max"); if (attr) { std::vector<std::string> strs; boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" ")); for (size_t i = 0; i < 3; ++ i) { if (i < strs.size()) { boost::algorithm::trim(strs[i]); max_pos[i] = static_cast<float>(atof(strs[i].c_str())); } else { max_pos[i] = 0; } } } ps_desc_.ps_data->max_pos = max_pos; } XMLNodePtr vel_node = emitter_node->FirstNode("vel"); if (vel_node) { XMLAttributePtr attr = vel_node->Attrib("min"); ps_desc_.ps_data->min_vel = attr->ValueFloat(); attr = vel_node->Attrib("max"); ps_desc_.ps_data->max_vel = attr->ValueFloat(); } XMLNodePtr life_node = emitter_node->FirstNode("life"); if (life_node) { XMLAttributePtr attr = life_node->Attrib("min"); ps_desc_.ps_data->min_life = attr->ValueFloat(); attr = life_node->Attrib("max"); ps_desc_.ps_data->max_life = attr->ValueFloat(); } } { XMLNodePtr updater_node = root->FirstNode("updater"); XMLAttributePtr type_attr = updater_node->Attrib("type"); if (type_attr) { ps_desc_.ps_data->updater_type = type_attr->ValueString(); } else { ps_desc_.ps_data->updater_type = "polyline"; } if ("polyline" == ps_desc_.ps_data->updater_type) { for (XMLNodePtr node = updater_node->FirstNode("curve"); node; node = node->NextSibling("curve")) { std::vector<float2> xys; for (XMLNodePtr ctrl_point_node = node->FirstNode("ctrl_point"); ctrl_point_node; ctrl_point_node = ctrl_point_node->NextSibling("ctrl_point")) { XMLAttributePtr attr_x = ctrl_point_node->Attrib("x"); XMLAttributePtr attr_y = ctrl_point_node->Attrib("y"); xys.push_back(float2(attr_x->ValueFloat(), attr_y->ValueFloat())); } XMLAttributePtr attr = node->Attrib("name"); size_t const name_hash = RT_HASH(attr->ValueString().c_str()); if (CT_HASH("size_over_life") == name_hash) { ps_desc_.ps_data->size_over_life_ctrl_pts = xys; } else if (CT_HASH("mass_over_life") == name_hash) { ps_desc_.ps_data->mass_over_life_ctrl_pts = xys; } else if (CT_HASH("opacity_over_life") == name_hash) { ps_desc_.ps_data->opacity_over_life_ctrl_pts = xys; } } } } RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderDeviceCaps const & caps = rf.RenderEngineInstance().DeviceCaps(); if (caps.multithread_res_creating_support) { this->MainThreadStage(); } }
MultiResSILLayer::MultiResSILLayer() { RenderFactory& rf = Context::Instance().RenderFactoryInstance(); RenderEngine& re = rf.RenderEngineInstance(); RenderDeviceCaps const & caps = re.DeviceCaps(); { rl_quad_ = rf.MakeRenderLayout(); rl_quad_->TopologyType(RenderLayout::TT_TriangleStrip); std::vector<float3> pos; std::vector<uint16_t> index; pos.push_back(float3(+1, +1, 1)); pos.push_back(float3(-1, +1, 1)); pos.push_back(float3(+1, -1, 1)); pos.push_back(float3(-1, -1, 1)); ElementInitData init_data; init_data.row_pitch = static_cast<uint32_t>(pos.size() * sizeof(pos[0])); init_data.slice_pitch = 0; init_data.data = &pos[0]; rl_quad_->BindVertexStream(rf.MakeVertexBuffer(BU_Static, EAH_GPU_Read | EAH_Immutable, &init_data), make_tuple(vertex_element(VEU_Position, 0, EF_BGR32F))); } vpl_tex_ = rf.MakeTexture2D(VPL_COUNT, 4, 1, 1, EF_ABGR16F, 1, 0, EAH_GPU_Read | EAH_GPU_Write, nullptr); gbuffer_to_depth_derivate_pp_ = SyncLoadPostProcess("MultiRes.ppml", "GBuffer2DepthDerivate"); depth_derivate_mipmap_pp_ = SyncLoadPostProcess("MultiRes.ppml", "DepthDerivateMipMap"); gbuffer_to_normal_cone_pp_ = SyncLoadPostProcess("MultiRes.ppml", "GBuffer2NormalCone"); normal_cone_mipmap_pp_ = SyncLoadPostProcess("MultiRes.ppml", "NormalConeMipMap"); RenderEffectPtr subsplat_stencil_effect = SyncLoadRenderEffect("MultiRes.fxml"); subsplat_stencil_tech_ = subsplat_stencil_effect->TechniqueByName("SetSubsplatStencil"); subsplat_cur_lower_level_param_ = subsplat_stencil_effect->ParameterByName("cur_lower_level"); subsplat_is_not_first_last_level_param_ = subsplat_stencil_effect->ParameterByName("is_not_first_last_level"); subsplat_depth_deriv_tex_param_ = subsplat_stencil_effect->ParameterByName("depth_deriv_tex"); subsplat_normal_cone_tex_param_ = subsplat_stencil_effect->ParameterByName("normal_cone_tex"); subsplat_depth_normal_threshold_param_ = subsplat_stencil_effect->ParameterByName("depth_normal_threshold"); RenderEffectPtr vpls_lighting_effect = SyncLoadRenderEffect("VPLsLighting.fxml"); vpls_lighting_instance_id_tech_ = vpls_lighting_effect->TechniqueByName("VPLsLightingInstanceID"); vpls_lighting_no_instance_id_tech_ = vpls_lighting_effect->TechniqueByName("VPLsLightingNoInstanceID"); vpl_view_param_ = vpls_lighting_effect->ParameterByName("view"); vpl_proj_param_ = vpls_lighting_effect->ParameterByName("proj"); vpl_depth_near_far_invfar_param_ = vpls_lighting_effect->ParameterByName("depth_near_far_invfar"); vpl_light_pos_es_param_ = vpls_lighting_effect->ParameterByName("light_pos_es"); vpl_light_color_param_ = vpls_lighting_effect->ParameterByName("light_color"); vpl_light_falloff_param_ = vpls_lighting_effect->ParameterByName("light_falloff"); vpl_x_coord_param_ = vpls_lighting_effect->ParameterByName("x_coord"); vpl_gbuffer_tex_param_ = vpls_lighting_effect->ParameterByName("gbuffer_tex"); vpl_depth_tex_param_ = vpls_lighting_effect->ParameterByName("depth_tex"); *(vpls_lighting_effect->ParameterByName("vpls_tex")) = vpl_tex_; *(vpls_lighting_effect->ParameterByName("vpl_params")) = float2(1.0f / VPL_COUNT, 0.5f / VPL_COUNT); upsampling_pp_ = SyncLoadPostProcess("MultiRes.ppml", "Upsampling"); rl_vpl_ = SyncLoadModel("indirect_light_proxy.meshml", EAH_GPU_Read | EAH_Immutable, CreateModelFactory<RenderModel>(), CreateMeshFactory<StaticMesh>())->Mesh(0)->GetRenderLayout(); if (caps.instance_id_support) { rl_vpl_->NumInstances(VPL_COUNT); } }
float2 getMousePosition() { // TODO: Implement. ASSERT(0); return float2(1.0, 1.0); }
BoxMesh::BoxMesh(ASTRING fileName, AREAL scalex, AREAL scaley, AREAL scalez) { //Initialize buffers m_pVertices = new VertexBuffer(); m_pTexCoords = new VertexBuffer(); m_pNormals = new VertexBuffer(); //m_pShaders = new ShaderBunch(); //Buffer resource BufferParams params; params.FillVertexBufferParams(sizeof(float3), 36, true, false, false, false); //resource data SubresourceData data; #pragma region Positions float3 pos [] = { float3(-0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, 0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(-0.5f*scalex, -0.5f*scaley, 0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, -0.5f*scalez), float3(0.5f*scalex, -0.5f*scaley, 0.5f*scalez), }; params.SetSize(sizeof(float3) * 36); data.SetData(pos); if (!m_pVertices->Create(¶ms, &data, 36, sizeof(float3))) { assert(0 && "Error creating vertex buffer in Box Mesh initialization!"); } #pragma endregion #pragma region Texture Coordinates float2 texCoords[] = { float2(0.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, 1.0f), float2(0.0f, 1.0f), float2(1.0f, 0.0f), float2(1.0f, 1.0f), float2(0.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, 1.0f), float2(0.0f, 1.0f), float2(1.0f, 0.0f), float2(1.0f, 1.0f), float2(0.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, 1.0f), float2(0.0f, 1.0f), float2(1.0f, 0.0f), float2(1.0f, 1.0f), float2(0.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, 1.0f), float2(0.0f, 1.0f), float2(1.0f, 0.0f), float2(1.0f, 1.0f), float2(0.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, 1.0f), float2(0.0f, 1.0f), float2(1.0f, 0.0f), float2(1.0f, 1.0f), float2(0.0f, 0.0f), float2(1.0f, 0.0f), float2(0.0f, 1.0f), float2(0.0f, 1.0f), float2(1.0f, 0.0f), float2(1.0f, 1.0f), }; params.SetSize(sizeof(float2) * 36); data.SetData(texCoords); if (!m_pTexCoords->Create(¶ms, &data, 36, sizeof(float2))) { assert(0 && "Error creating vertex buffer with texture coordinates in Box Mesh initialization!"); } #pragma endregion #pragma region Normal Data NormalData normalData[36]; //generate normals data for each face for (int i = 0; i < 12; i++) { float3 normal; float3 tangent; float3 binormal; CreateNormalTangentBinormal(&pos[i*3], &texCoords[i*3], normal, tangent, binormal); //fill the data for vertex buffer normalData[i*3+2].normal = normal; normalData[i*3+2].tangent = tangent; normalData[i*3+2].binormal = binormal; normalData[i*3+1].normal = normal; normalData[i*3+1].tangent = tangent; normalData[i*3+1].binormal = binormal; normalData[i*3].normal = normal; normalData[i*3].tangent = tangent; normalData[i*3].binormal = binormal; } params.SetSize(sizeof(NormalData) * 36); data.SetData(normalData); if (!m_pNormals->Create(¶ms, &data, 36, sizeof(NormalData))) { assert(0 && "Error creating vertex buffer with Normal data in Box Mesh initialization!"); } #pragma endregion //initialize input layout /*INPUT_LAYOUT layout[] = { { "POSITION", 0, TEX_R32G32B32_FLOAT, 0, 0, IA_PER_VERTEX_DATA, 0}, { "TEXCOORDS", 0, TEX_R32G32_FLOAT, 1, 0, IA_PER_VERTEX_DATA, 0}, { "NORMAL", 0, TEX_R32G32B32_FLOAT, 2, 0, IA_PER_VERTEX_DATA, 0}, { "TANGENT", 0, TEX_R32G32B32_FLOAT, 2, 12, IA_PER_VERTEX_DATA, 0}, { "BINORMAL", 0, TEX_R32G32B32_FLOAT, 2, 24, IA_PER_VERTEX_DATA, 0}, }; //Initialize shaders m_pShaders->VSetVertexShader(L"GBufferShader.hlsl", "VS", layout, 5, TOPOLOGY_TRIANGLELIST); m_pShaders->VSetPixelShader(L"GBufferShader.hlsl", "PS"); */ }
float3 DiTracer::GetDi(World const& world, Light const& light, Sampler const& lightsampler, Sampler const& bsdfsampler, float3 const& wo, ShapeBundle::Hit& hit) const { float3 radiance; // TODO: fix that later with correct heuristic assert(lightsampler.num_samples() == bsdfsampler.num_samples()); // Sample light source first to apply MIS later { // Direction from the shading point to the light float3 lightdir; // PDF for BSDF sample float bsdfpdf = 0.f; // PDF for light sample float lightpdf = 0.f; // Sample numsamples times int numsamples = lightsampler.num_samples(); // Allocate samples std::vector<float2> lightsamples(numsamples); std::vector<float2> bsdfsamples(numsamples); // Generate samples for (int i = 0; i < numsamples; ++i) { lightsamples[i] = lightsampler.Sample2D(); bsdfsamples[i] = bsdfsampler.Sample2D(); } // Cache singularity flag to avoid virtual call in the loop below bool singularlight = light.Singular(); // Fetch the material Material const& mat = *world.materials_[hit.m]; // Start sampling for (int i=0; i<numsamples; ++i) { lightpdf = 0.f; bsdfpdf = 0.f; // This is needed to support normal mapping. // Original intersection needs to be kept around since bsdf might alter the normal ShapeBundle::Hit hitlocal = hit; // Sample light source float3 le = light.GetSample(hitlocal, lightsamples[i], lightdir, lightpdf); // Continue if intensity > 0 and there is non-zero probability of sampling the point if (lightpdf > MINPDF && le.sqnorm() > 0.f) { // Normalize direction to light float3 wi = normalize(lightdir); // Calculate distance for shadow testing float dist = sqrtf(lightdir.sqnorm()); // Spawn shadow ray ray shadowray; // From an intersection point shadowray.o = hitlocal.p; // Into evaluated direction shadowray.d = wi; // TODO: move ray epsilon into some global options object shadowray.t = float2(0.01f, dist - 0.01f); // Check for an occlusion float shadow = world.Intersect(shadowray) ? 0.f : 1.f; // If we are not in shadow if (shadow > 0.f) { // Evaluate BSDF float3 bsdf = mat.Evaluate(hitlocal, wi, wo); // We can't apply MIS for singular lights, so use simple estimator if (singularlight) { // Estimate with Monte-Carlo L(wo) = int{ Ld(wi, wo) * fabs(dot(n, wi)) * dwi } radiance += le * bsdf * fabs(dot(hitlocal.n, wi)) * (1.f / lightpdf); assert(!has_nans(radiance)); } else { // Apply MIS bsdfpdf = mat.GetPdf(hitlocal, wi, wo); // Evaluate weight float weight = PowerHeuristic(1, lightpdf, 1, bsdfpdf); // Estimate with Monte-Carlo L(wo) = int{ Ld(wi, wo) * fabs(dot(n, wi)) * dwi } radiance += le * bsdf * fabs(dot(hitlocal.n, wi)) * weight * (1.f / lightpdf); assert(!has_nans(radiance)); } } } // Sample BSDF if the light is not singular if (!singularlight) { int bsdftype = 0; float3 wi; // Sample material float3 bsdf = mat.Sample(hitlocal, bsdfsamples[i], wo, wi, bsdfpdf, bsdftype); //assert(!has_nans(bsdf)); //assert(!has_nans(bsdfpdf < 1000000.f)); // Normalize wi wi = normalize(wi); // If something would be reflected if (bsdf.sqnorm() > 0.f && bsdfpdf > MINPDF) { float weight = 1.f; // Apply MIS if BSDF is not specular if (! (bsdftype & Bsdf::SPECULAR)) { // Evaluate light PDF lightpdf = light.GetPdf(hitlocal, wi); // If light PDF is zero skip to next sample if (lightpdf < MINPDF) { continue; } // Apply heuristic weight = PowerHeuristic(1, bsdfpdf, 1, lightpdf); } // Spawn shadow ray ray shadowray; // From an intersection point shadowray.o = hitlocal.p; // Into evaluated direction shadowray.d = wi; // TODO: move ray epsilon into some global options object shadowray.t = float2(0.01f, 10000000.f); // Cast the ray into the scene ShapeBundle::Hit shadowhit; float3 le(0.f, 0.f, 0.f); // If the ray intersects the scene check if we have intersected this light // TODO: move that to area light class if (world.Intersect(shadowray, shadowhit)) { // Only sample if this is our light if ((Light const*)shadowhit.bundle->GetAreaLight() == &light) { Material const& lightmat = *world.materials_[shadowhit.m]; // Get material emission properties ShapeBundle::Sample sampledata(shadowhit); float3 d = sampledata.p - hitlocal.p; // If the object facing the light compute emission if (dot(sampledata.n, -wi) > 0.f) { // Emissive power with squared fallof float d2inv = 1.f / d.sqnorm(); // Return emission characteristic of the material le = lightmat.GetLe(sampledata, -wi) * d2inv; } } } else { // This is to give a chance for IBL to contribute le = light.GetLe(shadowray); } if (le.sqnorm() > 0.f) { // Estimate with Monte-Carlo L(wo) = int{ Ld(wi, wo) * fabs(dot(n, wi)) * dwi } radiance += le * bsdf * fabs(dot(hitlocal.n, wi)) * weight * (1.f / bsdfpdf); //assert(!has_nans(radiance)); } } } } return (1.f / numsamples) * radiance; } }
float4 test(float2 p, float2 d, float range){ if(p.x > range || p.y > range) return float4(1.0,1.0,1.0,1.0); return tex2D(gphTexture0,(p*0.5)/float2(range,range)); }
void MayaCamera::Update(float timestep) { (void)timestep; // Track mouse motion int2 mousePos; GetCursorPos((POINT *)&mousePos); int2 mouseMove = mousePos - m_mousePosPrev; m_mousePosPrev = mousePos; // Handle mouse rotation if (m_mbuttonCur == MBUTTON_Left) { m_yaw -= m_rotateSpeed * mouseMove.x; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch -= m_rotateSpeed * mouseMove.y; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } // Retrieve controller state XINPUT_STATE controllerState = {}; float2 controllerLeftStick(0.0f), controllerRightStick(0.0f); float controllerLeftTrigger = 0.0f, controllerRightTrigger = 0.0f; if (m_controllerPresent) { // Look out for disconnection if (XInputGetState(0, &controllerState) == ERROR_SUCCESS) { // Decode axes and apply dead zones controllerLeftTrigger = float(max(0, controllerState.Gamepad.bLeftTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerRightTrigger = float(max(0, controllerState.Gamepad.bRightTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerLeftStick = float2(controllerState.Gamepad.sThumbLX, controllerState.Gamepad.sThumbLY); float lengthLeft = length(controllerLeftStick); if (lengthLeft > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) controllerLeftStick = (controllerLeftStick / lengthLeft) * (lengthLeft - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE); else controllerLeftStick = float2(0.0f); controllerRightStick = float2(controllerState.Gamepad.sThumbRX, controllerState.Gamepad.sThumbRY); float lengthRight = length(controllerRightStick); if (lengthRight > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) controllerRightStick = (controllerRightStick / lengthRight) * (lengthRight - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE); else controllerRightStick = float2(0.0f); } else { m_controllerPresent = false; } } // Handle controller rotation if (m_controllerPresent) { m_yaw -= m_controllerRotateSpeed * controllerRightStick.x * abs(controllerRightStick.x) * timestep; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch += m_controllerRotateSpeed * controllerRightStick.y * abs(controllerRightStick.y) * timestep; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } UpdateOrientation(); // Handle zoom if (m_mbuttonCur == MBUTTON_Right) { m_radius *= expf(mouseMove.y * m_zoomSpeed); } m_radius *= expf(-m_wheelDelta * m_zoomWheelSpeed); m_wheelDelta = 0; // Handle controller zoom if (m_controllerPresent && !(controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)) { m_radius *= expf(-controllerLeftStick.y * abs(controllerLeftStick.y) * m_controllerZoomSpeed * timestep); } // Handle motion of target point if (m_mbuttonCur == MBUTTON_Middle) { m_posTarget -= m_rotateSpeed * mouseMove.x * m_radius * m_viewToWorld[0].xyz; m_posTarget += m_rotateSpeed * mouseMove.y * m_radius * m_viewToWorld[1].xyz; } // Handle controller motion of target point if (m_controllerPresent && (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)) { float3 localVelocity(0.0f); localVelocity.x = controllerLeftStick.x * abs(controllerLeftStick.x); localVelocity.y = square(controllerRightTrigger) - square(controllerLeftTrigger); localVelocity.z = -controllerLeftStick.y * abs(controllerLeftStick.y); m_posTarget += xfmVector(localVelocity, m_viewToWorld) * (m_radius * m_controllerMoveSpeed * timestep); } // Calculate remaining matrices m_pos = m_posTarget + m_radius * m_viewToWorld[2].xyz; setTranslation(&m_viewToWorld, m_pos); UpdateWorldToClip(); }
void FPSCamera::Update(float timestep) { // Track mouse motion int2 mousePos; GetCursorPos((POINT *)&mousePos); int2 mouseMove = mousePos - m_mousePosPrev; m_mousePosPrev = mousePos; // Handle mouse rotation if (m_mbuttonActivate == MBUTTON_None || m_mbuttonCur == m_mbuttonActivate) { m_yaw -= m_rotateSpeed * mouseMove.x; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch -= m_rotateSpeed * mouseMove.y; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } // Retrieve controller state XINPUT_STATE controllerState = {}; float2 controllerLeftStick(0.0f), controllerRightStick(0.0f); float controllerLeftTrigger = 0.0f, controllerRightTrigger = 0.0f; if (m_controllerPresent) { // Look out for disconnection if (XInputGetState(0, &controllerState) == ERROR_SUCCESS) { // Decode axes and apply dead zones controllerLeftTrigger = float(max(0, controllerState.Gamepad.bLeftTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerRightTrigger = float(max(0, controllerState.Gamepad.bRightTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerLeftStick = float2(controllerState.Gamepad.sThumbLX, controllerState.Gamepad.sThumbLY); float lengthLeft = length(controllerLeftStick); if (lengthLeft > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) controllerLeftStick = (controllerLeftStick / lengthLeft) * (lengthLeft - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE); else controllerLeftStick = float2(0.0f); controllerRightStick = float2(controllerState.Gamepad.sThumbRX, controllerState.Gamepad.sThumbRY); float lengthRight = length(controllerRightStick); if (lengthRight > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) controllerRightStick = (controllerRightStick / lengthRight) * (lengthRight - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE); else controllerRightStick = float2(0.0f); } else { m_controllerPresent = false; } } // Handle controller rotation if (m_controllerPresent) { m_yaw -= m_controllerRotateSpeed * controllerRightStick.x * abs(controllerRightStick.x) * timestep; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch += m_controllerRotateSpeed * controllerRightStick.y * abs(controllerRightStick.y) * timestep; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } UpdateOrientation(); // Handle translation // !!!UNDONE: acceleration based on how long you've been holding the button, // to make fine motions easier? float moveStep = timestep * m_moveSpeed; // !!!UNDONE: move keyboard tracking into an input system that respects focus, etc. if (GetAsyncKeyState(VK_SHIFT) || (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)) moveStep *= 3.0f; if (GetAsyncKeyState('W')) m_pos -= m_viewToWorld[2].xyz * moveStep; if (GetAsyncKeyState('S')) m_pos += m_viewToWorld[2].xyz * moveStep; if (GetAsyncKeyState('A')) m_pos -= m_viewToWorld[0].xyz * moveStep; if (GetAsyncKeyState('D')) m_pos += m_viewToWorld[0].xyz * moveStep; if (GetAsyncKeyState('E')) m_pos += m_viewToWorld[1].xyz * moveStep; if (GetAsyncKeyState('C')) m_pos -= m_viewToWorld[1].xyz * moveStep; if (m_controllerPresent) { float3 localVelocity(0.0f); localVelocity.x = controllerLeftStick.x * abs(controllerLeftStick.x); localVelocity.y = square(controllerRightTrigger) - square(controllerLeftTrigger); localVelocity.z = -controllerLeftStick.y * abs(controllerLeftStick.y); m_pos += xfmVector(localVelocity, m_viewToWorld) * (moveStep * m_controllerMoveSpeed); } // Calculate remaining matrices setTranslation(&m_viewToWorld, m_pos); UpdateWorldToClip(); }
float2 Lagrange::getDerivative(float t) { return float2(); }
MovableBox::MovableBox() :mBoxAnimation("data/images/movableblock.bmp",1) ,mGravityHitTimer(0) { setSize(float2(20.f,20.f)); }
void drawBorder(const FRect &rect, Color color, const float2 &offset, float width) { float2 min = rect.min - offset, max = rect.max + offset; width = ::min(width, (max.x - min.x) * 0.5f - 2.0f); Color transparent = Color(color, 0); DTexture::unbind(); // left drawLine(float2(min.x, min.y), float2(min.x, max.y), color, color); drawLine(float2(min.x + width, min.y), float2(min.x, min.y), transparent, color); drawLine(float2(min.x + width, max.y), float2(min.x, max.y), transparent, color); // right drawLine(float2(max.x, min.y), float2(max.x, max.y), color, color); drawLine(float2(max.x - width, min.y), float2(max.x, min.y), transparent, color); drawLine(float2(max.x - width, max.y), float2(max.x, max.y), transparent, color); }
void AABB::Triangulate(int numFacesX, int numFacesY, int numFacesZ, vec *outPos, vec *outNormal, float2 *outUV, bool ccwIsFrontFacing) const { assume(numFacesX >= 1); assume(numFacesY >= 1); assume(numFacesZ >= 1); assume(outPos); if (!outPos) return; // Generate both X-Y planes. int i = 0; for(int face = 0; face < 6; ++face) // Faces run in the order -X, +X, -Y, +Y, -Z, +Z. { int numFacesU; int numFacesV; bool flip = (face == 1 || face == 2 || face == 5); if (ccwIsFrontFacing) flip = !flip; if (face == 0 || face == 1) { numFacesU = numFacesY; numFacesV = numFacesZ; } else if (face == 2 || face == 3) { numFacesU = numFacesX; numFacesV = numFacesZ; } else// if (face == 4 || face == 5) { numFacesU = numFacesX; numFacesV = numFacesY; } for(int x = 0; x < numFacesU; ++x) for(int y = 0; y < numFacesV; ++y) { float u = (float)x / (numFacesU); float v = (float)y / (numFacesV); float u2 = (float)(x+1) / (numFacesU); float v2 = (float)(y+1) / (numFacesV); outPos[i] = FacePoint(face, u, v); outPos[i+1] = FacePoint(face, u, v2); outPos[i+2] = FacePoint(face, u2, v); if (flip) Swap(outPos[i+1], outPos[i+2]); outPos[i+3] = outPos[i+2]; outPos[i+4] = outPos[i+1]; outPos[i+5] = FacePoint(face, u2, v2); if (outUV) { outUV[i] = float2(u,v); outUV[i+1] = float2(u,v2); outUV[i+2] = float2(u2,v); if (flip) Swap(outUV[i+1], outUV[i+2]); outUV[i+3] = outUV[i+2]; outUV[i+4] = outUV[i+1]; outUV[i+5] = float2(u2,v2); } if (outNormal) for(int j = 0; j < 6; ++j) outNormal[i+j] = FaceNormal(face); i += 6; } } assert(i == NumVerticesInTriangulation(numFacesX, numFacesY, numFacesZ)); }
Spike::Spike() : mSpikeTile(Resource::getBitmap("data/images/tileset1.bmp"), 70, 0, 10, 10) { setSize(float2(10,10)); }
void Renderable::OnRenderBegin() { RenderEngine& re = Context::Instance().RenderFactoryInstance().RenderEngineInstance(); Camera const & camera = *re.CurFrameBuffer()->GetViewport()->camera; float4x4 const & view = camera.ViewMatrix(); float4x4 const & proj = camera.ProjMatrix(); float4x4 mv = model_mat_ * view; float4x4 mvp = mv * proj; AABBox const & pos_bb = this->PosBound(); AABBox const & tc_bb = this->TexcoordBound(); DeferredRenderingLayerPtr const & drl = Context::Instance().DeferredRenderingLayerInstance(); if (drl) { int32_t cas_index = drl->CurrCascadeIndex(); if (cas_index >= 0) { mvp *= drl->GetCascadedShadowLayer()->CascadeCropMatrix(cas_index); } } if (select_mode_on_) { *mvp_param_ = mvp; *pos_center_param_ = pos_bb.Center(); *pos_extent_param_ = pos_bb.HalfSize(); *select_mode_object_id_param_ = select_mode_object_id_; } else if (deferred_effect_) { *mvp_param_ = mvp; *model_view_param_ = mv; *far_plane_param_ = float2(camera.FarPlane(), 1.0f / camera.FarPlane()); *pos_center_param_ = pos_bb.Center(); *pos_extent_param_ = pos_bb.HalfSize(); *tc_center_param_ = float2(tc_bb.Center().x(), tc_bb.Center().y()); *tc_extent_param_ = float2(tc_bb.HalfSize().x(), tc_bb.HalfSize().y()); switch (type_) { case PT_OpaqueDepth: case PT_TransparencyBackDepth: case PT_TransparencyFrontDepth: *diffuse_tex_param_ = diffuse_tex_; *diffuse_clr_param_ = float4(mtl_ ? mtl_->diffuse.x() : 0, mtl_ ? mtl_->diffuse.y() : 0, mtl_ ? mtl_->diffuse.z() : 0, static_cast<float>(!!diffuse_tex_)); *opaque_depth_tex_param_ = drl->CurrFrameDepthTex(drl->ActiveViewport()); break; case PT_OpaqueGBufferRT0: case PT_TransparencyBackGBufferRT0: case PT_TransparencyFrontGBufferRT0: case PT_OpaqueGBufferRT1: case PT_TransparencyBackGBufferRT1: case PT_TransparencyFrontGBufferRT1: case PT_OpaqueGBufferMRT: case PT_TransparencyBackGBufferMRT: case PT_TransparencyFrontGBufferMRT: case PT_GenReflectiveShadowMap: *diffuse_tex_param_ = diffuse_tex_; *diffuse_clr_param_ = float4(mtl_ ? mtl_->diffuse.x() : 0, mtl_ ? mtl_->diffuse.y() : 0, mtl_ ? mtl_->diffuse.z() : 0, static_cast<float>(!!diffuse_tex_)); *normal_map_enabled_param_ = static_cast<int32_t>(!!normal_tex_); *normal_tex_param_ = normal_tex_; *height_map_enabled_param_ = static_cast<int32_t>(!!height_tex_); *height_tex_param_ = height_tex_; *specular_tex_param_ = specular_tex_; *specular_clr_param_ = float4(mtl_ ? mtl_->specular.x() : 0, mtl_ ? mtl_->specular.y() : 0, mtl_ ? mtl_->specular.z() : 0, static_cast<float>(!!specular_tex_)); *shininess_clr_param_ = float2(MathLib::clamp(static_cast<float>(mtl_ ? log(mtl_->shininess) * INV_LOG_8192 : 0), 1e-6f, 0.999f), static_cast<float>(!!shininess_tex_)); *shininess_tex_param_ = shininess_tex_; *opacity_clr_param_ = mtl_ ? mtl_->opacity : 1.0f; *opaque_depth_tex_param_ = drl->CurrFrameDepthTex(drl->ActiveViewport()); break; case PT_GenShadowMap: case PT_GenCascadedShadowMap: case PT_GenShadowMapWODepthTexture: *diffuse_tex_param_ = diffuse_tex_; break; case PT_OpaqueShading: case PT_TransparencyBackShading: case PT_TransparencyFrontShading: *shininess_clr_param_ = float2(MathLib::clamp(static_cast<float>(mtl_ ? log(mtl_->shininess) * INV_LOG_8192 : 0), 1e-6f, 0.999f), static_cast<float>(!!shininess_tex_)); *shininess_tex_param_ = shininess_tex_; *diffuse_tex_param_ = diffuse_tex_; *diffuse_clr_param_ = float4(mtl_ ? mtl_->diffuse.x() : 0, mtl_ ? mtl_->diffuse.y() : 0, mtl_ ? mtl_->diffuse.z() : 0, static_cast<float>(!!diffuse_tex_)); *specular_tex_param_ = specular_tex_; *specular_clr_param_ = float4(mtl_ ? mtl_->specular.x() : 0, mtl_ ? mtl_->specular.y() : 0, mtl_ ? mtl_->specular.z() : 0, static_cast<float>(!!specular_tex_)); *emit_tex_param_ = emit_tex_; *emit_clr_param_ = float4(mtl_ ? mtl_->emit.x() : 0, mtl_ ? mtl_->emit.y() : 0, mtl_ ? mtl_->emit.z() : 0, static_cast<float>(!!emit_tex_)); *opacity_clr_param_ = mtl_ ? mtl_->opacity : 1.0f; *opacity_map_enabled_param_ = static_cast<int32_t>(opacity_map_enabled_); break; case PT_OpaqueSpecialShading: case PT_TransparencyBackSpecialShading: case PT_TransparencyFrontSpecialShading: *diffuse_tex_param_ = diffuse_tex_; *emit_tex_param_ = emit_tex_; *emit_clr_param_ = float4(mtl_ ? mtl_->emit.x() : 0, mtl_ ? mtl_->emit.y() : 0, mtl_ ? mtl_->emit.z() : 0, static_cast<float>(!!emit_tex_)); *opacity_clr_param_ = mtl_ ? mtl_->opacity : 1; *opacity_map_enabled_param_ = static_cast<int32_t>(opacity_map_enabled_); break; default: break; } } }
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A //// PARTICULAR PURPOSE. //// //// Copyright (c) Microsoft Corporation. All rights reserved #pragma once #include "pch.h" #include "BasicShapes.h" #include "DirectXSample.h" #include <memory> BasicVertex cubeVertices[] = { { float3(-0.5f, 0.5f, -0.5f), float3(0.0f, 1.0f, 0.0f), float2(0.0f, 0.0f) }, // +Y (top face) { float3( 0.5f, 0.5f, -0.5f), float3(0.0f, 1.0f, 0.0f), float2(1.0f, 0.0f) }, { float3( 0.5f, 0.5f, 0.5f), float3(0.0f, 1.0f, 0.0f), float2(1.0f, 1.0f) }, { float3(-0.5f, 0.5f, 0.5f), float3(0.0f, 1.0f, 0.0f), float2(0.0f, 1.0f) }, { float3(-0.5f, -0.5f, 0.5f), float3(0.0f, -1.0f, 0.0f), float2(0.0f, 0.0f) }, // -Y (bottom face) { float3( 0.5f, -0.5f, 0.5f), float3(0.0f, -1.0f, 0.0f), float2(1.0f, 0.0f) }, { float3 (0.5f, -0.5f, -0.5f), float3(0.0f, -1.0f, 0.0f), float2(1.0f, 1.0f) }, { float3(-0.5f, -0.5f, -0.5f), float3(0.0f, -1.0f, 0.0f), float2(0.0f, 1.0f) }, { float3(0.5f, 0.5f, 0.5f), float3(1.0f, 0.0f, 0.0f), float2(0.0f, 0.0f) }, // +X (right face) { float3(0.5f, 0.5f, -0.5f), float3(1.0f, 0.0f, 0.0f), float2(1.0f, 0.0f) }, { float3(0.5f, -0.5f, -0.5f), float3(1.0f, 0.0f, 0.0f), float2(1.0f, 1.0f) }, { float3(0.5f, -0.5f, 0.5f), float3(1.0f, 0.0f, 0.0f), float2(0.0f, 1.0f) }, { float3(-0.5f, 0.5f, -0.5f), float3(-1.0f, 0.0f, 0.0f), float2(0.0f, 0.0f) }, // -X (left face)
void App::drawFrame(){ const float near_plane = 20.0f; const float far_plane = 4000.0f; // Reversed depth float4x4 projection = toD3DProjection(perspectiveMatrixY(1.2f, width, height, far_plane, near_plane)); float4x4 view = rotateXY(-wx, -wy); view.translate(-camPos); float4x4 viewProj = projection * view; // Pre-scale-bias the matrix so I can use the screen position directly float4x4 viewProjInv = (!viewProj) * (translate(-1.0f, 1.0f, 0.0f) * scale(2.0f / width, -2.0f / height, 1.0f)); TextureID bufferRTs[] = { baseRT, normalRT }; renderer->changeRenderTargets(bufferRTs, elementsOf(bufferRTs), depthRT); renderer->clear(false, true, false, NULL, 0.0f); /* Main scene pass. This is where the buffers are filled for the later deferred passes. */ renderer->reset(); renderer->setRasterizerState(cullBack); renderer->setShader(fillBuffers); renderer->setShaderConstant4x4f("viewProj", viewProj); renderer->setShaderConstant3f("camPos", camPos); renderer->setSamplerState("baseFilter", trilinearAniso); renderer->setDepthState(depthTest); renderer->apply(); for (uint i = 0; i < map->getBatchCount(); i++){ renderer->setTexture("Base", base[i]); renderer->setTexture("Bump", bump[i]); renderer->applyTextures(); map->drawBatch(renderer, i); } renderer->changeToMainFramebuffer(); int mode = renderMode->getSelectedItem(); /* Deferred ambient pass */ renderer->reset(); renderer->setRasterizerState(cullNone); renderer->setShader(ambient); renderer->setShaderConstant2f("factors", float2((mode == 3)? 0.0f : 0.1f, (mode == 3)? 1.0f : 0.0f)); renderer->setTexture("Base", baseRT); if (antiAliasSamples == 1) renderer->setSamplerState("filter", pointClamp); renderer->setDepthState(noDepthTest); renderer->apply(); context->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->Draw(3, 0); if (mode == 3) return; renderer->changeRenderTargets(NULL, 0, stencilMask); renderer->clear(false, true, true, NULL, 0.0f, 0); /* Create the stencil mask */ renderer->reset(); renderer->setRasterizerState(cullNone); renderer->setShader(createMask); renderer->setTexture("BackBuffer", backBufferTexture); renderer->setSamplerState("filter", pointClamp); renderer->setDepthState(stencilSet, 0x1); renderer->apply(); context->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->Draw(3, 0); renderer->changeRenderTarget(FB_COLOR, stencilMask); /* Deferred lighting pass. Draw twice, using stencil to separate pixels for single or multiple sample evaluation. */ float2 zw = projection.rows[2].zw(); int passCount = (mode == 0 && antiAliasSamples > 1)? 2 : 1; for (int p = 0; p < passCount; p++){ renderer->reset(); if (mode == 0 && antiAliasSamples > 1){ renderer->setDepthState(stencilTest, (p == 0)? 0x1 : 0x0); renderer->setShader(lighting[p]); } else { renderer->setDepthState(noDepthTest); if (mode == 1){ renderer->setShader(lighting[0]); } else { renderer->setShader(lighting[1]); } } renderer->setRasterizerState(cullFront); renderer->setBlendState(blendAdd); renderer->setShaderConstant4x4f("viewProj", viewProj); renderer->setShaderConstant4x4f("viewProjInv", viewProjInv); renderer->setShaderConstant3f("camPos", camPos); renderer->setTexture("Base", baseRT); renderer->setTexture("Normal", normalRT); renderer->setTexture("Depth", depthRT); renderer->apply(); for (uint i = 0; i < LIGHT_COUNT; i++){ float3 lightPos = lights[i].position; float radius = lights[i].radius; float invRadius = 1.0f / radius; // Compute z-bounds float4 lPos = view * float4(lightPos, 1.0f); float z1 = lPos.z + radius; if (z1 > near_plane){ float z0 = max(lPos.z - radius, near_plane); float2 zBounds; zBounds.y = saturate(zw.x + zw.y / z0); zBounds.x = saturate(zw.x + zw.y / z1); renderer->setShaderConstant3f("lightPos", lightPos); renderer->setShaderConstant1f("radius", radius); renderer->setShaderConstant1f("invRadius", invRadius); renderer->setShaderConstant2f("zBounds", zBounds); renderer->applyConstants(); sphere->draw(renderer); } } } // Display help text static float displayTime = 5.0f; if (displayTime > 0 && antiAliasSamples <= 1){ if (configDialog->isVisible()){ displayTime = 0; } else { displayTime -= min(frameTime, 0.1f); renderer->drawText("Press F1 to select\na multisampled mode", width * 0.5f - 140, height * 0.5f - 38, 30, 38, defaultFont, linearClamp, blendSrcAlpha, noDepthTest); } } }
void BasicShapes::CreateBox( float3 r, _Out_ ID3D11Buffer **vertexBuffer, _Out_ ID3D11Buffer **indexBuffer, _Out_opt_ unsigned int *vertexCount, _Out_opt_ unsigned int *indexCount ) { BasicVertex boxVertices[] = { // FLOOR {float3(-r.x, -r.y, r.z), float3(0.0f, 1.0f, 0.0f), float2(0.0f, 0.0f)}, {float3( r.x, -r.y, r.z), float3(0.0f, 1.0f, 0.0f), float2(1.0f, 0.0f)}, {float3(-r.x, -r.y, -r.z), float3(0.0f, 1.0f, 0.0f), float2(0.0f, 1.5f)}, {float3( r.x, -r.y, -r.z), float3(0.0f, 1.0f, 0.0f), float2(1.0f, 1.5f)}, // WALL {float3(-r.x, r.y, r.z), float3(0.0f, 0.0f, -1.0f), float2(0.0f, 0.0f)}, {float3( r.x, r.y, r.z), float3(0.0f, 0.0f, -1.0f), float2(2.0f, 0.0f)}, {float3(-r.x, -r.y, r.z), float3(0.0f, 0.0f, -1.0f), float2(0.0f, 1.5f)}, {float3( r.x, -r.y, r.z), float3(0.0f, 0.0f, -1.0f), float2(2.0f, 1.5f)}, // WALL {float3(r.x, r.y, r.z), float3(-1.0f, 0.0f, 0.0f), float2(0.0f, 0.0f)}, {float3(r.x, r.y, -r.z), float3(-1.0f, 0.0f, 0.0f), float2(r.y, 0.0f)}, {float3(r.x, -r.y, r.z), float3(-1.0f, 0.0f, 0.0f), float2(0.0f, 1.5f)}, {float3(r.x, -r.y, -r.z), float3(-1.0f, 0.0f, 0.0f), float2(r.y, 1.5f)}, // WALL {float3( r.x, r.y, -r.z), float3(0.0f, 0.0f, 1.0f), float2(0.0f, 0.0f)}, {float3(-r.x, r.y, -r.z), float3(0.0f, 0.0f, 1.0f), float2(2.0f, 0.0f)}, {float3( r.x, -r.y, -r.z), float3(0.0f, 0.0f, 1.0f), float2(0.0f, 1.5f)}, {float3(-r.x, -r.y, -r.z), float3(0.0f, 0.0f, 1.0f), float2(2.0f, 1.5f)}, // WALL {float3(-r.x, r.y, -r.z), float3(1.0f, 0.0f, 0.0f), float2(0.0f, 0.0f)}, {float3(-r.x, r.y, r.z), float3(1.0f, 0.0f, 0.0f), float2(r.y, 0.0f)}, {float3(-r.x, -r.y, -r.z), float3(1.0f, 0.0f, 0.0f), float2(0.0f, 1.5f)}, {float3(-r.x, -r.y, r.z), float3(1.0f, 0.0f, 0.0f), float2(r.y, 1.5f)}, // CEILING {float3(-r.x, r.y, -r.z), float3(0.0f, -1.0f, 0.0f), float2(-0.15f, 0.0f)}, {float3( r.x, r.y, -r.z), float3(0.0f, -1.0f, 0.0f), float2( 1.25f, 0.0f)}, {float3(-r.x, r.y, r.z), float3(0.0f, -1.0f, 0.0f), float2(-0.15f, 2.1f)}, {float3( r.x, r.y, r.z), float3(0.0f, -1.0f, 0.0f), float2( 1.25f, 2.1f)}, }; unsigned short boxIndices[] = { 0, 2, 1, 1, 2, 3, 4, 6, 5, 5, 6, 7, 8, 10, 9, 9, 10, 11, 12, 14, 13, 13, 14, 15, 16, 18, 17, 17, 18, 19, 20, 22, 21, 21, 22, 23, }; CreateVertexBuffer( ARRAYSIZE(boxVertices), boxVertices, vertexBuffer ); if (vertexCount != nullptr) { *vertexCount = ARRAYSIZE(boxVertices); } CreateIndexBuffer( ARRAYSIZE(boxIndices), boxIndices, indexBuffer ); if (indexCount != nullptr) { *indexCount = ARRAYSIZE(boxIndices); } }
void GLWidget::mousePressEvent(QMouseEvent *event) { mouse_pos_prev_.x = event->x(), mouse_pos_prev_.y = event->y(); if (event->buttons() & Qt::LeftButton) draw_engine_->mouse_press_event(float2((float)event->x(),(float)event->y())); }
void BasicShapes::CreateTangentSphere( _Out_ ID3D11Buffer **vertexBuffer, _Out_ ID3D11Buffer **indexBuffer, _Out_opt_ unsigned int *vertexCount, _Out_opt_ unsigned int *indexCount ) { const int numSegments = 64; const int numSlices = numSegments / 2; const int numVertices = (numSlices + 1) * (numSegments + 1); std::unique_ptr<TangentVertex[]> sphereVertices(new TangentVertex[numVertices]); for (int slice = 0; slice <= numSlices; slice++) { float v = (float)slice/(float)numSlices; float inclination = v * PI_F; float y = cos(inclination); float r = sin(inclination); for (int segment = 0; segment <= numSegments; segment++) { float u = (float)segment/(float)numSegments; float azimuth = u * PI_F * 2.0f; int index = slice * (numSegments+1) + segment; sphereVertices[index].pos = float3(r*sin(azimuth), y, r*cos(azimuth)); sphereVertices[index].tex = float2(u, v); sphereVertices[index].uTan = float3(cos(azimuth), 0, -sin(azimuth)); sphereVertices[index].vTan = float3(cos(inclination)*sin(azimuth), -sin(inclination), cos(inclination)*cos(azimuth)); } } const int numIndices = numSlices * (numSegments-2) * 6; std::unique_ptr<unsigned short[]> sphereIndices(new unsigned short[numIndices]); unsigned int index = 0; for (int slice = 0; slice < numSlices; slice++) { unsigned short sliceBase0 = (unsigned short)((slice)*(numSegments+1)); unsigned short sliceBase1 = (unsigned short)((slice+1)*(numSegments+1)); for (int segment = 0; segment < numSegments; segment++) { if (slice > 0) { sphereIndices[index++] = sliceBase0 + segment; sphereIndices[index++] = sliceBase0 + segment + 1; sphereIndices[index++] = sliceBase1 + segment + 1; } if (slice < numSlices-1) { sphereIndices[index++] = sliceBase0 + segment; sphereIndices[index++] = sliceBase1 + segment + 1; sphereIndices[index++] = sliceBase1 + segment; } } } CreateTangentVertexBuffer( numVertices, sphereVertices.get(), vertexBuffer ); if (vertexCount != nullptr) { *vertexCount = numVertices; } CreateIndexBuffer( numIndices, sphereIndices.get(), indexBuffer ); if (indexCount != nullptr) { *indexCount = numIndices; } }
STARTDECL(gl_origin) () { auto pos = float2(object2view[3].x(), object2view[3].y()); return ToValue(pos); }
void BasicShapes::CreateReferenceAxis( _Out_ ID3D11Buffer **vertexBuffer, _Out_ ID3D11Buffer **indexBuffer, _Out_opt_ unsigned int *vertexCount, _Out_opt_ unsigned int *indexCount ) { BasicVertex axisVertices[] = { { float3( 0.500f, 0.000f, 0.000f), float3( 0.125f, 0.500f, 0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.125f, 0.000f), float3( 0.125f, 0.500f, 0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.000f, 0.125f), float3( 0.125f, 0.500f, 0.500f), float2(0.250f, 0.250f) }, { float3( 0.500f, 0.000f, 0.000f), float3( 0.125f,-0.500f, 0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.000f, 0.125f), float3( 0.125f,-0.500f, 0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f,-0.125f, 0.000f), float3( 0.125f,-0.500f, 0.500f), float2(0.250f, 0.250f) }, { float3( 0.500f, 0.000f, 0.000f), float3( 0.125f,-0.500f,-0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f,-0.125f, 0.000f), float3( 0.125f,-0.500f,-0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.000f,-0.125f), float3( 0.125f,-0.500f,-0.500f), float2(0.250f, 0.250f) }, { float3( 0.500f, 0.000f, 0.000f), float3( 0.125f, 0.500f,-0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.000f,-0.125f), float3( 0.125f, 0.500f,-0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.125f, 0.000f), float3( 0.125f, 0.500f,-0.500f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.125f, 0.000f), float3(-0.125f, 0.000f, 0.000f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.000f,-0.125f), float3(-0.125f, 0.000f, 0.000f), float2(0.250f, 0.250f) }, { float3( 0.000f,-0.125f, 0.000f), float3(-0.125f, 0.000f, 0.000f), float2(0.250f, 0.250f) }, { float3( 0.000f, 0.000f, 0.125f), float3(-0.125f, 0.000f, 0.000f), float2(0.250f, 0.250f) }, { float3(-0.500f, 0.000f, 0.000f), float3(-0.125f, 0.500f, 0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.000f, 0.125f), float3(-0.125f, 0.500f, 0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.125f, 0.000f), float3(-0.125f, 0.500f, 0.500f), float2(0.250f, 0.500f) }, { float3(-0.500f, 0.000f, 0.000f), float3(-0.125f, 0.500f,-0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.125f, 0.000f), float3(-0.125f, 0.500f,-0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.000f,-0.125f), float3(-0.125f, 0.500f,-0.500f), float2(0.250f, 0.500f) }, { float3(-0.500f, 0.000f, 0.000f), float3(-0.125f,-0.500f,-0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.000f,-0.125f), float3(-0.125f,-0.500f,-0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f,-0.125f, 0.000f), float3(-0.125f,-0.500f,-0.500f), float2(0.250f, 0.500f) }, { float3(-0.500f, 0.000f, 0.000f), float3(-0.125f,-0.500f, 0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f,-0.125f, 0.000f), float3(-0.125f,-0.500f, 0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.000f, 0.125f), float3(-0.125f,-0.500f, 0.500f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.000f, 0.125f), float3( 0.125f, 0.000f, 0.000f), float2(0.250f, 0.500f) }, { float3( 0.000f,-0.125f, 0.000f), float3( 0.125f, 0.000f, 0.000f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.000f,-0.125f), float3( 0.125f, 0.000f, 0.000f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.125f, 0.000f), float3( 0.125f, 0.000f, 0.000f), float2(0.250f, 0.500f) }, { float3( 0.000f, 0.500f, 0.000f), float3( 0.500f, 0.125f, 0.500f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.000f, 0.125f), float3( 0.500f, 0.125f, 0.500f), float2(0.500f, 0.250f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f, 0.125f, 0.500f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.500f, 0.000f), float3( 0.500f, 0.125f,-0.500f), float2(0.500f, 0.250f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f, 0.125f,-0.500f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.000f,-0.125f), float3( 0.500f, 0.125f,-0.500f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.500f, 0.000f), float3(-0.500f, 0.125f,-0.500f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.000f,-0.125f), float3(-0.500f, 0.125f,-0.500f), float2(0.500f, 0.250f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f, 0.125f,-0.500f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.500f, 0.000f), float3(-0.500f, 0.125f, 0.500f), float2(0.500f, 0.250f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f, 0.125f, 0.500f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.000f, 0.125f), float3(-0.500f, 0.125f, 0.500f), float2(0.500f, 0.250f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.000f,-0.125f, 0.000f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.000f, 0.125f), float3( 0.000f,-0.125f, 0.000f), float2(0.500f, 0.250f) }, { float3(-0.125f, 0.000f, 0.000f), float3( 0.000f,-0.125f, 0.000f), float2(0.500f, 0.250f) }, { float3( 0.000f, 0.000f,-0.125f), float3( 0.000f,-0.125f, 0.000f), float2(0.500f, 0.250f) }, { float3( 0.000f,-0.500f, 0.000f), float3( 0.500f,-0.125f, 0.500f), float2(0.500f, 0.500f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f,-0.125f, 0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f, 0.000f, 0.125f), float3( 0.500f,-0.125f, 0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f,-0.500f, 0.000f), float3(-0.500f,-0.125f, 0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f, 0.000f, 0.125f), float3(-0.500f,-0.125f, 0.500f), float2(0.500f, 0.500f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f,-0.125f, 0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f,-0.500f, 0.000f), float3(-0.500f,-0.125f,-0.500f), float2(0.500f, 0.500f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f,-0.125f,-0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f, 0.000f,-0.125f), float3(-0.500f,-0.125f,-0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f,-0.500f, 0.000f), float3( 0.500f,-0.125f,-0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f, 0.000f,-0.125f), float3( 0.500f,-0.125f,-0.500f), float2(0.500f, 0.500f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f,-0.125f,-0.500f), float2(0.500f, 0.500f) }, { float3( 0.000f, 0.000f,-0.125f), float3( 0.000f, 0.125f, 0.000f), float2(0.500f, 0.500f) }, { float3(-0.125f, 0.000f, 0.000f), float3( 0.000f, 0.125f, 0.000f), float2(0.500f, 0.500f) }, { float3( 0.000f, 0.000f, 0.125f), float3( 0.000f, 0.125f, 0.000f), float2(0.500f, 0.500f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.000f, 0.125f, 0.000f), float2(0.500f, 0.500f) }, { float3( 0.000f, 0.000f, 0.500f), float3( 0.500f, 0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f, 0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f, 0.125f, 0.000f), float3( 0.500f, 0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f, 0.000f, 0.500f), float3(-0.500f, 0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f, 0.125f, 0.000f), float3(-0.500f, 0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f, 0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f, 0.000f, 0.500f), float3(-0.500f,-0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f,-0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f,-0.125f, 0.000f), float3(-0.500f,-0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f, 0.000f, 0.500f), float3( 0.500f,-0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f,-0.125f, 0.000f), float3( 0.500f,-0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f,-0.500f, 0.125f), float2(0.750f, 0.250f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.000f, 0.000f,-0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f,-0.125f, 0.000f), float3( 0.000f, 0.000f,-0.125f), float2(0.750f, 0.250f) }, { float3(-0.125f, 0.000f, 0.000f), float3( 0.000f, 0.000f,-0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f, 0.125f, 0.000f), float3( 0.000f, 0.000f,-0.125f), float2(0.750f, 0.250f) }, { float3( 0.000f, 0.000f,-0.500f), float3( 0.500f, 0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f, 0.125f, 0.000f), float3( 0.500f, 0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f, 0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f, 0.000f,-0.500f), float3( 0.500f,-0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.500f,-0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f,-0.125f, 0.000f), float3( 0.500f,-0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f, 0.000f,-0.500f), float3(-0.500f,-0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f,-0.125f, 0.000f), float3(-0.500f,-0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f,-0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f, 0.000f,-0.500f), float3(-0.500f, 0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3(-0.125f, 0.000f, 0.000f), float3(-0.500f, 0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f, 0.125f, 0.000f), float3(-0.500f, 0.500f,-0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f, 0.125f, 0.000f), float3( 0.000f, 0.000f, 0.125f), float2(0.750f, 0.500f) }, { float3(-0.125f, 0.000f, 0.000f), float3( 0.000f, 0.000f, 0.125f), float2(0.750f, 0.500f) }, { float3( 0.000f,-0.125f, 0.000f), float3( 0.000f, 0.000f, 0.125f), float2(0.750f, 0.500f) }, { float3( 0.125f, 0.000f, 0.000f), float3( 0.000f, 0.000f, 0.125f), float2(0.750f, 0.500f) }, }; unsigned short axisIndices[] = { 0, 2, 1, 3, 5, 4, 6, 8, 7, 9, 11, 10, 12, 14, 13, 12, 15, 14, 16, 18, 17, 19, 21, 20, 22, 24, 23, 25, 27, 26, 28, 30, 29, 28, 31, 30, 32, 34, 33, 35, 37, 36, 38, 40, 39, 41, 43, 42, 44, 46, 45, 44, 47, 46, 48, 50, 49, 51, 53, 52, 54, 56, 55, 57, 59, 58, 60, 62, 61, 60, 63, 62, 64, 66, 65, 67, 69, 68, 70, 72, 71, 73, 75, 74, 76, 78, 77, 76, 79, 78, 80, 82, 81, 83, 85, 84, 86, 88, 87, 89, 91, 90, 92, 94, 93, 92, 95, 94, }; CreateVertexBuffer( ARRAYSIZE(axisVertices), axisVertices, vertexBuffer ); if (vertexCount != nullptr) { *vertexCount = ARRAYSIZE(axisVertices); } CreateIndexBuffer( ARRAYSIZE(axisIndices), axisIndices, indexBuffer ); if (indexCount != nullptr) { *indexCount = ARRAYSIZE(axisIndices); } }
float2 localpos(const int2 &pos) { return (view2object * float4(float3(float2(pos), 0), 1)).xyz().xy(); }
void MovableBox::setInitialPosition(float2 position){ setPosition(float2(position.x+5,position.y)); }
void startDrag(int x, int y) { lastMousePos = float2(x, y); }
float2 transform(mat2 p, float2 q) { return float2(dot(p.v[0], q), dot(p.v[1], q)); }